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

source

pub fn calc_delta(&self) -> Result<f32, String>

Calculates the delta of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the 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 delta = inputs.calc_delta().unwrap();
source

pub fn calc_gamma(&self) -> Result<f32, String>

Calculates the gamma of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the 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 gamma = inputs.calc_gamma().unwrap();
source

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();
source

pub fn calc_vega(&self) -> Result<f32, String>

Calculates the vega of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the vega 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 vega = inputs.calc_vega().unwrap();
source

pub fn calc_rho(&self) -> Result<f32, String>

Calculates the rho of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the rho 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 rho = inputs.calc_rho().unwrap();
source

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();
source

pub fn calc_lambda(&self) -> Result<f32, String>

Calculates the lambda of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the lambda 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 lambda = inputs.calc_lambda().unwrap();
source

pub fn calc_vanna(&self) -> Result<f32, String>

Calculates the vanna of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the vanna 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 vanna = inputs.calc_vanna().unwrap();
source

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();
source

pub fn calc_veta(&self) -> Result<f32, String>

Calculates the veta of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the veta 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 veta = inputs.calc_veta().unwrap();
source

pub fn calc_vomma(&self) -> Result<f32, String>

Calculates the vomma of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the vomma 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 vomma = inputs.calc_vomma().unwrap();
source

pub fn calc_speed(&self) -> Result<f32, String>

Calculates the speed of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the speed 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 speed = inputs.calc_speed().unwrap();
source

pub fn calc_zomma(&self) -> Result<f32, String>

Calculates the zomma of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the zomma 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 zomma = inputs.calc_zomma().unwrap();
source

pub fn calc_color(&self) -> Result<f32, String>

Calculates the color of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the color 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 color = inputs.calc_color().unwrap();
source

pub fn calc_ultima(&self) -> Result<f32, String>

Calculates the ultima of the option.

Requires

s, k, r, q, t, sigma

Returns

f32 of the ultima 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 ultima = inputs.calc_ultima().unwrap();
source

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();
source

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();
source

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

source

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

Methods for calculating the price, greeks, and implied volatility of an option.

source

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.

source§

impl Inputs

source

pub fn calc_price(&self) -> Result<f32, String>

Calculates the price of the option.

Requires

s, k, r, q, t, sigma.

Returns

f32 of the price 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 price = inputs.calc_price().unwrap();

Trait Implementations§

source§

impl Clone for Inputs

source§

fn clone(&self) -> Inputs

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Inputs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Inputs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> fmtResult

Formats the value using the given formatter. Read more
source§

impl From<Inputs> for JsValue

source§

fn from(value: Inputs) -> Self

Converts to this type from the input type.
source§

impl FromWasmAbi for Inputs

§

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary.
source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
source§

impl IntoWasmAbi for Inputs

§

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary.
source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
source§

impl LongRefFromWasmAbi for Inputs

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = Ref<'static, Inputs>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl OptionFromWasmAbi for Inputs

source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
source§

impl OptionIntoWasmAbi for Inputs

source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
source§

impl PartialEq<Inputs> for Inputs

source§

fn eq(&self, other: &Inputs) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RefFromWasmAbi for Inputs

§

type Abi = u32

The wasm ABI type references to Self are recovered from.
§

type Anchor = Ref<'static, Inputs>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
source§

impl RefMutFromWasmAbi for Inputs

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = RefMut<'static, Inputs>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl WasmDescribe for Inputs

source§

impl Copy for Inputs

source§

impl StructuralPartialEq for Inputs

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ReturnWasmAbi for Twhere T: IntoWasmAbi,

§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,