#linux #value #distribution #algorithm #compute #functions #density

fang_oost

A library implementing Fang and Oosterlee’s algorithm for inverting characteristic functions

25 releases (13 breaking)

0.14.2 Nov 23, 2020
0.14.0 Mar 2, 2019
0.13.8 Jan 12, 2019
0.13.7 Sep 11, 2018
0.7.0 Jul 16, 2018
Download history 66/week @ 2020-08-13 56/week @ 2020-08-20 41/week @ 2020-08-27 222/week @ 2020-09-03 32/week @ 2020-09-10 18/week @ 2020-09-17 17/week @ 2020-09-24 41/week @ 2020-10-01 79/week @ 2020-10-08 93/week @ 2020-10-15 92/week @ 2020-10-22 16/week @ 2020-10-29 21/week @ 2020-11-05 24/week @ 2020-11-12 80/week @ 2020-11-19 135/week @ 2020-11-26

241 downloads per month
Used in 5 crates (4 directly)

MIT license

21KB
300 lines

Linux Codecov
lin-badge cov-badge

Fang-Oosterlee Library for Rust

Implements Fang-Oosterlee algorithm in Rust. While the algorithm originally was used for option pricing, it can be used for a variety of use cases. For example, it can be used to compute the Value at Risk of a distribution, the density of a distribution, and the partial expectation.

It requires a characteristic function computed at various specific intervals. A utility function is provided which converts an analytical characteristic function into a vector.

Documentation is at docs.rs

Use

Put the following in your Cargo.toml:

[dependencies]
fang_oost = "0.13"

Import and use:

extern crate num_complex;
extern crate fang_oost;
extern crate rayon;
use rayon::prelude::*;
use num_complex::Complex;

let num_x = 1024;
let num_u = 256;
let x_min = -20.0;
let x_max = 25.0;
let mu=2.0;
let sigma:f64=5.0;
let norm_cf = |u:&Complex<f64>|(u*mu+0.5*u*u*sigma*sigma).exp();
let x_domain=fang_oost::get_x_domain(num_x, x_min, x_max);
//computes discrete gaussian characteristic function
let discrete_cf=fang_oost::get_discrete_cf(num_u, x_min, x_max, &norm_cf);
let density:Vec<f64> = fang_oost::get_density(
   x_min, x_max, x_domain, &discrete_cf
).collect();

Related Crates

Benchmarks

View benchmarks at https://phillyfan1138.github.io/fang_oost_rust/report/index.html.

Dependencies

~1.5MB
~35K SLoC