Volatility Surface#
A class to compute and hold market and model-implied volatility surfaces.
This class takes a DataFrame of option market data and provides methods to calculate the Black-Scholes implied volatility (IV) for each option, either from its market price or from a price generated by a financial model.
Source code in src/quantfin/calibration/iv_surface.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
__init__(option_data: pd.DataFrame)
#
Initializes the VolatilitySurface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option_data
|
DataFrame
|
A DataFrame containing market prices of options. Must include 'strike', 'maturity', 'marketPrice', 'optionType', and 'expiry' columns. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the required columns are missing from |
Source code in src/quantfin/calibration/iv_surface.py
calculate_market_iv(stock: Stock, rate: Rate) -> VolatilitySurface
#
Calculates the market implied volatility surface from market prices.
This method inverts the Black-Scholes formula for each option's market
price to find the corresponding implied volatility. The results are
stored in the self.surface
DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
Returns:
Type | Description |
---|---|
VolatilitySurface
|
The same instance of the class, allowing for method chaining. |
Source code in src/quantfin/calibration/iv_surface.py
calculate_model_iv(stock: Stock, rate: Rate, model: BaseModel, technique: BaseTechnique) -> VolatilitySurface
#
Calculates a model's implied volatility surface.
This method first prices every option in the dataset using the provided model and technique. It then inverts the Black-Scholes formula for each of these model prices to generate the model-implied volatility surface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
model
|
BaseModel
|
The financial model to generate prices from. |
required |
technique
|
BaseTechnique
|
The pricing technique to use with the model. |
required |
Returns:
Type | Description |
---|---|
VolatilitySurface
|
The same instance of the class, allowing for method chaining. |