Finance & Trading

QuantLib

The pricing math that Wall Street actually uses for bonds and options, free for anyone to run.

Install it: pip install quantlib

What does it do?

QuantLib provides the actual mathematical models banks and trading desks use to price complicated financial instruments, bond yields, interest rate swaps, and options whose value depends on unpredictable future prices. The Python version wraps a much larger library originally written in C++, so you get institutional-grade financial mathematics through simple Python code. It handles fiddly real-world details that make finance math hard in practice, like exactly how many days count in a financial year under different market conventions. This isn’t a beginner’s toy; it’s genuinely the kind of engine used in production trading systems.

See it in action

This uses professional-grade financial calendar math to figure out the correct business-day date six months after a given date, accounting for holidays and weekends.

import QuantLib as ql

today = ql.Date(15, 6, 2024)
ql.Settings.instance().evaluationDate = today
calendar = ql.TARGET()
maturity = calendar.advance(today, ql.Period(6, ql.Months))
print(maturity)

Why would a non-developer care?

Every time you’ve heard about a bank’s risk model or a complex financial product being mispriced, tools like QuantLib are the category of software meant to get that pricing right. It’s a rare case of genuinely institutional financial technology being available to anyone for free rather than locked inside a bank’s proprietary systems.

Real-world examples

QuantLib, in its original C++ form with these Python bindings as one of several wrappers, has been used inside real banks and financial institutions for actual derivatives pricing and risk management, not just as an academic exercise. Its open source nature means a graduate student and a bank’s quant desk can, in principle, run the very same options-pricing formula.

Who uses it

Quantitative analysts, finance graduate students, and risk teams who need rigorous, industry-standard financial models rather than a rough approximation.

How it compares to alternatives

It’s far more mathematically rigorous than lighter finance libraries like backtrader, which focus on strategy testing rather than precise instrument pricing; commercially it competes conceptually with expensive proprietary systems from vendors like Bloomberg or Numerix, at no cost.

Fun fact

QuantLib started as a C++ project in the early 2000s and has since grown bindings for Python, Java, Ruby, and several other languages, all sharing the same core pricing engine.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries