Struct blackscholes_python::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
sourceimpl Inputs
impl Inputs
Methods for calculating the price, greeks, and implied volatility of an option.
sourcepub fn new(
option_type: OptionType,
s: f64,
k: f64,
p: Option<f64>,
r: f64,
q: f64,
t: f64,
sigma: Option<f64>
) -> Self
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.
sourcepub fn calc_price(&self) -> PyResult<f64>
pub fn calc_price(&self) -> PyResult<f64>
sourcepub fn calc_delta(&self) -> PyResult<f64>
pub fn calc_delta(&self) -> PyResult<f64>
sourcepub fn calc_gamma(&self) -> PyResult<f64>
pub fn calc_gamma(&self) -> PyResult<f64>
sourcepub fn calc_theta(&self) -> PyResult<f64>
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();
sourcepub fn calc_iv(&self, tolerance: f64) -> PyResult<f64>
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
sourceimpl PyClassImpl for Inputs
impl PyClassImpl for Inputs
sourceconst IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
sourceconst IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
sourceconst IS_MAPPING: bool = false
const IS_MAPPING: bool = false
sourceconst IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
type ThreadChecker = ThreadCheckerStub<Inputs>
type ThreadChecker = ThreadCheckerStub<Inputs>
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type Dict = PyClassDummySlot
type Dict = PyClassDummySlot
#[pyclass(dict)]
or not.type WeakRef = PyClassDummySlot
type WeakRef = PyClassDummySlot
#[pyclass(weakref)]
or not.type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
. Read morefn items_iter() -> PyClassItemsIter
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
sourceimpl PyMethods<Inputs> for PyClassImplCollector<Inputs>
impl PyMethods<Inputs> for PyClassImplCollector<Inputs>
fn py_methods(self) -> &'static PyClassItems
sourceimpl PyTypeInfo for Inputs
impl PyTypeInfo for Inputs
type AsRefTarget = PyCell<Inputs>
type AsRefTarget = PyCell<Inputs>
sourcefn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
sourcefn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
sourcefn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.sourcefn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<'a, T> FromPyObject<'a> for Twhere
T: PyClass + Clone,
impl<'a, T> FromPyObject<'a> for Twhere
T: PyClass + Clone,
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 morefn 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.