Coder Social home page Coder Social logo

fang_oost_rust's Introduction

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.15"

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 result=fang_oost::get_expectation_single_element_real(
    x_min, x_max, x, &discrete_cf,
     |u_im, x, k|{
         if k==0{x-x_min} else { ((x-x_min)*u_im).sin()/u_im }
     }
);

Related Crates

Benchmarks

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

fang_oost_rust's People

Contributors

danielhstahl avatar changdaniel avatar

Stargazers

Eduardo Gallego avatar frankfanslc avatar Josep Rubió Piqué avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.