A financial math library
Project description
finmath
finmath is a high-performance financial mathematics library written in C++ with Python bindings using pybind11. The library includes various functions for calculating compound interest, option pricing (including Black-Scholes and Binomial Tree models), and time series analysis. The goal is to provide a fast and reliable tool for financial calculations that can be used in Python.
Installation
Prerequisites
- C++17 or later
- Python 3.6 or later
pybind11(for Python bindings)CMake3.5 or later (for building the library)ninjaFor optimizing cmake build
Build Instructions
-
Clone the repository:
git clone https://github.com/prajwalshah19/finmath.git cd finmath
-
Create a build directory:
mkdir build cd build
-
Run CMake:
cmake .. -
Build the library:
make
-
Install the Python bindings (optional):
pip install .
This will build the finmath library and create the Python bindings so that you can use finmath directly in Python.
Usage
Python
After installing the finmath library, you can import and use it in Python:
import finmath
# Example: Calculate compound interest
principal = 1000
rate = 5
time = 10
frequency = 4
result = finmath.compound_interest(principal, rate, time, frequency)
print(f"Compound Interest: {result}")
# Example: Calculate option price using Black-Scholes model
option_price = finmath.black_scholes(finmath.OptionType.CALL, 95, 100, 1, 0.05, 0.2)
print(f"Black-Scholes Option Price: {option_price}")
# Example: Calculate rolling volatility over a 22-day window
prices = [100, 101, 102, 100, 99, 98, 100, 102, 103, 104, 105] # Example price series
vol = finmath.rolling_volatility(prices, 22)
print(f"Rolling Volatility: {vol}")
C++
If you want to use the library directly in C++:
#include "finmath/InterestAndAnnuities/compound_interest.h"
#include "finmath/OptionPricing/black_scholes.h"
#include "finmath/TimeSeries/rolling_volatility.h"
#include <iostream>
#include <vector>
int main() {
double principal = 1000;
double rate = 5;
int time = 10;
int frequency = 4;
double compound_result = compound_interest(principal, rate, time, frequency);
std::cout << "Compound Interest: " << compound_result << std::endl;
std::vector<double> prices = {100, 101, 102, 100, 99, 98, 100, 102, 103, 104, 105};
auto vol = rolling_volatility(prices, 22);
std::cout << "Rolling Volatility: " << vol.back() << std::endl;
return 0;
}
Benchmarking
You can compare the performance of finmath functions with other implementations (e.g., gs_quant) to see the speedup provided by the C++ implementations:
import timeit
import gs_quant.timeseries as ts
import functions
import finmath
# Example data for 1000 days
prices = ts.generate_series(1000)
# Timing the finmath C++ implementation of rolling volatility
def test_cpp_implementation():
return finmath.rolling_volatility(prices.tolist(), 22)
cpp_time = timeit.timeit(test_cpp_implementation, number=100)
print(f"C++ implementation time: {cpp_time:.6f} seconds")
Contributing
We welcome contributions to finmath! To contribute:
-
Fork the repository.
-
Create a new branch for your feature or bug fix:
git checkout -b feature/my-new-feature
-
Commit your changes:
git commit -m "Add some feature"
-
Push the branch to your fork:
git push origin feature/my-new-feature
-
Open a Pull Request on the original repository.
License
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
Acknowledgments
- Inspired by the
gs_quantlibrary for financial time series analysis. - Thanks to
pybind11for making it easy to integrate C++ and Python.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file finmath-0.1.16-cp314-cp314t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.14t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
520e8d858aaf1eccdb3d259835d6142b2f6671c7771ff28c7b1b3bed1b94175c
|
|
| MD5 |
85700bed4ed003b9154de303cb521068
|
|
| BLAKE2b-256 |
d19fd8da4448dfb1cd578157f7f424df37c8fc60f432aea758bb2cf3a752d088
|
File details
Details for the file finmath-0.1.16-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 112.9 kB
- Tags: CPython 3.14t, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45339e6124a7b6b31c996c371c909901a14b14778498b19deffb9597ec4773cd
|
|
| MD5 |
d5a019648446c004ba4d730c2c0ebd7e
|
|
| BLAKE2b-256 |
bc91496efccb6d4fee18e2e3544e36e331c7c059895c67928a5333e0abf88599
|
File details
Details for the file finmath-0.1.16-cp314-cp314t-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314t-macosx_11_0_arm64.whl
- Upload date:
- Size: 98.5 kB
- Tags: CPython 3.14t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e133c5e159f8fbf57a0dc2313c4263cff7e70955bcb0f1a516f8b2775f93f2af
|
|
| MD5 |
a8d4c6a3d0ca6c377b2427362fa31435
|
|
| BLAKE2b-256 |
6f10eceef76e67c7f51663438eb6dcca0e8162b87f4ac6dc740d8bd5e4c7acdd
|
File details
Details for the file finmath-0.1.16-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2395c71996d50fb88ec8ab80aef3bf0cbea05a4456280d4c92cc13334781619
|
|
| MD5 |
61bab9143f7287659f63087398f44198
|
|
| BLAKE2b-256 |
08a3c71f9c1e3122f8f88ffa654a4d9530edb65b524334f29bff1f975fca9af4
|
File details
Details for the file finmath-0.1.16-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 113.1 kB
- Tags: CPython 3.14, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ab9d9d7d39b98f20c9787e7d015f54eb17c2dfcdf2bb3563b14cc6dbcbb66fd
|
|
| MD5 |
4175670100f561559cdaddd2d3296c12
|
|
| BLAKE2b-256 |
5cd0a56fe8367b421b3af20c6c6211b3391959ed884778cdafd2b7b80757d31c
|
File details
Details for the file finmath-0.1.16-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 93.5 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
137cf5fa0f8ccf53d0d0c1b2242393b79695074167592f726e287d918e9658c8
|
|
| MD5 |
e389fcf60d735bf949ed36ad8dc89dfb
|
|
| BLAKE2b-256 |
bba9f68988de3ab19a66bb8f6a3317c9a2030a44709de67d5187f6f36d186eb7
|
File details
Details for the file finmath-0.1.16-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60622ee4d806a4fe06cb3646c9b9ce7bb166859069c2f20da4291b6ea337aa20
|
|
| MD5 |
69d1e66ee63f4bc7e206d7d041ed9434
|
|
| BLAKE2b-256 |
f0966d8cb54b2211c7cfc52708e3ba13bc9004077bac1b71c75e7fa5e5de5389
|
File details
Details for the file finmath-0.1.16-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 112.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5a36aa58634973079a65b3ce2b78dae775c50bf0773fdc296b6827a71f9780
|
|
| MD5 |
286ca8202294ef656fb8e04f62c4ab48
|
|
| BLAKE2b-256 |
074311503cbd20c4099dc5faa757e57dc1834a917b2370b9a523832aded5ec4f
|
File details
Details for the file finmath-0.1.16-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 93.2 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63f191fd940a335c382277e4d766eb40a292c5320d1ab1d6ead6287ad75d6e97
|
|
| MD5 |
93fb0ee2416ff4712adc8980fd12094d
|
|
| BLAKE2b-256 |
5ccd406f95c3e191e5a4efa416cb1682e0d25531de0699538b9311ae6b4a1684
|
File details
Details for the file finmath-0.1.16-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe2d1e6c7302422fb9adcd91c6447c85cc33b42a1aa9716d40861738e5015ebc
|
|
| MD5 |
0acd37e718cf7446be46651a73a06a7e
|
|
| BLAKE2b-256 |
68ee16fe995acb0e95ba30b1bec7f2898cfe85bfafc69d5e1312bd08cd570ebd
|
File details
Details for the file finmath-0.1.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 112.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7533b1ef6ca421f9f55b4fea4c0aab063fb384287eb03789bf9db2f08abedd19
|
|
| MD5 |
66fe51c273dfea30a303ab19367f976f
|
|
| BLAKE2b-256 |
d1724bdba86c79eefe9c2eb8f087be3aa452464ee2e0ec3899d6b444a04d7f47
|
File details
Details for the file finmath-0.1.16-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 93.2 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c2591df21978d86852beee9cefa5501f1798eebf14762d6addb8fe27eaca3f9
|
|
| MD5 |
feb89002d86fafb23644fb31f49ac293
|
|
| BLAKE2b-256 |
ed124c8a3a59812f99bae1167d938190d08dd013a179ec66cdc5d26b00806fc6
|
File details
Details for the file finmath-0.1.16-cp311-cp311-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5d603668d167b1d694625f433fea638b94a6dea4ff6a82f15e42561893ca629
|
|
| MD5 |
a92910240a2cd7be144c29d3fc5a4bbd
|
|
| BLAKE2b-256 |
9815c540d37cb5c1379688f606e9d64cf48967942e01922a9ad801068181a123
|
File details
Details for the file finmath-0.1.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 111.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0170d2b645db0c73bb04aa18dbb1972aef4865fd2894dbc50321c9fdeb0ff5b9
|
|
| MD5 |
9a9a7954e90fd2163426a24258b5ee57
|
|
| BLAKE2b-256 |
484c8fe8b6e10caaec4f9e838ffbfc2d4b7b21748ed6654fc0226d5cabcad070
|
File details
Details for the file finmath-0.1.16-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 92.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7ad2a36107db20ac4eeb2135e1c9fe049d1b741d39741bae686bddca3a32b1d
|
|
| MD5 |
4ca411c7277550e1bba99dae822ecdde
|
|
| BLAKE2b-256 |
a94e38b4359663255a49cf33cb3ff480fa416b190598fc326bd9086be582899f
|
File details
Details for the file finmath-0.1.16-cp310-cp310-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c582f4f273dcade792049c03097f1e7bf06ba775b430078d1e3c49e18178fff9
|
|
| MD5 |
b4737d2fbe175114dfd556a2a6efc96f
|
|
| BLAKE2b-256 |
8c316aa069e7dda14639514319d39baf4de36650487f01c0043059bde6a7c33c
|
File details
Details for the file finmath-0.1.16-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 112.0 kB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4e9c3c820c9070cd0dd75ea48c25dbd5948b8ca10fb5c5c0fac326f2077a454
|
|
| MD5 |
74365b6e9d3859dd9ee9ffbe107ac07a
|
|
| BLAKE2b-256 |
9d9482fa5432ffc2f2b3392f85e035e691d70ab8d2d5347d915ef46dafbf14bf
|
File details
Details for the file finmath-0.1.16-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 92.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b668e5e1f75273dd85025080508b19e4936c437bc97d49e90e117fa92497b2c
|
|
| MD5 |
678d3c5b085d23f02a098c27f52ebb53
|
|
| BLAKE2b-256 |
37e63ff8c9b023f8d995ac81a177e5b8dba4d701690440fa2fd081b2b966c14e
|
File details
Details for the file finmath-0.1.16-cp39-cp39-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp39-cp39-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a008c96b197b98455474b8c7c7b04bcfdd252369895ff98635272fd68fbdf47f
|
|
| MD5 |
4f8b3f942d72631c23fd184ee1e63684
|
|
| BLAKE2b-256 |
dc8595cd4f826805e2d1304b36186bace50f196a804e7e5d60e0e6e71d2b0a98
|
File details
Details for the file finmath-0.1.16-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: finmath-0.1.16-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 112.3 kB
- Tags: CPython 3.9, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21a095e2836ec307e63db46ec9c8c1ccb5d0bee677c6095ab9da5f75ba6adb0c
|
|
| MD5 |
4256707a173cb77f35ff7309a22b1b96
|
|
| BLAKE2b-256 |
07d70cd9846f1f08f3a40c04bf5616f38bc63d455fd7cc9441798f55edfb0bbc
|
File details
Details for the file finmath-0.1.16-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: finmath-0.1.16-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 92.7 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ae37b31ce045bb5c2848022733edcca97a5812facafb4da2da2ef58fb007413
|
|
| MD5 |
cf57884a31e41b98e22002253419b561
|
|
| BLAKE2b-256 |
0cb89328788393da18248d207b2c842a3f719d2d1836a467b1d2c44376d1d3ec
|