How to Calculate Derivative Risks and Prices in Python at C++ Speed
If you've ever tried writing financial models for pricing options, swaps, or bonds in Python, you've likely encountered a well-known dilemma. On one hand, you have slow pure Python, where Monte Carlo simulations take too long. On the other hand, there are heavyweight libraries like QuantLib with C++ wrappers, where reading source code or debugging model behavior becomes a non-trivial task.
The FinancePy library offers a different path. It was created by Dominic O'Kane, a former finance professor at EDHEC Business School with twelve years of experience in the financial industry. He set out to create an open tool where all code is written in Python, and the calculation results are as close as possible to professional systems like Bloomberg.
How the project is structured
The library architecture revolves around a clear concept. Any valuation calculation is described by the formula:
Valuation = Product + Model + Market
In code, this looks logical. The library modules are split into several main directories:
- utils: dates, financial calendars, and payment schedule generators
- market: interest rate curves, volatility surfaces, and market prices
- models: mathematical pricing models from Black-Scholes to the Vasicek model
- products: specific instruments, broken down by Bonds, Credit, Equity, FX, and Rates categories
Each product has a value() method. You create a financial instrument object, pass it a model and the current market situation, and then get the value or risk parameters. For most products, the author added Monte Carlo simulations. This helps understand how contract payouts work over time.
How speed is achieved
FinancePy is written in pure Python, but actively uses the Numba library. On the first function call, the JIT compiler transforms the model mathematics into machine code. Because of this, the first import of a module may take a couple of seconds.
However, all subsequent calls take fractions of a millisecond. Compiled functions are stored in cache. As a result, you get C/C++-level speed while retaining the ability to open a source code file and read the algorithm line by line without compiling Cython or writing C extensions.
A clear example and notebooks
Installation is done with a standard pip call:
pip install financepy
You can then import date utilities:
from financepy.utils import Date
start_date = Date(19, 2, 2026)
future_date = start_date.add_days(2)
print(future_date) # 21-FEB-2026
Developers won't have to guess function signatures from source code. In the repository, you'll find over 90 Jupyter notebooks with ready-made examples. These contain detailed scenarios: from basic corporate bond valuation and currency barrier options to building complex discount curves and credit default swaps.
Code style and contributing
The author deliberately avoids complex inheritance and overloaded architecture. Readability and performance are prioritized over clever language tricks. A simple for loop in FinancePy code is preferred over an elaborate list comprehension, as Numba optimizes regular loops more effectively.
If you want to submit a pull request to the project, the author has clear requirements:
- Strict compliance with PEP8 standard
- Clear comments for every function and class
- Presence of unit tests and at least one integration test for each method
Is it worth using
FinancePy is suitable for quantitative analysts, risk and portfolio managers who need a clear tool for quick price and sensitivity verification. The project will also be useful for students and teachers of finance courses for learning derivative mathematics.
The project only requires NumPy, SciPy, and Numba as dependencies. The GPL-3.0 license provides access to all source code. The project is in beta status, and the author honestly warns about possible discrepancies in date generation or interpolation methods compared to proprietary terminals. However, for personal research, testing trading strategies, and quick derivative valuation, the library's capabilities are more than sufficient.
Related projects