options_pricing/
options_pricing.rs1use solmath::{bs_full_hp, fp, SolMathError, SCALE};
2
3fn as_decimal(x: u128) -> f64 {
4 x as f64 / SCALE as f64
5}
6
7fn main() -> Result<(), SolMathError> {
8 let spot = fp("100")?;
11 let strike = fp("105")?;
12 let risk_free_rate = fp("0.05")?;
13 let volatility = fp("0.20")?;
14 let years_to_expiry = fp("1")?;
15
16 let greeks = bs_full_hp(spot, strike, risk_free_rate, volatility, years_to_expiry)?;
17
18 println!("call: {:.12}", as_decimal(greeks.call));
19 println!("put: {:.12}", as_decimal(greeks.put));
20 println!("gamma: {:.12}", greeks.gamma as f64 / SCALE as f64);
21 println!("vega: {:.12}", greeks.vega as f64 / SCALE as f64);
22
23 Ok(())
24}