Template Class OptionCalculator
Defined in File option_calculator.hpp
Class Documentation
-
template<VolatilityType v_type = SPOT_VOLATILITY, TreeType t_type = CRR>
class OptionCalculator A class to calculate options using different pricing models and parameters.
This class supports various option types, volatility models, and tree methods to calculate option prices. It can handle European and American option styles, as well as dividend schedules and interest rates.
- Template Parameters:
v_type – The type of volatility to use for the option pricing (default: SPOT_VOLATILITY).
t_type – The type of tree model to use for the option pricing (default: CRR).
Public Functions
-
OptionCalculator()
Default constructor for the OptionCalculator.
-
OptionCalculator(const DividendTable ÷nd_table, double underlying_price, double time_to_expiration, double annualized_continuous_compounding_borrow_rate, double annualized_continuous_compounding_interest_rate, double strike, double annualized_volatility, OptionType type, OptionStyle style, double precision)
Constructor for the OptionCalculator that takes various option pricing parameters.
- Parameters:
dividend_table – The dividend table for the underlying asset.
underlying_price – The current price of the underlying asset.
time_to_expiration – Time to expiration in years.
annualized_continuous_compounding_borrow_rate – The annualized borrowing rate using continuous compounding.
annualized_continuous_compounding_interest_rate – The annualized interest rate using continuous compounding.
strike – The strike price of the option.
annualized_volatility – The annualized volatility of the underlying asset.
type – The option type (CALL or PUT).
style – The option style (EUROPEAN or AMERICAN).
precision – The precision for the pricing.
Constructor for the OptionCalculator that takes additional parameters for time and schedules.
- Parameters:
style – The option style (EUROPEAN or AMERICAN).
expiration – The expiration date of the option.
strike – The strike price of the option.
type – The option type (CALL or PUT).
valuation_time – The current valuation time.
underlying_price – The price of the underlying asset.
annualized_continuous_compounding_interest_rate – The annualized interest rate using continuous compounding.
annualized_continuous_compounding_borrow_rate – The annualized borrowing rate using continuous compounding.
annualized_volatility – The annualized volatility of the underlying asset.
variance_tenor_calculator – A shared pointer to the variance tenor calculator.
dividend_schedule – An optional shared pointer to the dividend schedule.
underlying_settlement_lag – The settlement lag for the underlying asset.
option_settlement_lag – The settlement lag for the option.
exercise_settlement_lag – The settlement lag for the exercise.
trading_calendar – A shared pointer to the trading calendar.
variance_schedule – An optional shared pointer to the variance schedule.
-
OptionCalculator(const OptionCalculator &other)
Copy constructor for the OptionCalculator.
- Parameters:
other – The OptionCalculator to copy.
-
OptionCalculator &operator=(const OptionCalculator &other)
Assignment operator for the OptionCalculator.
- Parameters:
other – The OptionCalculator to assign from.
- Returns:
A reference to this OptionCalculator.
-
void set_interest_rate(double annualized_continuous_compounding_interest_rate)
Sets the annualized continuous compounding interest rate.
- Parameters:
annualized_continuous_compounding_interest_rate – The new interest rate.
-
void set_borrow_rate(double annualized_continuous_compounding_borrow_rate)
Sets the annualized continuous compounding borrowing rate.
- Parameters:
annualized_continuous_compounding_borrow_rate – The new borrowing rate.
-
void set_strike(double strike)
Sets the strike price of the option.
- Parameters:
strike – The new strike price.
-
void set_underlying_settlement_lag(int underlying_settlement_lag)
Sets the underlying settlement lag.
- Parameters:
underlying_settlement_lag – The new underlying settlement lag.
-
void set_option_settlement_lag(int option_settlement_lag)
Sets the option settlement lag.
- Parameters:
option_settlement_lag – The new option settlement lag.
-
void set_exercise_settlement_lag(int exercise_settlement_lag)
Sets the exercise settlement lag.
- Parameters:
exercise_settlement_lag – The new exercise settlement lag.
-
void set_underlying_price(double underlying_price)
Sets the underlying asset price.
- Parameters:
underlying_price – The new underlying asset price.
-
void set_valuation_time(const boost::posix_time::ptime &valuation_time)
Sets the valuation time.
- Parameters:
valuation_time – The new valuation time.
-
void set_expiration(const boost::posix_time::ptime &expiration)
Sets the expiration date of the option.
- Parameters:
expiration – The new expiration date.
Sets the dividend schedule.
- Parameters:
dividend_schedule – The new dividend schedule.
-
void dividend_schedule_updated()
Notifies the object that the dividend schedule has been updated.
This should be called whenever the dividend table is changed.
Sets the tenor calculator used to compute time intervals for variance calculations.
- Parameters:
tenor_calculator – Shared pointer to a TenorCalculator instance.
-
void variance_tenor_calculator_updated()
Notifies the object that the variance tenor calculator has been updated.
Sets the trading calendar used to determine business days and holidays.
- Parameters:
trading_calendar – Shared pointer to a TradingCalendar instance.
-
void trading_calendar_updated()
Notifies the object that the trading calendar has been updated.
Sets the schedule of estimated variances to be used in computations.
-
void variance_schedule_updated()
Notifies the object that the variance schedule has been updated.
-
void set_precision(double precision)
Sets the numerical precision used in internal calculations.
- Parameters:
precision – The new precision value. Recommend 1 for standard precision.
-
void set_volatility(double annualized_volatility)
Sets the annualized volatility used in pricing and risk calculations.
- Parameters:
annualized_volatility – The annualized volatility.
-
void set_option_type(OptionType type)
Sets the type of the option (e.g., Call or Put).
- Parameters:
type – The option type.
-
void set_option_style(OptionStyle style)
Sets the style of the option (e.g., European, American).
- Parameters:
style – The option style.
-
void overwrite(const DividendTable ÷nd_table, double carry_tenor, double hedge_tenor, double variance_tenor)
Overwrites core market assumptions for pricing calculations. Instead of calculating time to dividends, carry time to expiration, hedge time to expiration and variance time to expiration, use these values.
- Parameters:
dividend_table – A new DividendTable to use.
carry_tenor – The tenor (in years) for carry cost estimation.
hedge_tenor – The tenor for delta hedging.
variance_tenor – The tenor used for implied volatility input.
-
double intrinsic() const
Returns the intrinsic value of the option.
For a call, this is max(S - K, 0); for a put, max(K - S, 0), where S is the underlying asset price.
-
double forward()
Computes and returns the forward price of the underlying asset.
- Returns:
The forward price.
-
double forward_phi()
Returns the sensitivity (derivative) of the forward price with respect to borrow rate change.
- Returns:
The value of phi (∂F/∂borrow).
-
double forward_rho()
Returns the sensitivity of the forward price with respect to interest rates.
- Returns:
The value of rho (∂F/∂interest).
-
double implied_borrow(double forward_price, double borrow_rate_tolerance, double guess = 0, double relative_forward_tolerance = 1e-4)
Computes the implied borrow rate from a given forward price.
- Parameters:
forward_price – Observed forward price.
borrow_rate_tolerance – Tolerance for convergence.
guess – Initial guess for implied borrow rate (optional).
relative_forward_tolerance – Relative tolerance on forward (optional).
- Returns:
The implied borrow rate.
-
double implied_interest(double forward_price, double interest_rate_tolerance, double guess = 0, double relative_forward_tolerance = 1e-4)
Computes the implied interest rate from a given forward price.
- Parameters:
forward_price – Observed forward price.
interest_rate_tolerance – Tolerance for convergence.
guess – Initial guess for implied interest rate (optional).
relative_forward_tolerance – Relative tolerance on forward (optional).
- Returns:
The implied interest rate.
Returns the premium (price) of the option.
This includes both intrinsic value and time value.
- Returns:
The option premium.
-
double delta()
Returns the delta of the option.
Delta measures the sensitivity of the option price to changes in the underlying asset price.
- Returns:
The delta.
-
double gamma()
Returns the gamma of the option.
Gamma measures the sensitivity of delta with respect to the underlying asset price.
- Returns:
The gamma.
-
double rho()
Returns the rho of the option.
Rho measures the sensitivity of the option price to changes in the interest rate.
- Returns:
The rho.
-
double theta()
Returns the theta of the option.
Theta measures the sensitivity of the option price to the passage of time.
- Returns:
The theta.
-
double vega()
Returns the vega of the option.
Vega measures the sensitivity of the option price to changes in implied volatility.
- Returns:
The vega.
-
double phi()
Returns the phi of the option.
Phi measures the sensitivity of the option price to dividend yield or borrow cost.
- Returns:
The phi.
-
double delta_decay()
Returns the decay in delta due to passage of time.
This can be interpreted as ∂delta/∂t.
- Returns:
The delta decay.
-
double vanna()
Returns the vanna of the option.
Vanna measures the sensitivity of delta to changes in volatility, or the sensitivity of vega to changes in the underlying.
- Returns:
The vanna.
-
double volga()
Returns the volga (or vomma) of the option.
Volga measures the sensitivity of vega to changes in volatility.
- Returns:
The volga.
-
double time_value()
Returns the time value of the option.
Time value is the portion of the premium exceeding intrinsic value.
- Returns:
The time value.
-
double forward_intrinsic()
Returns the intrinsic value using the forward price.
This is computed as max(F - K, 0) for calls, or max(K - F, 0) for puts, where F is the forward price.
- Returns:
The forward intrinsic value.
-
double fugit()
Returns the fugit (expected life) of the option.
Fugit is a weighted average time to exercise, often used for American options.
- Returns:
The fugit.
-
double implied_volatility(double price, double volatility_tolerance = 1e-4, double guess = 0.25, double relative_price_tolerance = 1e-4)
Computes the implied volatility that matches a given option price.
Uses numerical methods to solve for the volatility that, when input into a pricing model, produces the specified option price.
- Parameters:
price – The observed option price to match.
volatility_tolerance – The tolerance for volatility convergence (default = 1e-4).
guess – The initial guess for the implied volatility (default = 0.25).
relative_price_tolerance – The tolerance for price convergence relative to input price (default = 1e-4).
- Returns:
The implied volatility.
Returns the premium of an European option using a grid-based numerical method.
- Returns:
The computed option premium.
Returns the premium of an American option using a grid-based numerical method.
- Returns:
The computed American option premium.
-
inline bool ctrl_smooth() const
-
inline void set_ctrl_smooth(bool ctrl_smooth)
-
inline double variance_tenor() const
Gets the variance tenor.
- Returns:
The variance tenor (in years).
-
inline double hedge_tenor() const
Gets the hedge tenor.
- Returns:
The hedge tenor (in years).
-
inline double carry_tenor() const
Gets the carry tenor.
- Returns:
The carry tenor (in years).
-
inline double get_borrow_rate() const
Gets the annualized borrow rate used in pricing.
- Returns:
The borrow rate.
-
inline double get_interest_rate() const
Gets the annualized risk-free interest rate used in pricing.
- Returns:
The interest rate.
-
inline double get_underlying_price() const
Gets the current price of the underlying asset.
- Returns:
The underlying asset price.
-
inline double get_volatility() const
Gets the annualized volatility.
- Returns:
The volatility.
-
inline int get_steps() const
-
inline double get_p() const
Computes the premium of a European option.
- Returns:
The European option premium.
-
double european_delta()
Computes the delta of a European option.
- Returns:
The European delta.
-
double european_gamma()
Computes the gamma of a European option.
- Returns:
The European gamma.
-
double european_rho()
Computes the rho (sensitivity to interest rates) of a European option.
- Returns:
The European rho.
-
double european_theta()
Computes the theta (time decay) of a European option.
- Returns:
The European theta.
-
double european_vega()
Computes the vega (sensitivity to volatility) of a European option.
- Returns:
The European vega.
-
double european_phi()
Computes the phi (sensitivity to borrow rate) of a European option.
- Returns:
The European phi.
-
double european_delta_decay()
Computes the rate of change of delta over time for a European option.
- Returns:
The European delta decay.
-
double european_vanna()
Computes the vanna (sensitivity of delta to volatility) of a European option.
- Returns:
The European vanna.
-
double european_volga()
Computes the volga (sensitivity of vega to volatility) of a European option.
- Returns:
The European volga.
-
double european_dual_delta()
Computes the dual delta (sensitivity to strike) of a European option.
- Returns:
The European dual delta.
-
double european_dual_gamma()
Computes the dual gamma (second-order sensitivity to strike) of a European option.
- Returns:
The European dual gamma.
Computes the early exercise premium of an American option.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise premium.
-
double early_exercise_delta()
Computes the delta of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise delta.
-
double early_exercise_gamma()
Computes the gamma of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise gamma.
-
double early_exercise_rho()
Computes the rho of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise rho.
-
double early_exercise_theta()
Computes the theta of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise theta.
-
double early_exercise_vega()
Computes the vega of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise vega.
-
double early_exercise_phi()
Computes the phi of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise phi.
-
double early_exercise_delta_decay()
Computes the delta decay of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise delta decay.
-
double early_exercise_vanna()
Computes the vanna of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise vanna.
-
double early_exercise_volga()
Computes the volga of the early exercise premium.
Note
This function is not const yet. Consider making it const.
- Returns:
The early exercise volga.
-
void _reset_susp()
Public Static Functions
-
static double standard_price(OptionType type, double strike, double log_strike, double annualized_volatility_times_sqrt_tenor)
Computes the standard (Black-Scholes) price of an option.
- Parameters:
type – The type of option (Call or Put).
strike – The strike price.
log_strike – The logarithm of the strike divided by forward price.
annualized_volatility_times_sqrt_tenor – Annualized volatility multiplied by square root of tenor.
- Returns:
The Black-Scholes price.
-
static double delta_to_log_relative_strike(double neg_put_delta, double sigma_sqrt_t)
Converts a negative put delta into a log-relative strike.
Assumes Black-Scholes framework and uses an approximation based on the inverse normal CDF.
- Parameters:
neg_put_delta – The negative of the put delta (should be in (0, 0.5) for puts).
sigma_sqrt_t – The product of volatility and sqrt(time to maturity).
- Returns:
The corresponding log-relative strike.
-
static double delta_to_stdev(double neg_put_delta, double sigma_sqrt_t)
Converts a negative put delta into a standardized deviation from forward.
Equivalent to the number of standard deviations below the forward price.
- Parameters:
neg_put_delta – The negative of the put delta.
sigma_sqrt_t – The product of volatility and sqrt(time to maturity).
- Returns:
The number of standard deviations.