# Struct blackscholes_python::Inputs

``````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

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

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.

##### Returns

string representation of the `Inputs` struct.

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

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

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

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

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

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

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.

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

Returns a copy of the value. Read more
Performs copy-assignment from `source`. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Performs the conversion.
Whether the pyclass is frozen. Read more
Class doc string
#[pyclass(subclass)]
#[pyclass(extends=…)]
#[pyclass(mapping)]
#[pyclass(sequence)]
Layout
Base class
This handles following two situations: Read more
Immutable or mutable
Specify this class has `#[pyclass(dict)]` or not.
Specify this class has `#[pyclass(weakref)]` or not.
The closest native ancestor. This is `PyAny` by default, and when you declare `#[pyclass(extends=PyDict)]`, it’s `PyDict`. Read more
Utility type to make Py::as_ref work.
Class name.
Module name, if any.
Returns the PyTypeObject instance for this type.
Returns the safe abstraction over the type object.
Checks if `object` is an instance of this type or a subclass of this type.
Checks if `object` is an instance of this type.

## Blanket Implementations

Gets the `TypeId` of `self`. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Extracts `Self` from the source `PyObject`.

Calls `U::from(self)`.

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

Arguments for exception
Should always be `Self`
The inverse inclusion map: attempts to construct `self` from the equivalent element of its superset. Read more
Checks if `self` is actually part of its subset `T` (and can be converted to it).
Use with care! Same as `self.to_subset` but without any property checks. Always succeeds.
The inclusion map: converts `self` to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a `String`. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.