SkillAgentSearch skills...

Quantrs

A (very) fast Rust library for quantitative finance.

Install / Use

/learn @carlobortolan/Quantrs

README

quantrs

tests MIT/Apache 2.0 licensed Crate docs.rs codecov-quantrs Crates.io MSRV Crates.io downloads PyPI version

<!-- [![Python versions](https://img.shields.io/pypi/pyversions/quantrs.svg)](https://pypi.org/project/quantrs/) --> <!-- [![PyPI downloads](https://img.shields.io/pypi/dm/quantrs.svg)](https://pypi.org/project/quantrs/) -->

Quantrs is a tiny quantitative finance library for Rust. It is designed to be as intuitive and easy to use as possible so that you can work with derivatives without the need to write complex code or have a PhD in reading QuantLib documentation. The library is still in the early stages of development and many features are not yet implemented.

Please check out the documentation here.

Python bindings are also available; see the Python README or the PyPI page.

Features

Options Pricing

Quantrs supports options pricing with various models for both vanilla and exotic options as well as options trading strategies for both basic options spreads and non-directional strategies.

<details> <summary><i>Click to see supported models</i></summary>

| | Black-Scholes | Black-76 | Lattice | ³Monte-Carlo | Finite Diff | Heston | | --------------------------- | --------------- | -------- | ------------ | ------------ | ------------- | ------ | | European | ✅ | ✅ | ✅ | ✅ | ⏳ | ⏳ | | American | ❌ | ❌ | ✅ | ❌ (L. Sq.) | ⏳ | ❌ | | Bermudan | ❌ | ❌ | ✅ | ❌ (L. Sq.) | ❌ (complex) | ❌ | | ¹Basket | ⏳ (∀component) | ❌ | ⏳ (approx.) | ⏳ | ❌ | ❌ | | ¹Rainbow | ✅ (∀component) | ❌ | ✅ | ✅ | ❌ | ❌ | | ²Barrier | ❌ (mod. BSM) | ❌ | ⏳ | ⏳ | ⏳ | ⏳ | | ²Double Barrier | ❌ (mod. BSM) | ❌ | ⏳ | ⏳ | ❌ (complex) | ⏳ | | ²Asian (fixed strike) | ❌ (mod. BSM) | ❌ | ❌ | ✅ | ⏳ | ⏳ | | ²Asian (floating strike) | ❌ (mod. BSM) | ❌ | ❌ | ✅ | ⏳ | ⏳ | | ²Lookback (fixed strike) | ❌ | ❌ | ❌ | ✅ | ⏳ | ⏳ | | ²Lookback (floating strike) | ✅ | ❌ | ❌ | ✅ | ⏳ | ⏳ | | ²Binary Cash-or-Nothing | ✅ | ❌ | ✅ | ✅ | ❌ (mod. PDE) | ⏳ | | ²Binary Asset-or-Nothing | ✅ | ❌ | ✅ | ✅ | ❌ (mod. PDE) | ⏳ | | Greeks (Δ,ν,Θ,ρ,Γ) | ✅ | ✅ | ⏳ | ❌ | ❌ | ❌ | | Implied Volatility | ✅ | ⏳ | ⏳ | ❌ | ❌ | ❌ |

¹ "Exotic" options with standard exercise style; only differ in their payoff value
² Non-vanilla path-dependent "exotic" options
³ MC simulates underlying price paths based on geometric Brownian motion for Black-Scholes models and both arithmetic or geometric average price paths for Asian and Lookback options
✅ = Supported, ⏳ = Planned / In progress, ❌ = Not supported / Not applicable

<!--Bachelier and Modified Bachelier--> </details> <details> <summary><i>Click to see supported strategies</i></summary>

| Strategy Name | Type | Description | | ------------------------ | ------------ | ------------------------------------------------------------------------------------------------- | | Covered Call | Income | Long stock + short call | | Protective Put | Hedging | Long stock + long put | | Guts | Volatility | Long ITM call + long ITM put | | Straddle | Volatility | Long ATM call + long ATM put | | Strangle | Volatility | Long OTM call + long OTM put | | Butterfly Spread | ¹Spread | Long ITM call, short two ATM calls, long OTM call (or all puts) | | Iron Butterfly | ¹Spread | Short straddle + long wings | | Christmas Tree Butterfly | ¹Spread | Long 1 ATM call, short 3 OTM calls, long 2 high-strike OTM calls (or all puts) | | Condor Spread | ¹Spread | Long low-strike ITM call, short ITM call, short OTM call, long high-strike OTM call (or all puts) | | Iron Condor | ¹Spread | Short strangle + long wings | | Calendar Spread | ²Time Spread | Long far-expiry ATM call + short near-expiry ATM call (or all puts) | | Diagonal Spread | ³Time Spread | Short near-expiry OTM call + long far-expiry further OTM call (or all puts) | | Back Spread | Directional | Long 2 OTM calls + short 1 ATM call (or all puts) |

¹ Also referred to as 'vertical'
² Also referred to as 'horizontal'
³ Also referred to as 'diagonal'

</details>

Fixed Income

  • Bond Types
    • [x] Zero-Coupon Bonds
    • [ ] Treasury Bonds (fixed-rate coupon)
    • [ ] Corporate Bonds (fixed-rate coupon with credit spreads)
    • [ ] Floating-Rate Bonds (variable coupon with caps/floors)
  • [ ] Duration (Macaulay, Modified, Effective)
  • [ ] Convexity
  • [ ] Yield Measures (YTM, YTC, YTW)
  • [x] Day Count Conventions (ACT/365F, ACT/365, ACT/360, 30/360 US, 30/360 Eurobond, ACT/ACT ISDA, ACT/ACT ICMA)

Usage

Add this to your Cargo.toml:

[dependencies]
quantrs = "0.1.8"

Now if you want to e.g., calculate the arbitrage-free price of a binary cash-or-nothing call using the Black-Scholes model, you can:

use quantrs::options::*;

// Create a new instrument with a spot price of 100 and a dividend yield of 2%
let instrument = Instrument::new().with_spot(100.0).with_cont_yield(0.02);

// Create a new Cash-or-Nothing binary call option with:
// - Strike price (K) = 85
// - Time to maturity (T) = 0.78 years
let option = BinaryOption::cash_or_nothing(instrument, 85.0, 0.78, Call);

// Create a new Black-Scholes model with:
// - Risk-free interest rate (r) = 5%
// - Volatility (σ) = 20%
let model = BlackScholesModel::new(0.05, 0.2);

// Calculate the price of the binary call option using the Black-Scholes model
println!("Price: {}", model.price(&option));

// Calculate first order greeks for the option
println!("{:?}", Greeks::calculate(&model, &option));

This will output:

Price: 0.8006934914644723
Greeks { delta: 0.013645840354947947, gamma: -0.0008813766475726433, theta: 0.17537248302290848, vega: -1.3749475702133236, rho: 0.4398346243436515 }

Plotting

Quantrs also supports plotting option prices and strategies using the plotters backend.

E.g., Plot the P/L of a slightly skewed Condor spread consisting of fixed-strike Asian calls using the Monte-Carlo model with the geometric average price path:

<details> <summary><i>Click to see example code</i></summary>
use quantrs::options::*;

// Create a new instrument with a spot price of 100 and a dividend yield of 2%
let instrument = Instrument::new().with_spot(100.0).with_cont_yield(0.02);

// Create a vector of fixed-strike Asian calls options with different strike prices
let options = [
    AsianOption::fixed(instrument.clone(), 85.0, 1.0, Call),
    AsianOption::fixed(instrument.clone(), 95.0, 1.0, Call),
    AsianOption::fixed(instrument.clone(), 102.0, 1.0, Call),
    AsianOption::fixed(instrument.clone(), 115.0, 1.0, Call),
];

// Create a new Monte-Carlo model with:
// - Risk-free interest rate (r) = 5%
// - Volatility (σ) = 20%
// - Number of simulations = 10,000
// - Number of time steps = 252
let model = MonteCarloModel::geometric(0.05, 0.2, 10_000, 252);

// Plot a breakdown of the Condor spread with a spot price range of [80,120]
model.plot_strategy_breakdown(
    "Condor Example",
    model.condor(&options[0], &options[1], &options[2], &options[3]),
    80.0..120.0,
    "examples/images/strategy.png",
    &options,
);
</details>

condor_strategy

<!--<div align="center">

Related Skills

View on GitHub
GitHub Stars19
CategoryFinance
Updated8d ago
Forks5

Languages

Rust

Security Score

95/100

Audited on Mar 28, 2026

No findings