Vol Surface¶
quantflow.options.surface.VolSurface
pydantic-model
¶
Bases: ForwardPricer[S]
Represents a volatility surface, which captures the implied volatility of an option for different strikes and maturities.
Key Concepts:
- Implied Volatility: The market's expectation of future volatility, derived from the price of an option using a pricing model (e.g., Black-Scholes).
- Strike Price: The price at which the underlying asset can be bought (call option) or sold (put option) at the option's expiry.
- Time to Maturity: The time remaining until the option's expiration date.
- Volatility Smile/Skew: The often-observed phenomenon where implied volatility varies across different strike prices for the same maturity. Typically, it forms a "smile" or "skew" shape.
This class provides a structure for storing and manipulating volatility surface data. It can be used for various tasks, such as:
- Option pricing and risk management: Using the surface to determine the appropriate volatility input for pricing models.
- Volatility arbitrage: Identifying mispricings in options by comparing market prices to model prices derived from the surface.
- Market analysis: Understanding market sentiment and expectations of future volatility.
Fields:
-
asset(str) -
spot(SpotPrice[S] | None) -
quote_curve(AnyYieldCurve) -
asset_curve(AnyYieldCurve) -
tick_size_forwards(DecimalNumber | None) -
tick_size_options(DecimalNumber | None) -
day_counter(DayCounter) -
maturities(tuple[VolCrossSection[S], ...])
maturities
pydantic-field
¶
Sorted tuple of VolCrossSection, each containing the forward price and option prices for that maturity
tick_size_forwards
pydantic-field
¶
Tick size for rounding forward and spot prices - optional
tick_size_options
pydantic-field
¶
Tick size for rounding option prices - optional
day_counter
pydantic-field
¶
Day counter for time to maturity calculations, by default it uses Act/Act
ref_date
property
¶
Reference date for the volatility surface, taken as the earliest maturity or the provided ref_date if it's earlier
securities
¶
securities(*, select=ALL, index=None, converged=False)
Iterator over securities in the volatility surface
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
converged
|
Include the spot, forwards and options with implied volatility converged only if True, otherwise include all securities regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
inputs
¶
inputs(*, select=ALL, index=None, converged=False)
Convert the volatility surface to a VolSurfaceInputs instance
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
converged
|
Include spot, forwards and options with implied volatility converged only if True, otherwise include all securities regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
term_structure
¶
Return the term structure of the volatility surface as a DataFrame
Source code in quantflow/options/surface.py
trim
¶
Create a new volatility surface with the last num_maturities maturities
option_prices
¶
option_prices(
*,
select=BEST,
index=None,
initial_vol=INITIAL_VOL,
converged=False
)
Iterator over selected option prices in the surface
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
converged
|
Include options with implied volatility converged only if True, otherwise include all options regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
option_list
¶
option_list(*, select=BEST, index=None, converged=False)
List of selected option prices in the surface
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
converged
|
Include options with implied volatility converged only if True, otherwise include all options regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
bs
¶
bs(*, select=BEST, index=None, initial_vol=INITIAL_VOL)
Calculate Black-Scholes implied volatility for options in the surface. For some option prices, the implied volatility calculation may not converge, in this case the implied volatility is not calculated correctly and the option is marked as not converged.
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
Source code in quantflow/options/surface.py
calc_bs_prices
¶
calc_bs_prices(*, select=BEST, index=None)
calculate Black-Scholes prices for all options in the surface
It uses options with a converged implied volatility calculation only, otherwise the price calculation won't be correct.
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
Source code in quantflow/options/surface.py
options_df
¶
options_df(
*,
select=BEST,
index=None,
initial_vol=INITIAL_VOL,
converged=False
)
Time frame of Black-Scholes call input data
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
converged
|
Whether the calculation has converged
TYPE:
|
Source code in quantflow/options/surface.py
as_array
¶
as_array(
*,
select=BEST,
index=None,
initial_vol=INITIAL_VOL,
converged=False
)
Organize option prices in a numpy arrays for Black volatility and price calculation
It returns an OptionArrays instance, which contains the option prices and their corresponding log strikes, time to maturity and implied volatility in numpy arrays for efficient calculations.
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
converged
|
If True, include only options for which the calculation has converged
TYPE:
|
Source code in quantflow/options/surface.py
reset_convergence
¶
Reset the convergence flag for all options in the surface
disable_outliers
¶
Disable outlier options across all maturities in the surface.
Calls VolCrossSection.disable_outliers on each maturity with the same parameters.
| PARAMETER | DESCRIPTION |
|---|---|
bid_ask_spread_fraction
|
Maximum allowed bid/ask spread as a fraction of the mid implied volatility. A value of 0.2 means options with a spread greater than 20% of the mid vol are disabled.
TYPE:
|
svi_residual_fraction
|
Maximum allowed SVI residual as a fraction of the mid implied volatility. A value of 0.2 means options whose mid vol deviates from the SVI fit by more than 20% of their mid vol are disabled.
TYPE:
|
repeat
|
Number of times to repeat the outlier removal process
TYPE:
|
Source code in quantflow/options/surface.py
plot
¶
plot(*, index=None, select=BEST, **kwargs)
Plot the volatility surface
| PARAMETER | DESCRIPTION |
|---|---|
index
|
Index of the cross section to use, if None use all
TYPE:
|
select
|
Option selection method
TYPE:
|
Source code in quantflow/options/surface.py
plot3d
¶
plot3d(
*,
select=BEST,
index=None,
dragmode="turntable",
**kwargs
)
Plot the volatility surface
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
index
|
Index of the cross section to use, if None use all
TYPE:
|
dragmode
|
Drag interaction mode for the 3D scene
TYPE:
|
Source code in quantflow/options/surface.py
spot_price
¶
forward
¶
Calculate the implied forward for a given maturity
Source code in quantflow/options/surface.py
clip_forward
¶
Clip the forward price to the nearest tick size if tick_size_forwards is set
Source code in quantflow/options/surface.py
quantflow.options.surface.VolCrossSection
pydantic-model
¶
Bases: BaseModel, Generic[S]
Represents a cross section of a volatility surface at a specific maturity.
Fields:
forward
pydantic-field
¶
Forward price of the underlying asset at the time of the cross section
day_counter
pydantic-field
¶
Day counter for time to maturity calculations - by default it uses Act/Act
ttm
¶
info_dict
¶
Return a dictionary with information about the cross section
Source code in quantflow/options/surface.py
option_prices
¶
option_prices(
ref_date,
forward,
*,
select=BEST,
initial_vol=INITIAL_VOL,
converged=False
)
Iterator over option prices in the cross section
| PARAMETER | DESCRIPTION |
|---|---|
ref_date
|
Reference date for time to maturity calculation
TYPE:
|
forward
|
Forward price of the underlying asset
TYPE:
|
select
|
Option selection method
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
converged
|
Whether the calculation has converged
TYPE:
|
Source code in quantflow/options/surface.py
securities
¶
securities(*, select=ALL, converged=False)
Iterator over all securities in the cross section
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
converged
|
Include the forward and options with implied volatility converged only if
TYPE:
|
Source code in quantflow/options/surface.py
option_securities
¶
option_securities(*, select=ALL, converged=False)
Iterator over all option securities in the cross section
| PARAMETER | DESCRIPTION |
|---|---|
select
|
Option selection method
TYPE:
|
converged
|
Include the forward and options with implied volatility converged only if
TYPE:
|
Source code in quantflow/options/surface.py
disable_outliers
¶
Disable outlier options in the cross section by marking them as not converged.
Two passes are applied:
First pass: options where the bid/ask spread in implied vol space exceeds
bid_ask_spread_fraction of the mid implied vol are disabled.
For example, a value of 0.2 disables options where the spread is more
than 20% of the mid vol. Options with a zero mid vol are also disabled.
Second pass: an SVI smile is fitted to the
surviving options (mid implied vol vs log-strike). Options whose
residual from the SVI fit exceeds svi_residual_fraction of their mid
implied vol are disabled. This is repeated up to repeat times,
refitting after each removal. The loop stops early if no outliers are
found or fewer than 5 options remain.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Time to maturity in years, used for SVI fitting
TYPE:
|
bid_ask_spread_fraction
|
Maximum allowed bid/ask spread as a fraction of the mid implied volatility. A value of 0.2 means options with a spread greater than 20% of the mid vol are disabled.
TYPE:
|
svi_residual_fraction
|
Maximum allowed SVI residual as a fraction of the mid implied volatility. A value of 0.2 means options whose mid vol deviates from the SVI fit by more than 20% of their mid vol are disabled.
TYPE:
|
repeat
|
Number of times to repeat the outlier removal process
TYPE:
|
Source code in quantflow/options/surface.py
quantflow.options.surface.GenericVolSurfaceLoader
pydantic-model
¶
Bases: ForwardPricer[S]
Helper class to build a volatility surface from a list of securities
Use this class to add spot, forward and option securities with their prices
and then call the surface method to build a VolSurface instance
from the provided data.
Fields:
-
asset(str) -
spot(SpotPrice[S] | None) -
quote_curve(AnyYieldCurve) -
asset_curve(AnyYieldCurve) -
tick_size_forwards(DecimalNumber | None) -
tick_size_options(DecimalNumber | None) -
day_counter(DayCounter) -
maturities(dict[datetime, VolCrossSectionLoader[S]]) -
exclude_open_interest(DecimalNumber | None) -
exclude_volume(DecimalNumber | None)
maturities
pydantic-field
¶
Dictionary of maturities and their corresponding cross section loaders
exclude_open_interest
pydantic-field
¶
Exclude options with open interest at or below this value
exclude_volume
pydantic-field
¶
Exclude options with volume at or below this value
tick_size_forwards
pydantic-field
¶
Tick size for rounding forward and spot prices - optional
tick_size_options
pydantic-field
¶
Tick size for rounding option prices - optional
day_counter
pydantic-field
¶
Day counter for time to maturity calculations, by default it uses Act/Act
ref_date
property
¶
Reference date for the volatility surface, taken as the earliest maturity or the provided ref_date if it's earlier
get_or_create_maturity
¶
Get or create a VolCrossSectionLoader for a given maturity
| PARAMETER | DESCRIPTION |
|---|---|
maturity
|
Maturity date for the options
TYPE:
|
Source code in quantflow/options/surface.py
add_spot
¶
Add a spot to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the spot price
TYPE:
|
bid
|
Bid price for the spot
TYPE:
|
ask
|
Ask price for the spot
TYPE:
|
open_interest
|
Open interest for the spot
TYPE:
|
volume
|
Volume for the spot
TYPE:
|
Source code in quantflow/options/surface.py
add_forward
¶
Add a forward to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the forward price
TYPE:
|
maturity
|
Maturity date for the forward price
TYPE:
|
bid
|
Bid price for the forward
TYPE:
|
ask
|
Ask price for the forward
TYPE:
|
open_interest
|
Open interest for the forward
TYPE:
|
volume
|
Volume for the forward
TYPE:
|
Source code in quantflow/options/surface.py
add_option
¶
add_option(
security,
strike,
maturity,
option_type,
bid,
ask,
open_interest=ZERO,
volume=ZERO,
inverse=True,
)
Add an option to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the option
TYPE:
|
strike
|
Strike price for the option
TYPE:
|
maturity
|
Maturity date for the option
TYPE:
|
option_type
|
Type of the option (call or put)
TYPE:
|
bid
|
Bid price for the option
TYPE:
|
ask
|
Ask price for the option
TYPE:
|
open_interest
|
Open interest for the option
TYPE:
|
volume
|
Volume for the option
TYPE:
|
inverse
|
Whether the option is an inverse option
TYPE:
|
Source code in quantflow/options/surface.py
surface
¶
Build a volatility surface from the provided data
Source code in quantflow/options/surface.py
calibrate_spot
¶
Calibrate the spot price from short-dated put-call parity.
For short-dated options where discount factors are approximately 1, put-call parity simplifies to C - P = S - K, so S = C - P + K. This method computes the median implied spot across all put-call pairs with time to maturity at or below max_ttm and updates the spot price.
Returns the implied spot, or None if no maturities fall within max_ttm.
| PARAMETER | DESCRIPTION |
|---|---|
max_ttm
|
Maximum time to maturity (in years) for maturities used to imply the spot price. Default is 1/52 (one week).
TYPE:
|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
calibrate_curves
¶
Calibrate the quote and/or asset discount curves from option prices.
Three modes are supported:
Both curves: pass a curve type or instance for both curves. A single OLS regression per maturity identifies \(D_q\) and \(D_a\) simultaneously.
Asset only: pass a curve type or instance for asset_curve, leave
quote_curve as None.
The existing quote_curve is treated as known and \(D_a\) is solved analytically.
Quote only: pass a curve type or instance for quote_curve, leave
asset_curve as None.
The existing asset_curve is treated as known and \(D_q\) is solved analytically.
| PARAMETER | DESCRIPTION |
|---|---|
quote_curve
|
YieldCurve type or instance to fit the quote currency discount curve \(D_q\) from option prices. When None the current quote_curve is unchanged.
TYPE:
|
asset_curve
|
YieldCurve type or instance to fit the asset discount curve \(D_a\) from option prices. When None the current asset_curve is unchanged.
TYPE:
|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
collect_put_call_parities
¶
Collect per-maturity continuously compounded rates from put-call parity.
| PARAMETER | DESCRIPTION |
|---|---|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
implied_forward_term_structure
¶
Return per-maturity implied forwards from put-call parity.
For each maturity, fits asset and quote discount factors from the most
liquid put-call pairs and returns the implied forward spot * Da / Dq.
Returns a list of (maturity, ttm, forward) tuples, one per maturity
for which a valid fit is available.
| PARAMETER | DESCRIPTION |
|---|---|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
spot_price
¶
forward
¶
Calculate the implied forward for a given maturity
Source code in quantflow/options/surface.py
clip_forward
¶
Clip the forward price to the nearest tick size if tick_size_forwards is set
Source code in quantflow/options/surface.py
quantflow.options.surface.VolSurfaceLoader
pydantic-model
¶
Bases: GenericVolSurfaceLoader[DefaultVolSecurity]
Helper class to build a volatility surface from a list of securities
Use this class to add spot, forward and option securities with their prices
and then call the surface method to build a VolSurface instance
from the provided data.
Fields:
-
asset(str) -
spot(SpotPrice[S] | None) -
quote_curve(AnyYieldCurve) -
asset_curve(AnyYieldCurve) -
tick_size_forwards(DecimalNumber | None) -
tick_size_options(DecimalNumber | None) -
day_counter(DayCounter) -
maturities(dict[datetime, VolCrossSectionLoader[S]]) -
exclude_open_interest(DecimalNumber | None) -
exclude_volume(DecimalNumber | None)
tick_size_forwards
pydantic-field
¶
Tick size for rounding forward and spot prices - optional
tick_size_options
pydantic-field
¶
Tick size for rounding option prices - optional
day_counter
pydantic-field
¶
Day counter for time to maturity calculations, by default it uses Act/Act
ref_date
property
¶
Reference date for the volatility surface, taken as the earliest maturity or the provided ref_date if it's earlier
maturities
pydantic-field
¶
Dictionary of maturities and their corresponding cross section loaders
exclude_open_interest
pydantic-field
¶
Exclude options with open interest at or below this value
exclude_volume
pydantic-field
¶
Exclude options with volume at or below this value
add
¶
Add a volatility security input to the loader
| PARAMETER | DESCRIPTION |
|---|---|
input
|
Volatility surface input data
TYPE:
|
Source code in quantflow/options/surface.py
spot_price
¶
forward
¶
Calculate the implied forward for a given maturity
Source code in quantflow/options/surface.py
clip_forward
¶
Clip the forward price to the nearest tick size if tick_size_forwards is set
Source code in quantflow/options/surface.py
get_or_create_maturity
¶
Get or create a VolCrossSectionLoader for a given maturity
| PARAMETER | DESCRIPTION |
|---|---|
maturity
|
Maturity date for the options
TYPE:
|
Source code in quantflow/options/surface.py
add_spot
¶
Add a spot to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the spot price
TYPE:
|
bid
|
Bid price for the spot
TYPE:
|
ask
|
Ask price for the spot
TYPE:
|
open_interest
|
Open interest for the spot
TYPE:
|
volume
|
Volume for the spot
TYPE:
|
Source code in quantflow/options/surface.py
add_forward
¶
Add a forward to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the forward price
TYPE:
|
maturity
|
Maturity date for the forward price
TYPE:
|
bid
|
Bid price for the forward
TYPE:
|
ask
|
Ask price for the forward
TYPE:
|
open_interest
|
Open interest for the forward
TYPE:
|
volume
|
Volume for the forward
TYPE:
|
Source code in quantflow/options/surface.py
add_option
¶
add_option(
security,
strike,
maturity,
option_type,
bid,
ask,
open_interest=ZERO,
volume=ZERO,
inverse=True,
)
Add an option to the volatility surface loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the option
TYPE:
|
strike
|
Strike price for the option
TYPE:
|
maturity
|
Maturity date for the option
TYPE:
|
option_type
|
Type of the option (call or put)
TYPE:
|
bid
|
Bid price for the option
TYPE:
|
ask
|
Ask price for the option
TYPE:
|
open_interest
|
Open interest for the option
TYPE:
|
volume
|
Volume for the option
TYPE:
|
inverse
|
Whether the option is an inverse option
TYPE:
|
Source code in quantflow/options/surface.py
surface
¶
Build a volatility surface from the provided data
Source code in quantflow/options/surface.py
calibrate_spot
¶
Calibrate the spot price from short-dated put-call parity.
For short-dated options where discount factors are approximately 1, put-call parity simplifies to C - P = S - K, so S = C - P + K. This method computes the median implied spot across all put-call pairs with time to maturity at or below max_ttm and updates the spot price.
Returns the implied spot, or None if no maturities fall within max_ttm.
| PARAMETER | DESCRIPTION |
|---|---|
max_ttm
|
Maximum time to maturity (in years) for maturities used to imply the spot price. Default is 1/52 (one week).
TYPE:
|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
calibrate_curves
¶
Calibrate the quote and/or asset discount curves from option prices.
Three modes are supported:
Both curves: pass a curve type or instance for both curves. A single OLS regression per maturity identifies \(D_q\) and \(D_a\) simultaneously.
Asset only: pass a curve type or instance for asset_curve, leave
quote_curve as None.
The existing quote_curve is treated as known and \(D_a\) is solved analytically.
Quote only: pass a curve type or instance for quote_curve, leave
asset_curve as None.
The existing asset_curve is treated as known and \(D_q\) is solved analytically.
| PARAMETER | DESCRIPTION |
|---|---|
quote_curve
|
YieldCurve type or instance to fit the quote currency discount curve \(D_q\) from option prices. When None the current quote_curve is unchanged.
TYPE:
|
asset_curve
|
YieldCurve type or instance to fit the asset discount curve \(D_a\) from option prices. When None the current asset_curve is unchanged.
TYPE:
|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
collect_put_call_parities
¶
Collect per-maturity continuously compounded rates from put-call parity.
| PARAMETER | DESCRIPTION |
|---|---|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
implied_forward_term_structure
¶
Return per-maturity implied forwards from put-call parity.
For each maturity, fits asset and quote discount factors from the most
liquid put-call pairs and returns the implied forward spot * Da / Dq.
Returns a list of (maturity, ttm, forward) tuples, one per maturity
for which a valid fit is available.
| PARAMETER | DESCRIPTION |
|---|---|
max_pairs
|
Maximum number of put-call pairs to use per maturity
TYPE:
|
Source code in quantflow/options/surface.py
quantflow.options.surface.VolCrossSectionLoader
pydantic-model
¶
Bases: BaseModel, Generic[S]
Fields:
-
maturity(datetime) -
forward(FwdPrice[S] | None) -
strikes(dict[Decimal, Strike[S]]) -
day_counter(DayCounter)
forward
pydantic-field
¶
Forward price of the underlying asset at the time of the cross section
day_counter
pydantic-field
¶
Day counter for time to maturity calculations - by default it uses Act/Act
add_option
¶
add_option(
security,
strike,
option_type,
bid,
ask,
open_interest=ZERO,
volume=ZERO,
inverse=True,
)
Add an option to the cross section loader
| PARAMETER | DESCRIPTION |
|---|---|
security
|
Security for the option
TYPE:
|
strike
|
Strike price for the option
TYPE:
|
option_type
|
Type of the option (call or put)
TYPE:
|
bid
|
Bid price for the option
TYPE:
|
ask
|
Ask price for the option
TYPE:
|
open_interest
|
Open interest for the option
TYPE:
|
volume
|
Volume for the option
TYPE:
|
inverse
|
Whether the option is an inverse option
TYPE:
|
Source code in quantflow/options/surface.py
put_call_parities
¶
Return a list of the most liquid PutCallParity from a cross-section loader.
Liquidity is determined by the bid-ask spread of the put-call parity price.
| PARAMETER | DESCRIPTION |
|---|---|
spot
|
Spot price of the underlying asset
TYPE:
|
ref_date
|
Reference date for time to maturity calculation
TYPE:
|
max_pairs
|
Maximum number of put-call pairs to consider
TYPE:
|
Source code in quantflow/options/surface.py
Info Models¶
quantflow.options.surface.OptionInfo
pydantic-model
¶
Bases: BaseModel
Structured representation of an option price with all computed fields
Fields:
-
strike(DecimalNumber) -
forward(DecimalNumber) -
maturity(datetime) -
log_strike(DecimalNumber) -
moneyness(DecimalNumber) -
ttm(DecimalNumber) -
iv(DecimalNumber) -
price(DecimalNumber) -
price_bp(DecimalNumber) -
price_quote(DecimalNumber) -
option_type(OptionType) -
side(Side) -
open_interest(DecimalNumber) -
volume(DecimalNumber)
Bid/Ask Prices¶
quantflow.options.surface.SpotPrice
pydantic-model
¶
Bases: SecurityPrice[S]
Represents the spot bid/ask price of an underlying asset
Fields:
quantflow.options.surface.FwdPrice
pydantic-model
¶
Bases: SecurityPrice[S]
Represents the forward bid/ask price of an underlying asset at a specific maturity
Fields:
-
bid(DecimalNumber) -
ask(DecimalNumber) -
open_interest(DecimalNumber) -
volume(DecimalNumber) -
security(S) -
maturity(datetime)
quantflow.options.surface.Strike
pydantic-model
¶
Bases: BaseModel, Generic[S]
Option prices for a single strike
Fields:
-
strike(DecimalNumber) -
call(OptionPrices[S] | None) -
put(OptionPrices[S] | None)
put_call_parity
¶
Return a [PutCallParity][quantflow.rates.calibrator.PutCallParity] for this strike, or None if either the call or the put are not available.
Source code in quantflow/options/surface.py
options_iter
¶
options_iter(forward, ttm, *, select=ALL)
Iterator over option prices for the strike
It uses the select parameter to determine which options to include in
the iteration. The forward price is used to determine the moneyness of
the options when the best or otm selection method is used, in which
case only the Out of the Money options are included in the iteration.
| PARAMETER | DESCRIPTION |
|---|---|
forward
|
Forward price of the underlying asset
TYPE:
|
ttm
|
Time to maturity in years
TYPE:
|
select
|
Option selection method
TYPE:
|
Source code in quantflow/options/surface.py
securities
¶
securities(
forward, ttm=0.0, *, select=ALL, converged=False
)
Iterator over option prices for the strike
| PARAMETER | DESCRIPTION |
|---|---|
forward
|
Forward price of the underlying asset
TYPE:
|
ttm
|
Time to maturity in years
TYPE:
|
select
|
Option selection method
TYPE:
|
converged
|
Include options with implied volatility converged only if True, otherwise include all options regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
option_prices
¶
option_prices(
forward,
ttm,
*,
select=BEST,
initial_vol=INITIAL_VOL,
converged=False
)
| PARAMETER | DESCRIPTION |
|---|---|
forward
|
Forward price of the underlying asset
TYPE:
|
ttm
|
Time to maturity in years
TYPE:
|
select
|
Option selection method
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
converged
|
Include options with implied volatility converged only if True, otherwise include all options regardless of convergence
TYPE:
|
Source code in quantflow/options/surface.py
quantflow.options.surface.OptionArrays
¶
Bases: NamedTuple
Represents the option data in array form for efficient calculations via vectorized operations
log_strike
instance-attribute
¶
The log strike of the options, calculated as log(strike/forward)
quantflow.options.surface.OptionPrice
pydantic-model
¶
Bases: BaseModel
Represents the price of an option quoted in the market along with its metadata and implied volatility information.
Fields:
-
price(DecimalNumber) -
meta(OptionMetadata) -
forward(DecimalNumber) -
ttm(float) -
iv(float) -
side(Side) -
converged(bool)
price_in_forward_space
property
¶
Price of the option as a percentage of the forward price
price_bp
property
¶
Price of the option in basis points, calculated as price in forward space multiplied by 10000
price_intrinsic
property
¶
Intrinsic price of the option in forward space, which is the price if the option had zero time value
price_time
property
¶
Time value of the option in forward space, which is the price minus its intrinsic value
call_price
property
¶
call price in forward space
use put-call parity to calculate the call price if a put
put_price
property
¶
put price in forward space
use put-call parity to calculate the put price if a call
is_in_the_money
¶
calculate_price
¶
Source code in quantflow/options/surface.py
info_dict
¶
Source code in quantflow/options/surface.py
info
¶
Return a structured OptionInfo representation of this option price
Source code in quantflow/options/surface.py
quantflow.options.surface.OptionPrices
pydantic-model
¶
Bases: BaseModel, Generic[S]
Represents the market for a single option contract (identified by its strike, maturity and option type), holding the bid and ask sides as separate OptionPrice objects.
Fields:
-
security(S) -
meta(OptionMetadata) -
bid(OptionPrice) -
ask(OptionPrice) -
open_interest(DecimalNumber) -
volume(DecimalNumber)
converged
property
¶
Check if the implied volatility calculation has converged for both bid and ask
price
¶
Convert the option prices to a PriceVolume object
iv_bid_ask_spread
¶
iv_mid
¶
is_in_the_money
¶
disable
¶
prices
¶
Iterator over bid/ask option prices
| PARAMETER | DESCRIPTION |
|---|---|
forward
|
Forward price of the underlying asset
TYPE:
|
ttm
|
Time to maturity in years
TYPE:
|
initial_vol
|
Initial volatility for the root finding algorithm
TYPE:
|
Source code in quantflow/options/surface.py
inputs
¶
Convert the option prices to an OptionInput instance
Source code in quantflow/options/surface.py
quantflow.options.surface.OptionSelection
¶
Bases: Enum
Option selection method
This enum is used to select which one between calls and puts are used for calculating implied volatility and other operations
BEST
class-attribute
instance-attribute
¶
Select the OTM option but blend call and put implied volatilities near the money. The blending weight transitions linearly from 50/50 at moneyness 0 to pure OTM at the moneyness threshold.
OTM
class-attribute
instance-attribute
¶
Select Out of the Money options only, where their intrinsic value is zero
ALL
class-attribute
instance-attribute
¶
Select all options regardless of their moneyness
quantflow.options.surface.surface_from_inputs
¶
Helper function to build a volatility surface from a VolSurfaceInputs instance
| PARAMETER | DESCRIPTION |
|---|---|
inputs
|
Volatility surface input data
TYPE:
|
Source code in quantflow/options/surface.py
Vol Surface Inputs¶
quantflow.options.inputs.OptionMetadata
pydantic-model
¶
Bases: BaseModel
Represents the metadata of an option, including its strike, type, maturity, and other relevant information.
Fields:
-
strike(DecimalNumber) -
option_type(OptionType) -
maturity(datetime) -
inverse(bool)
quantflow.options.inputs.VolSurfaceInputs
pydantic-model
¶
Bases: BaseModel
Class representing the inputs for a volatility surface
Fields:
-
asset(str) -
asset_curve(AnyYieldCurve) -
quote_curve(AnyYieldCurve) -
inputs(list[ForwardInput | SpotInput | OptionInput])
quantflow.options.inputs.VolSurfaceInput
module-attribute
¶
VolSurfaceInput = SpotInput | ForwardInput | OptionInput
quantflow.options.inputs.SpotInput
pydantic-model
¶
Bases: PriceVolume
Input data for a spot contract in the volatility surface
Fields:
-
bid(DecimalNumber) -
ask(DecimalNumber) -
open_interest(DecimalNumber) -
volume(DecimalNumber) -
security_type(VolSecurityType)
bp_spread
property
¶
Bid-ask spread in basis points, calculated as spread divided by mid price and multiplied by 10000
quantflow.options.inputs.ForwardInput
pydantic-model
¶
Bases: PriceVolume
Input data for a forward contract in the volatility surface
Fields:
-
bid(DecimalNumber) -
ask(DecimalNumber) -
open_interest(DecimalNumber) -
volume(DecimalNumber) -
maturity(datetime) -
security_type(VolSecurityType)
bp_spread
property
¶
Bid-ask spread in basis points, calculated as spread divided by mid price and multiplied by 10000
quantflow.options.inputs.OptionInput
pydantic-model
¶
Bases: PriceVolume, OptionMetadata
Input data for an option in the volatility surface
Fields:
-
strike(DecimalNumber) -
option_type(OptionType) -
maturity(datetime) -
inverse(bool) -
bid(DecimalNumber) -
ask(DecimalNumber) -
open_interest(DecimalNumber) -
volume(DecimalNumber) -
security_type(VolSecurityType) -
iv_bid(DecimalNumber | None) -
iv_ask(DecimalNumber | None)
iv_bid
pydantic-field
¶
Implied volatility based on the bid price as decimal number (e.g. 0.2 for 20%)
iv_ask
pydantic-field
¶
Implied volatility based on the ask price as decimal number (e.g. 0.2 for 20%)
inverse
pydantic-field
¶
Whether the option is an inverse option (i.e. quoted in terms of the underlying) or not (i.e. quoted in terms of the quote currency)
bp_spread
property
¶
Bid-ask spread in basis points, calculated as spread divided by mid price and multiplied by 10000
is_in_the_money
¶
Check if the option is in the money given the forward price