50个版本 (31个重大更新)
0.32.1 | 2021年9月4日 |
---|---|
0.31.1 | 2020年11月23日 |
0.28.1 | 2020年1月11日 |
0.28.0 | 2019年3月2日 |
0.20.0 | 2018年7月26日 |
#7 in #定价
每月下载量 127
在 2 crates 中使用
71KB
1.5K SLoC
[lin-badge]: https://github.com/danielhstahl/fang_oost_option_rust/workflows/Rust/badge.svg [cov-badge]: https://codecov.io/gh/danielhstahl/fang_oost_option_rust/branch/master/graph/badge.svg
Linux | Codecov |
---|---|
![lin-badge] | ![cov-badge] |
Fang-Oosterlee Rust期权定价
在Rust中实现Fang-Oosterlee期权定价。文档位于docs.rs
使用
该crate可在crates.io上找到。
导入和使用
extern crate num_complex;
use num_complex::Complex;
extern crate fang_oost_option;
use rayon::prelude::*;
use fang_oost_option::option_pricing;
let num_u:usize = 256;
let asset = 50.0;
let strikes = vec![75.0, 50.0, 40.0];
// max_strike sets the domain of the empirical estimate.
// This should be large enough to capture the potential
// dynamics of the underlying, but not too large or accuracy
// will sacrificed. A good rule of thumb is to scale this
// in proportion to the volatility of the underlying. For
// example, if the underlying is 50.0 and has a (log)
// volatility of 0.3, then a good max strike would be
// exp(0.3*scale)*50.0. I tend to use scale=10, yielding
// in this example ~1004.
let max_strike = 1004.0;
let rate = 0.03;
let t_maturity = 0.5;
let volatility:f64 = 0.3;
//As an example, cf is standard diffusion
let cf = |u: &Complex<f64>| {
((rate-volatility*volatility*0.5)*t_maturity*u+volatility*volatility*t_maturity*u*u*0.5).exp()
};
let prices: Vec<fang_oost::GraphElement>= option_pricing::fang_oost_call_price(
num_u, asset, &strikes, max_strike,
rate, t_maturity, &cf
).collect();
速度
基准测试与我的C++实现相当。要运行带有基准测试的测试,请使用cargo bench
。您可以在https://danielhstahl.github.io/fang_oost_option_rust/report/index.html查看基准测试。
依赖项
~2–2.9MB
~60K SLoC