1个不稳定版本
0.2.1 | 2021年1月6日 |
---|
#1136 在 WebAssembly
235KB
861 行
opcalc
一个易于使用的Black-Scholes期权计算器。适用于JS,用Rust构建。
入门指南
在JavaScript中使用库
您可以使用以下方式配置期权计算实例
// Import opcalc as a webassembly module
const option = opcalc
.create_option()
.with_asset_price(100)
.with_strike(105)
.with_volatility(0.2)
.with_interest(0.005)
.with_current_time(1606780800) // timestamp in seconds: 2020/12/01 00:00:00
.with_maturity_time(1610668800) // timestamp in seconds: 2021/01/15 00:00:00
.finalize();
创建期权后,您可以通过以下方式访问其价格(看涨和看跌)、希腊字母(delta、gamma等)
const call = option.call_value();
const delta = option.call_delta();
// ...
示例
在/examples
文件夹中提供了多个使用此库的示例。
- React
- Angular(即将推出)
- Vue.js(即将推出)
在Rust中使用库
在Rust中使用库的体验与JavaScript中类似。
use opcalc::option::builder::BSOptionBuilder;
let option = BSOptionBuilder::new()
.with_asset_price(100.0)
.with_strike(105.0)
.with_interest(0.008)
.with_volatility(0.23)
.with_current_time(1_606_780_800) // timestamp in seconds: 2020/12/01 00:00:00
.with_maturity_time(1_610_668_800) // timestamp in seconds: 2021/01/15 00:00:00
.finalize()
.unwrap(); // safely unwrap here because all required builder steps are taken
// then, use this option to obtain calculation results
let gamma = option.call_gamma();
贡献
想要贡献?请参阅我们的贡献指南。
依赖项
~11MB
~197K SLoC