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.
Key Features:
- Cross-platform SIMD optimizations (ARM NEON, x86 AVX/SSE) for 2-4x speedups
- Zero-copy NumPy integration for efficient memory usage
- 34-308x faster than pure Python/NumPy implementations
- Production-ready with comprehensive tests
- C++17 or later
- Python 3.6 or later
pybind11(for Python bindings)CMake3.10 or later (for building the library)
-
Clone the repository:
git clone https://github.com/Boiler-Quant/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.
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}")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;
}The library uses SIMD optimizations and zero-copy NumPy integration for maximum performance. See demos/ for benchmark comparisons.
Example with NumPy (zero-copy):
import finmath
import numpy as np
# Zero-copy NumPy arrays for best performance
prices = np.array([100, 101, 102, 103, 104, 105])
sma = finmath.simple_moving_average_simd(prices, window_size=3)
rsi = finmath.smoothed_rsi_simd(prices, window_size=14)Run the test suite:
cd build
ctestWe 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.
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
- Inspired by the
gs_quantlibrary for financial time series analysis. - Thanks to
pybind11for making it easy to integrate C++ and Python.