Struct blackscholes_wasm::Inputs
source · pub struct Inputs {
pub option_type: OptionType,
pub s: f32,
pub k: f32,
pub p: Option<f32>,
pub r: f32,
pub q: f32,
pub t: f32,
pub sigma: Option<f32>,
}
Expand description
The inputs to the Black-Scholes-Merton model.
Fields§
§option_type: OptionType
The type of the option (call or put)
s: f32
Stock price
k: f32
Strike price
p: Option<f32>
Option price
r: f32
Risk-free rate
q: f32
Dividend yield
t: f32
Time to maturity in years
sigma: Option<f32>
Volatility
Implementations§
source§impl Inputs
impl Inputs
sourcepub fn calc_delta(&self) -> Result<f32, String>
pub fn calc_delta(&self) -> Result<f32, String>
sourcepub fn calc_gamma(&self) -> Result<f32, String>
pub fn calc_gamma(&self) -> Result<f32, String>
sourcepub fn calc_theta(&self) -> Result<f32, String>
pub fn calc_theta(&self) -> Result<f32, String>
Calculates the theta of the option. Uses 365.25 days in a year for calculations.
Requires
s, k, r, q, t, sigma
Returns
f32 of theta per day (not per year).
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let theta = inputs.calc_theta().unwrap();
sourcepub fn calc_epsilon(&self) -> Result<f32, String>
pub fn calc_epsilon(&self) -> Result<f32, String>
Calculates the epsilon of the option.
Requires
s, k, r, q, t, sigma
Returns
f32 of the epsilon of the option.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let epsilon = inputs.calc_epsilon().unwrap();
sourcepub fn calc_lambda(&self) -> Result<f32, String>
pub fn calc_lambda(&self) -> Result<f32, String>
sourcepub fn calc_vanna(&self) -> Result<f32, String>
pub fn calc_vanna(&self) -> Result<f32, String>
sourcepub fn calc_charm(&self) -> Result<f32, String>
pub fn calc_charm(&self) -> Result<f32, String>
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let charm = inputs.calc_charm().unwrap();
sourcepub fn calc_vomma(&self) -> Result<f32, String>
pub fn calc_vomma(&self) -> Result<f32, String>
sourcepub fn calc_speed(&self) -> Result<f32, String>
pub fn calc_speed(&self) -> Result<f32, String>
sourcepub fn calc_zomma(&self) -> Result<f32, String>
pub fn calc_zomma(&self) -> Result<f32, String>
sourcepub fn calc_color(&self) -> Result<f32, String>
pub fn calc_color(&self) -> Result<f32, String>
sourcepub fn calc_ultima(&self) -> Result<f32, String>
pub fn calc_ultima(&self) -> Result<f32, String>
sourcepub fn calc_dual_delta(&self) -> Result<f32, String>
pub fn calc_dual_delta(&self) -> Result<f32, String>
Calculates the dual delta of the option.
Requires
s, k, r, q, t, sigma
Returns
f32 of the dual delta of the option.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let dual_delta = inputs.calc_dual_delta().unwrap();
sourcepub fn calc_dual_gamma(&self) -> Result<f32, String>
pub fn calc_dual_gamma(&self) -> Result<f32, String>
Calculates the dual gamma of the option.
Requires
s, k, r, q, t, sigma
Returns
f32 of the dual gamma of the option.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let dual_gamma = inputs.calc_dual_gamma().unwrap();
sourcepub fn calc_all_greeks(&self) -> Result<String, String>
pub fn calc_all_greeks(&self) -> Result<String, String>
Calculates all Greeks of the option.
Requires
s, k, r, q, t, sigma
Returns
HashMap of type <String, f32> of all Greeks of the option.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let greeks = inputs.calc_all_greeks().unwrap();
source§impl Inputs
impl Inputs
sourcepub fn calc_iv(&self, tolerance: f32) -> Result<f32, String>
pub fn calc_iv(&self, tolerance: f32) -> Result<f32, String>
Calculates the implied volatility of the option. Tolerance is the max error allowed for the implied volatility, the lower the tolerance the more iterations will be required. Recommended to be a value between 0.001 - 0.0001 for highest efficiency/accuracy. Initializes estimation of sigma using Brenn and Subrahmanyam (1998) method of calculating initial iv estimation. Uses Newton Raphson algorithm to calculate implied volatility.
Requires
s, k, r, q, t, p
Returns
f32 of the implied volatility of the option.
Example:
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, Some(0.2), 0.05, 0.2, 20.0/365.25, None);
let iv = inputs.calc_iv(0.0001).unwrap();
source§impl Inputs
impl Inputs
Methods for calculating the price, greeks, and implied volatility of an option.
sourcepub fn new(
option_type: OptionType,
s: f32,
k: f32,
p: Option<f32>,
r: f32,
q: f32,
t: f32,
sigma: Option<f32>
) -> Self
pub fn new( option_type: OptionType, s: f32, k: f32, p: Option<f32>, r: f32, q: f32, t: f32, sigma: Option<f32> ) -> Self
Creates instance ot the Inputs
struct.
Arguments
option_type
- The type of option to be priced.s
- The current price of the underlying asset.k
- The strike price of the option.p
- The dividend yield of the underlying asset.r
- The risk-free interest rate.q
- The dividend yield of the underlying asset.t
- The time to maturity of the option in years.sigma
- The volatility of the underlying asset.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
Returns
An instance of the Inputs
struct.
Trait Implementations§
source§impl FromWasmAbi for Inputs
impl FromWasmAbi for Inputs
source§impl IntoWasmAbi for Inputs
impl IntoWasmAbi for Inputs
source§impl LongRefFromWasmAbi for Inputs
impl LongRefFromWasmAbi for Inputs
source§impl OptionFromWasmAbi for Inputs
impl OptionFromWasmAbi for Inputs
source§impl OptionIntoWasmAbi for Inputs
impl OptionIntoWasmAbi for Inputs
source§impl PartialEq<Inputs> for Inputs
impl PartialEq<Inputs> for Inputs
source§impl RefFromWasmAbi for Inputs
impl RefFromWasmAbi for Inputs
source§impl RefMutFromWasmAbi for Inputs
impl RefMutFromWasmAbi for Inputs
impl Copy for Inputs
impl StructuralPartialEq for Inputs
Auto Trait Implementations§
impl RefUnwindSafe for Inputs
impl Send for Inputs
impl Sync for Inputs
impl Unpin for Inputs
impl UnwindSafe for Inputs
Blanket Implementations§
source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.