API Documentation¶
Option Pricing Formulas¶
Intrinsic Option Payoffs¶
-
putcall.formulas.option_payoffs.
option_payoff
(forward_value, strike_value, is_call_bool)[source]¶ simple option payoff
@param strike_value: strike price @param forward_value: forward price of underlying @param is_call_bool: call -> True, put -> False @return: option payoff value
Black Scholes¶
-
putcall.formulas.plain_vanilla_options.blackscholes.
black_scholes
(spot_value, strike_value, vol_value, time_value, is_call_bool, rate=0.0)[source]¶ Black Scholes option pricing formula on log-normal spot value
Parameters: - forward_value (real) – forward price of underlying at exercise date
- strike_value (real) – strike of the option
- vol_value (non-negative real) – volatility of underlying price
- time_value (non-negative real) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
- rate (real) – risk free rate
Returns: option price
Return type: real
Returns:
-
putcall.formulas.plain_vanilla_options.blackscholes.
black_scholes_digital
(spot_value, strike_value, vol_value, time_value, is_call_bool, rate=0.0)[source]¶ Black Scholes digital option pricing formula on log-normal spot value
Parameters: - spot_value (real) – forward price of underlying at exercise date
- strike_value (real) – strike of the option
- vol_value (non-negative real) – volatility of underlying price
- time_value (non-negative real) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
- rate (real) – risk free rate
Returns: option price
Return type: real
Returns:
-
putcall.formulas.plain_vanilla_options.blackscholes.
forward_black_scholes
(forward_value, strike_value, vol_value, time_value, is_call_bool, rate=0.0)[source]¶ Black Scholes option pricing formula on log-normal forward value
Parameters: - strike_value (real) – strike of the option
- forward_value (real) – forward price of underlying at exercise date
- vol_value (non-negative real) – volatility of underlying price
- time_value (non-negative real) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
- rate (real) – risk free rate
Returns: option price
Return type: real
Returns:
-
putcall.formulas.plain_vanilla_options.blackscholes.
forward_black_scholes_digital
(forward_value, strike_value, vol_value, time_value, is_call_bool, rate=0.0)[source]¶ Black Scholes digital option pricing formula on log-normal forward value
Parameters: - strike_value (real) – strike of the option
- forward_value (real) – forward price of underlying at exercise date
- vol_value (non-negative real) – volatility of underlying price
- time_value (non-negative real) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
- rate (real) – risk free rate
Returns: option price
Return type: real
Returns:
Interest Rate Options¶
-
putcall.formulas.interest_rate_options.bachelier.
bachelier
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier formula (Black formula for normal underlying distribution).
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ delta sensitivity for Bachelier formula.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ gamma sensitivity for Bachelier formula.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ vega sensitivity for Bachelier formula.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_digital
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier formula for digital option (Black formula for normal underlying distribution).
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_digital_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ delta sensitivity for Bachelier formula for digital option.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_digital_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ gamma sensitivity for Bachelier formula for digital option.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_digital_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ vega sensitivity for Bachelier formula for digital option.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_straddle
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier formula for straddle option on log-normal underlying distribution.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_straddle_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier delta sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_straddle_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier gamma sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.bachelier.
bachelier_straddle_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Bachelier vega sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Standard Black-76 formula for log-normal underlying distribution.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 delta sensitivity.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 gamma sensitivity.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 vega sensitivity.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_digital
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Standard Black-76 formula for digital option on log-normal underlying distribution.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_digital_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 delta sensitivity for digital payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_digital_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 gamma sensitivity for digital payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_digital_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 vega sensitivity for digital payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_straddle
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Standard Black-76 formula for straddle option on log-normal underlying distribution.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_straddle_delta
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 delta sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_straddle_gamma
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 gamma sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.black76.
black_straddle_vega
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool)[source]¶ Black-76 vega sensitivity for straddle payoff.
Parameters: - forward_value (float) – forward price of underlying at exercise date
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of underlying price
- time_value (float) – year fraction until exercise date
- is_call_bool (boolean) – call -> True, put -> False
Returns: float
-
putcall.formulas.interest_rate_options.hullwhite.
hw_discount_bond_option
(forward_value, strike_value, implied_vol_value, time_value, is_call_bool, time_to_bond_value, mean_reversion_value, maturity_discount_value)[source]¶ discount bond option pricing formula in the Hull White framework
Parameters: - forward_value (float) – forward price of underlying (discount bond) at bond maturity (D(t,Tau,r))
- strike_value (float) – strike price
- implied_vol_value (float) – volatility of the spot rate
- time_value (float) – year fraction until exercise date (option maturity date)
- bool is_call_bool (float) – call -> True, put -> False
- time_to_bond_value (float) – year fraction between option’s maturity and bond’s maturity
- maturity_discount_value (float) – forward price of underlying (discount bond) at option maturity date (D(t,T,r))
- mean_reversion_value (float) – mean reversion / alpha
Returns: float
discount bond option pricing formula in the Hull White framework as described in A. Pelsser, Efficient Methods for Valuing Interest Rate Derivatives, 2000, pp. 50
-
putcall.formulas.interest_rate_options.hullwhite.
hw_cap_floor_let
(forward_rate_value, strike_value, implied_vol_value, time_value, is_call_bool, year_fraction_value, mean_reversion_value, discount_value)[source]¶ pricing formula of a caplet/floorlet under the Hull White framework
Parameters: - forward_rate_value (float) – forward rate (LIBOR,EURIBOR…)
- discount_value (float) – zero bond price between pricing time and start of the caplet (D(t,T,r))
- mean_reversion_value (float) – mean reversion in the Hull White model
- strike_value (float) – strike of the option
- implied_vol_value (float) – volatility of the spot rate
- year_fraction_value (float) – year fraction between start and maturity = tenor of the rate
- time_value (float) – year_fraction between pricing date (e.g. start of the Cap) and start of the caplet Y(t,T)
- is_call_bool (bool) – call(caplet) -> True, put(floorlet) -> False
Returns: float
pricing formula of a caplet/floorlet under the Hull White framework as described in A. Pelsser, Efficient Methods for Valuing Interest Rate Derivatives, 2000, pp. 57
-
putcall.formulas.interest_rate_options.sabr.
sabr_black_vol
(strike_value, forward_value, alpha_value, beta_value, nu_value, rho_value, time_value)[source]¶ Parameters: - strike_value –
- forward_value –
- alpha_value –
- beta_value –
- nu_value –
- rho_value –
- time_value –
Returns: Return type:
Option Calibration¶
-
putcall.calibration.hw_calibration.
binary_vol_hw_calibration_cap_floor
(price_dict, mean_reversion_start=0.0, mean_reversion_stop=0.01, mean_reversion_step=0.0001, volatility_start=0.0001, volatility_stop=0.01, volatility_step=0.0001)[source]¶ Binary search based calibration of the Hull White model using caps and floors
Parameters: - price_dict (dictionary) – contains prices, time_values, year_fractions,forward values
- mean_reversion_start (real) – mean reversion error mean_reversion_start
- mean_reversion_stop (real) – mean reversion error mean_reversion_stop
- mean_reversion_step (real) – step for the mean reversion optimisation loop
- volatility_start (real) – volatility error mean_reversion_start
- volatility_stop (real) – volatility error mean_reversion_stop
- volatility_step (real) – step for the volatility optimisation loop
Returns: optimal mean reversion, optimal volatility, vector of errors
Return type: list(list())
- remarks:
- price_dict is a dictionary s.t.: price_dict[‘time_value’] contains the year fractions between start date and maturity price_dict[‘year_fraction’] contains the year fractions between start and maturity price_dict[‘forward_values’] contains the rate forward values price_dict[‘price’] price of the lets price_dict[‘strike’] list of strikes price_dict[‘bool’] list of booleans (True if call False if put) threshold_vol mean_reversion_stop on the vola mean_reversion_stop is the mean_reversion_stop on the mean revertion
-
putcall.calibration.hw_calibration.
binary_mr_hw_calibration_cap_floor
(price_dict, mean_reversion_start=0.0, mean_reversion_stop=0.01, mean_reversion_step=0.0001, volatility_start=0.0001, volatility_stop=0.01, volatility_step=0.0001)[source]¶ Binary search based calibration of the Hull White model using caps and floors
Parameters: - price_dict (dictionary) – contains prices, time_values, year_fractions,forward values
- mean_reversion_start (real) – mean reversion error mean_reversion_start
- mean_reversion_stop (real) – mean reversion error mean_reversion_stop
- mean_reversion_step (real) – step for the mean reversion optimisation loop
- volatility_start (real) – volatility error mean_reversion_start
- volatility_stop (real) – volatility error mean_reversion_stop
- volatility_step (real) – step for the volatility optimisation loop
Returns: optimal mean reversion, optimal volatility, vector of errors
Return type: list(list())
- remarks:
- price_dict is a dictionary s.t.: price_dict[‘time_value’] contains the year fractions between start date and maturity price_dict[‘year_fraction’] contains the year fractions between start and maturity price_dict[‘forward_values’] contains the rate forward values price_dict[‘price’] price of the lets price_dict[‘strike’] list of strikes price_dict[‘bool’] list of booleans (True if call False if put) threshold_vol mean_reversion_stop on the vola mean_reversion_stop is the mean_reversion_stop on the mean revertion
-
putcall.calibration.hw_calibration.
brute_hw_calibration_cap_floor
(price_dict, mean_reversion_start=0.0, mean_reversion_stop=0.01, mean_reversion_step=0.0001, volatility_start=0.0001, volatility_stop=0.01, volatility_step=0.0001, error_func=None)[source]¶ Brute force based calibration of the Hull White model using caps and floors
Parameters: - price_dict (dictionary) – contains prices as a price_dict
- mean_reversion_start (float) – mean reversion starting point
- mean_reversion_stop (float) – mean reversion threshold
- mean_reversion_step (float) – mean reversion step
- volatility_start (float) – volatility starting point
- volatility_stop (float) – volatility reversion threshold
- volatility_step (float) – volatility reversion step
- error_func (function) – function to aggregate errors
Returns: optimal mean reversion, optimal volatility, corresponding error
calculates the error for different choices of mean rev and volatility which will make it possible for the user to pick the values for which the error is minimal
- remarks:
- price_dict is a dictionary s.t.: price_dict[‘time_value’] contains the year fractions between start date and maturity price_dict[‘year_fraction’] contains the year fractions between start and maturity price_dict[‘forward_values’] contains the rate forward values price_dict[‘price’] price of the lets price_dict[‘strike’] list of strikes price_dict[‘bool’] list of booleans (True if call False if put) threshold_vol threshold on the vola threshold is the threshold on the mean reversion
-
class
putcall.calibration.implied_volatility.
OptionValueByVolatility
(option_value_function, forward, strike, time, option_type, discount_factor=1.0)[source]¶ Bases:
object
Option Valuators¶
-
class
putcall.optionvaluator.
OptionType
[source]¶ Bases:
object
-
CALL
= 0¶
-
PUT
= 1¶
-
DIGITAL_CALL
= 2¶
-
DIGITAL_PUT
= 3¶
-
STRADDLE
= 4¶
-