Struct Inputs

Source
pub struct Inputs {
    pub option_type: OptionType,
    pub s: f64,
    pub k: f64,
    pub p: Option<f64>,
    pub r: f64,
    pub q: f64,
    pub t: f64,
    pub sigma: Option<f64>,
}
Expand description

The inputs to the Black-Scholes-Merton model.

Fields§

§option_type: OptionType

The type of the option (call or put)

§s: f64

Stock price

§k: f64

Strike price

§p: Option<f64>

Option price

§r: f64

Risk-free rate

§q: f64

Dividend yield

§t: f64

Time to maturity in years

§sigma: Option<f64>

Volatility

Implementations§

Source§

impl Inputs

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

Source

pub fn new( option_type: OptionType, s: f64, k: f64, p: Option<f64>, r: f64, q: f64, t: f64, sigma: Option<f64>, ) -> 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;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
§Returns

An instance of the Inputs struct.

Source

pub fn __str__(&self) -> String

§Returns

string representation of the Inputs struct.

Source

pub fn calc_price(&self) -> PyResult<f64>

Calculates the price of the option.

§Requires

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

§Returns

f64 of the price of the option.

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let price = inputs.calc_price();
Source

pub fn calc_delta(&self) -> PyResult<f64>

Calculates the delta of the option.

§Requires

s, k, r, q, t, sigma

§Returns

f64 of the delta of the option.

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let delta = inputs.calc_delta();
Source

pub fn calc_gamma(&self) -> PyResult<f64>

Calculates the gamma of the option.

§Requires

s, k, r, q, t, sigma

§Returns

f64 of the gamma of the option.

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let gamma = inputs.calc_gamma();
Source

pub fn calc_theta(&self) -> PyResult<f64>

Calculates the theta of the option. Uses 365.25 days in a year for calculations.

§Requires

s, k, r, q, t, sigma

§Returns

f64 of theta per day (not per year).

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let theta = inputs.calc_theta();
Source

pub fn calc_vega(&self) -> PyResult<f64>

Calculates the vega of the option.

§Requires

s, k, r, q, t, sigma

§Returns

f64 of the vega of the option.

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let vega = inputs.calc_vega();
Source

pub fn calc_rho(&self) -> PyResult<f64>

Calculates the rho of the option.

§Requires

s, k, r, q, t, sigma

§Returns

f64 of the rho of the option.

§Example
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20/365.25, Some(0.2));
let rho = inputs.calc_rho();
Source

pub fn calc_iv(&self, tolerance: f64) -> PyResult<f64>

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

f64 of the implied volatility of the option.

§Example:
use blackscholes::Inputs;
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, Some(10), 0.05, 0.02, 20.0 / 365.25, None);
let iv = inputs.calc_iv(0.0001);

Trait Implementations§

Source§

impl Clone for Inputs

Source§

fn clone(&self) -> Inputs

Returns a duplicate 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<'_>) -> Result

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

impl IntoPy<Py<PyAny>> for Inputs

Source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
Source§

impl PyClass for Inputs

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for Inputs

Source§

const DOC: &'static str = "Inputs(option_type, s, k, p, r, q, t, sigma, /)\n--\n\nThe inputs to the Black-Scholes-Merton model.\u{0}"

Class doc string
Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

type Layout = PyCell<Inputs>

Layout
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = ThreadCheckerStub<Inputs>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Inputs

Source§

type Holder = Option<PyRef<'py, Inputs>>

Source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Inputs

Source§

type Holder = Option<PyRefMut<'py, Inputs>>

Source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

Source§

impl PyMethods<Inputs> for PyClassImplCollector<Inputs>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for Inputs

Source§

const NAME: &'static str = "Inputs"

Class name.
Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
Source§

type AsRefTarget = PyCell<Inputs>

Utility type to make Py::as_ref work.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type.

Auto Trait Implementations§

§

impl Freeze for Inputs

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromPyObject<'a> for T
where T: PyClass + Clone,

Source§

fn extract(obj: &'a PyAny) -> Result<T, PyErr>

Extracts Self from the source PyObject.
Source§

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

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> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> PyTypeObject for T
where T: PyTypeInfo,

Source§

impl<T> Ungil for T
where T: Send,