RustQuant

Rust library for quantitative finance tools.

Contact: rustquantcontact@gmail.com

Latest additions:

Disclaimer: This is currently a free-time project and not a professional financial software library. Nothing in this library should be taken as financial advice, and I do not recommend you to use it for trading or making financial decisions.

Table of Contents

  1. Automatic Differentiation
  2. Option Pricers
  3. Stochastic Processes and Short Rate Models
  4. Bonds
  5. Random
  6. Mathematics
  7. Helper Functions and Macros
  8. How-tos
  9. References

Automatic Differentiation

Currently only gradients can be computed. Suggestions on how to extend the functionality to Hessian matrices are definitely welcome.

Option Pricers

The stochastic process generators can be used to price path-dependent options via Monte-Carlo.

Stochastic Processes and Short Rate Models

The following is a list of stochastic processes that can be generated.

Bonds

Most will follow the notation and formulas in John C. Hull's Options, Futures, and Other Derivatives.

Random

Mathematics

Helper Functions and Macros

A collection of utility functions and macros.

How-tos

Compute gradients:

```rust use RustQuant::autodiff::*;

fn main() { // Create a new Tape. let t = Tape::new();

// Assign variables.
let x = t.var(0.5);
let y = t.var(4.2);

// Define a function.
let z = x * y + x.sin();

// Accumulate the gradient.
let grad = z.accumulate();

println!("Function = {}", z);
println!("Gradient = {:?}", grad.wrt([x, y]));

} ```

Compute integrals:

```rust use RustQuant::math::*;

fn main() { // Define a function to integrate: e^(sin(x)) fn f(x: f64) -> f64 { (x.sin()).exp() }

// Integrate from 0 to 5.
let integral = integrate(f, 0.0, 5.0);

// ~ 7.18911925
println!("Integral = {}", integral);

} ```

Price options:

```rust use RustQuant::options::*;

fn main() { let VanillaOption = EuropeanOption { initialprice: 100.0, strikeprice: 110.0, riskfreerate: 0.05, volatility: 0.2, dividendrate: 0.02, timeto_maturity: 0.5, };

let prices = VanillaOption.price();

println!("Call price = {}", prices.0);
println!("Put price = {}", prices.1);

} ```

Generate stochastic processes:

```rust use RustQuant::stochastics::*;

fn main() { // Create new GBM with mu and sigma. let gbm = GeometricBrownianMotion::new(0.05, 0.9);

// Generate path using Euler-Maruyama scheme.
// Parameters: x_0, t_0, t_n, n, sims, parallel.
let output = (&gbm).euler_maruyama(10.0, 0.0, 0.5, 10, 1, false);

println!("GBM = {:?}", output.trajectories);

} ```

References: