Skip to content

Models

Classes

BinomialOptionPricing

Class for Binomial Option Pricing.

Parameters:

Name Type Description Default
inputs OptionInputs

Object containing the following option parameters: - spot : float Current price of the underlying asset - strike : float Strike price of the option - rate : float Risk-free interest rate (as a decimal) - ttm : float Time to maturity in years - volatility : float Implied volatility of the underlying asset (as a decimal) - callprice : float, optional Market price of call option (used for implied volatility calculation) - putprice : float, optional Market price of put option (used for implied volatility calculation)

required
nsteps int

Number of steps

Field(..., gt=0, description='Number of steps')
option_type OptionType

Option type, either 'call' or 'put'

Field(..., description='Call or Put')
exercise_style ExerciseStyle

Exercise style, either 'american' or 'european'

Field(..., description='American or European')
output str

Output type ('price', 'payoff', 'value', 'delta'), by default 'payoff'

'payoff'

Attributes:

Name Type Description
binomialoption ndarray

The calculated option prices (depends on the selected output type)

Methods:

Name Description
plot_tree

Plots the binomial tree based on the selected output type

Functions

plot_tree
plot_tree()

Plot the binomial tree with option values

BlackScholesOptionPricing

A class implementing the Black-Scholes option pricing model.

This class calculates option prices and Greeks (sensitivity measures) using the Black-Scholes formula for European-style options.

Parameters:

Name Type Description Default
inputs OptionInputs

Object containing the following option parameters: - spot : float Current price of the underlying asset - strike : float Strike price of the option - rate : float Risk-free interest rate (as a decimal) - ttm : float Time to maturity in years - volatility : float Implied volatility of the underlying asset (as a decimal) - callprice : float, optional Market price of call option (used for implied volatility calculation) - putprice : float, optional Market price of put option (used for implied volatility calculation)

required

Attributes:

Name Type Description
call_price float

Price of the call option

put_price float

Price of the put option

call_delta float

Delta of the call option (sensitivity to underlying price)

put_delta float

Delta of the put option (sensitivity to underlying price)

gamma float

Gamma of the option (second derivative with respect to underlying price)

vega float

Vega of the option (sensitivity to volatility changes)

call_theta float

Theta of the call option (sensitivity to time decay)

put_theta float

Theta of the put option (sensitivity to time decay)

call_rho float

Rho of the call option (sensitivity to interest rate changes)

put_rho float

Rho of the put option (sensitivity to interest rate changes)

impvol float

Implied volatility calculated from market price (if provided)

Notes

All Greeks are calculated using the analytical formulas from the Black-Scholes model. Theta is expressed in price change per day, and vega and rho are expressed per 1% change in their respective parameters.

MonteCarloOptionPricing

Monte Carlo Pricing for options.

Parameters:

Name Type Description Default
inputs OptionInputs

The inputs for the option pricing model.

required
nsims int

Number of simulations (default is Field(..., gt=0)).

Field(..., gt=0, description='Number of simulations')
timestep int

Time step (default is Field(..., gt=0)).

Field(..., gt=0, description='Time step')
option_type OptionType

Type of option (Call or Put).

Field(..., description='Call or Put')
exercise_style ExerciseStyle

Style of exercise (American, European, or Barrier).

Field(..., description='American or European or Barrier')
barrier_level float

Barrier level for barrier options (default is None).

Field(None, gt=0, description='Barrier level (for barrier options)')
barrier_rebate int

Barrier rebate for barrier options (default is None).

Field(None, gt=0, description='Barrier rebate (for barrier options)')
barrier_type BarrierType

Type of barrier option (default is None).

Field(None, description='Type of barrier option')

Attributes:

Name Type Description
option_price float

The calculated option price.

Raises:

Type Description
ValueError

If an unsupported exercise style or barrier type is provided.

OptionInputs

Bases: BaseModel

Option inputs parameters

Returns:

Type Description
OptionInputs

Option inputs parameters

Raises:

Type Description
ValueError

If any of the input parameters are invalid