quantrs 0.1.3

A tiny Rust library for quantitative finance
Documentation

quantrs

tests MIT licensed Crate docs.rs codecov-quantrs Crates.io MSRV

Quantrs is a tiny quantitative finance library for Rust. It is designed to be simple and easy to use, with a focus on performance and correctness. It is still in the early stages of development, so expect bugs and breaking changes.

Please check out the documentation here.

Features

Options Pricing

For now quantrs only supports options pricing. The following features are available:

  • Option types: European, American, Binary Cash-or-Nothing, Binary Asset-or-Nothing
  • Option pricing: Black-Scholes, Binomial Tree, Monte Carlo Simulation
  • Greeks: Delta, Gamma, Theta, Vega, Rho
  • Implied volatility
Model Black-Scholes Binomial Tree Monte Carlo Simulation
European Options
American Options ❌ (not applicable)
Binary Cash-or-Nothing
Binary Asset-or-Nothing
Greeks
Implied Volatility

(✅ = Supported, ⏳ = Planned / In progress, ❌ = Not supported)

Usage

Add this to your Cargo.toml:

[dependencies]
quantrs = "0.1.3"

Now if you want to e.g., model binary call options using the Black-Scholes model, you can:

use quantrs::options::*;

fn main() {
    // 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_continuous_dividend_yield(0.02);

    // Create a new Cash-or-Nothing binary call option with a strike price of 85
    let option = BinaryOption::cash_or_nothing(instrument, 85.0, OptionType::Call);

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

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

    // Calculate the Greeks (Delta, Gamma, Theta, Vega, Rho) for the option
    let greeks = OptionGreeks::calculate(&model, option);
    println!("Greeks: {:?}\n", greeks);
}

This will output:

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

See the documentation for more information and examples.

Minimum supported Rust version (MSRV)

This crate requires a Rust version of 1.65.0 or higher. Increases in MSRV will be considered a semver non-breaking API change and require a version increase (PATCH until 1.0.0, MINOR after 1.0.0).

Outlook

Planned Features

  • Data retrieval
    • Yahoo Finance
    • Alpha Vantage
    • Quandl
    • IEX Cloud
  • Fixed income & IR
    • Bond pricing
    • Duration
    • Convexity
    • Yield curve
    • Term structure
    • Forward rates
    • Interest rate models
  • Time series analysis
    • Moving averages
    • Volatility
    • Correlation
    • Cointegration
    • ARIMA
    • GARCH
    • Kalman filter
  • Portfolio optimization
    • Mean-variance optimization
    • Black-Litterman model
    • Risk parity
    • Minimum variance
    • Maximum diversification

Contributing

If you find any bugs or have suggestions for improvement, please open a new issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.


© Carlo Bortolan

Carlo Bortolan  ·  GitHub carlobortolan  ·  contact via carlobortolan@gmail.com