This repository is a Python pricing library for common rates and equity derivatives. It integrates the existing interest-rate swap work into a reusable rates module, adds an ASR module inspired by the existing ASR implementation, and extends the library to European options, American options, stochastic-volatility options, equity forwards, and arithmetic Asian options.
pricing_library/
core/
curves.py # Discount curves, flat curves, interpolation, compounding
daycount.py # ACT/360, ACT/365F, 30/360
schedule.py # Market calendars, coupon schedules, business-day dates
rates/
swaps.py # Single-curve and multi-curve interest-rate swaps
equity/
options.py # Black-Scholes, binomial, local-vol, Heston Monte Carlo
forwards.py # Equity forward pricing
asian.py # Arithmetic Asian option Monte Carlo with variance reduction
asr.py # Accelerated share repurchase Monte Carlo
examples/
pricing_examples.py
tests/
test_pricing_library.py
The package has no required third-party runtime dependency.
python3 -m unittest discover -s tests
python3 -m examples.pricing_examplesFor editable installation:
python3 -m pip install -e .The schedule module supports weekend-only calendars, static custom holidays, and named rule-based calendars:
weekendus_federaltarget2nyse
Supported business-day adjustments are following, modified_following, preceding, and modified_preceding. Schedule generation also supports end-of-month rolling.
DiscountCurve supports:
- Zero-rate or discount-factor input
- Continuous, simple, annual, semiannual, quarterly, and monthly compounding
- Linear zero-rate interpolation
- Linear discount-factor interpolation
- Log-linear discount-factor interpolation
- Parallel zero-rate bumps
- Simple money-market discount-factor bootstrapping
A plain-vanilla fixed-vs-floating interest rate swap exchanges fixed coupons for floating coupons on a notional amount. No notional is exchanged.
Contractual features:
- Notional
- Fixed rate
- Payer or receiver direction
- Fixed and floating payment frequencies
- Fixed and floating day-count conventions
- Floating spread
- Coupon schedules with following, modified-following, preceding, and modified-preceding adjustment
- Weekend, custom-holiday, US Federal, TARGET2, and NYSE calendars
- End-of-month schedule generation
Pricing features:
- Single-curve pricing by default
- Optional separate discounting and floating-rate forecast curves
- Discount, forecast, and total DV01
Pricing math:
For payment dates
The floating forward for period
With spread
For a fixed-rate payer:
For a fixed-rate receiver, the sign is reversed. The par fixed rate is:
A European option can be exercised only at maturity. The library implements Black-Scholes-Merton closed-form valuation, CRR/Jarrow-Rudd/Tian binomial trees, optional local-volatility trees, and Heston stochastic-volatility Monte Carlo.
Contractual features:
- Call or put
- Spot
- Strike
- Maturity in years
- Continuously compounded risk-free rate
- Continuous dividend yield
- Volatility
- Quantity
Black-Scholes math:
European call:
European put:
The implementation also returns delta, gamma, vega, theta, and rho.
Heston Monte Carlo uses full-truncation Euler variance steps:
An American option can be exercised on any tree step up to maturity. There is no simple general closed form for American puts, so the library uses binomial trees. Supported tree models are crr, jarrow_rudd, and tian; a spot/time local-volatility callback is also available for smaller non-recombining trees.
Tree math:
At each node:
For American exercise:
An equity forward is an agreement to buy or sell stock at a fixed strike on a future date.
No-arbitrage forward price with continuous dividend yield:
Long forward PV:
An arithmetic Asian option pays based on the arithmetic average of observed prices rather than only the terminal price. The arithmetic-average payoff does not generally have a simple Black-Scholes closed form, so the library uses risk-neutral Monte Carlo.
Call payoff:
Put payoff:
where:
The simulated equity process is:
Variance-reduction options include:
- Antithetic paths
- Moment matching
- Geometric-average Asian control variate
The Monte Carlo result includes a standard error and 95% confidence interval.
An accelerated share repurchase is a structured equity transaction where a company pays a cash notional upfront, receives an initial delivery of shares, and later settles based on the average stock price over an averaging period.
Implemented contractual features:
- Cash notional
- Initial spot
- Current spot
- Upfront share delivery fraction
- Averaging dates
- Discount to average price
- Average cap and floor
- Variable notional multiplier between low and high average levels
- Discrete cash dividends
- Realized average and realized observation count for in-flight ASRs
Core settlement math:
Upfront shares:
Final net average:
Variable notional multiplier
Total shares deliverable:
Final settlement shares:
The ASR pricer reports the present value of final settlement shares from the corporate client's perspective:
The model uses risk-neutral Monte Carlo with optional antithetic paths. It is intentionally simpler than the legacy asr_pricer.py PDE script, which includes a Crank-Nicolson path-variable PDE and requires numpy/scipy.
from datetime import date
from pricing_library.core.curves import DiscountCurve
from pricing_library.rates import InterestRateSwapPricer, build_vanilla_interest_rate_swap
valuation_date = date(2026, 5, 15)
discount_curve = DiscountCurve(
valuation_date,
((0.0, 0.049), (1.0, 0.046), (3.0, 0.042), (5.0, 0.0405)),
interpolation="log_linear_discount",
)
forecast_curve = DiscountCurve(
valuation_date,
((0.0, 0.050), (1.0, 0.048), (3.0, 0.044), (5.0, 0.0420)),
interpolation="log_linear_discount",
)
swap = build_vanilla_interest_rate_swap(
valuation_date,
valuation_date,
date(2031, 5, 15),
notional=50_000_000,
fixed_rate=0.0415,
direction="payer",
calendar="us_federal",
)
value = InterestRateSwapPricer().price(swap, discount_curve, forecast_curve)
print(value.pv, value.par_rate, value.discount_dv01, value.forecast_dv01)Run all example products:
python3 -m examples.pricing_examples