Equity

Curves

class rivapy.marketdata.EquityForwardCurve(spot: float, funding_curve: DiscountCurve, borrow_curve: DiscountCurve, div_table)[source]

Bases: object

Equity Forward Curve

Parameters:
plot(days: int = 10, days_end: int = 3650, **kwargs)[source]

Plots the forward curve using matplotlibs plot function.

Parameters:
  • days (int, optional) – The number of days between two plotted rates/discount factors. Defaults to 10.

  • days_end (int. optional) – Number of days when plotting will end. Defaults to 10*365 (10yr)

  • **kwargs – optional arguments that will be directly passed to the matplotlib plto function

value(refdate, expiry)[source]

Volatility Surface

class rivapy.marketdata.VolatilitySurface(id: str, refdate: datetime, forward_curve, daycounter, vol_param)[source]

Bases: object

Volatility surface

Parameters:
calc_implied_vol(expiry: datetime, strike: float, refdate: datetime = None, forward_curve=None) float[source]

Calculate implied volatility

Parameters:
  • refdate (datetime) – Valuation date.

  • expiry (datetime) – Expiration date.

  • strike (float) – Strike price.

Raises:

Exception – [description]

Returns:

Implied volatility.

Return type:

float

static load(filename: str)[source]
static set_stickyness(vol_stickyness: VolatilityStickyness)[source]

Volatility Parametrizations

class rivapy.marketdata.VolatilityParametrizationFlat(vol: float)[source]

Bases: object

Flat volatility parametrization

Parameters:

vol (float) – Constant volatility.

class rivapy.marketdata.VolatilityParametrizationTerm(expiries: List[float], fwd_atm_vols: List[float])[source]

Bases: object

Term volatility parametrization

Parameters:
  • expiries (List[float]) – List of expiries (sorted from nearest to farest).

  • fwd_atm_vols (List[float]) – List of at-the-money volatilities.

class rivapy.marketdata.VolatilityParametrizationSVI(expiries: List[float], svi_params: List[Tuple])[source]

Bases: _VolatilityParametrizationExpiry

Raw SVI parametrization (definition 3.1 in https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2033323)

\[w(k) = a + b(\rho (k-m) + \sqrt{(k-m)^2+\sigma^2 })\]
Parameters:
  • expiries (List[float]) – List of expiries (sorted from nearest to farest).

  • svi_params (List[Tuple]) – List of SVI parameters (one Tuple for each expiry). Tuple in the order (a, b, rho, m, sigma).

class rivapy.marketdata.VolatilityParametrizationSSVI(expiries: List[float], fwd_atm_vols: List[float], rho: float, eta: float, gamma: float)[source]

Bases: object

SSVI volatility parametrization https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2033323

Parameters:
  • expiries (List[float]) – List of expiries (sorted from nearest to farest).

  • fwd_atm_vols (List[float]) – List of at-the-money volatilities.

  • rho (float) – Responsible for the skewness of the volatility surface.

  • eta (float) – Responsible for the curvature.

  • gamma (float) – Responsible for the “rate of decay”.

calc_implied_vol(ttm, strike)[source]

Calculate implied volatility for given expiry and strike

Parameters:
  • ttm ([float]) – Expiry.

  • strike ([float]) – Strike.

Returns:

Implied volatility.

Return type:

[float]

get_eta()[source]
get_fwd_atm_vols()[source]
get_gamma()[source]
get_rho()[source]
class rivapy.marketdata.VolatilityParametrizationSABR(expiries: List[float], sabr_params: List[Tuple])[source]

Bases: _VolatilityParametrizationExpiry

SABR parametrization https://bsic.it/sabr-stochastic-volatility-model-volatility-smile/

The SABR model assumes that the forward rate and the instantaneous volatility are driven by two correlated Brownian motions:

\[df_t = \alpha_t f_t^\beta dW_t^1\]
\[d\alpha_t = \nu\alpha_t dW_t^2\]
\[E\bigl[dW_t^1 dW_T^2\bigr] = \rho dt\]

The expression that the implied volatility must satisfy is

\[\sigma_B(K,f) = \frac{\alpha\biggl\{1+\biggl[\frac {(1-\beta)^2}{24}\frac {\alpha^2}{(fK)^{1-\beta}}+\frac {1}{4}\frac {\rho\beta\nu\alpha}{(FK)^{(1-\beta)/2}}+\frac {2-3\rho^2}{24}\nu^2\biggr ]T\biggr \}}{(fK)^{(1-\beta)/2}\biggl[1+\frac {(1-\beta)^2}{24}{ln}^2\frac {f}{K}+\frac {(1-\beta)^4}{1920}{ln}^4\frac {f}{K}\biggr]} \frac {z}{\chi(z)}\]
\[z = \frac {\nu }{\alpha }(fK)^{(1-\beta )/2} ln \frac {f}{K}\]
\[\chi(z) = ln \bigl[ \frac {\sqrt{1-2 \rho z+z^2}+z-\rho }{1- \rho} \bigr]\]

When \(f = K\) (for ATM options), the above formula for implied volatility simplifies to:

\[\sigma_{ATM} = \sigma_B(f,f)=\frac{\alpha\biggl\{1+\biggl[\frac{(1-\beta)^2}{24}\frac{\alpha^2}{f^{2-2\beta}}+\frac{1}{4}\frac{\rho\beta\nu\alpha}{f^{1-\beta}}\frac{2-3\rho^2}{24}\nu^2\biggr]T\biggr\}}{f^{1-\beta}}\]

where

> \(\alpha\) is the instantaneous vol;

> \(\nu\) is the vol of vol;

> \(\rho\) is the correlation between the Brownian motions driving the forward rate and the instantaneous vol;

> \(\beta\) is the CEV component for forward rate (determines shape of forward rates, leverage effect and backbond of ATM vol).

Parameters:
  • expiries (List[float]) – List of expiries (sorted from nearest to farest).

  • sabr_params (List[Tuple]) – List of SABR parameters (one Tuple for each expiry). Tuple in the order (alpha, nu, beta, rho).

class rivapy.marketdata.VolatilityGridParametrization(expiries: array, strikes: ndarray, vols: ndarray)[source]

Bases: object

Grid parametrization This parametrization stores a set of strike-vol grids for a given list of expiries and computes a volatility by - search for the neighboring expiries - apply a splien interpolation in each expiry to get the respective volatility - apply a linear interpolation (in total variance)

Parameters:
  • expiries (np.array) – An array of the expiries.

  • strikes (np.ndarray)

  • vols (np.ndarray) – Two dimensional array of volatilities where each row i contains the values for expiry i

calc_implied_vol(ttm: float, strike: float)[source]

Calculate implied volatility for given expiry and strike

Parameters:
  • ttm ([float]) – Expiry.

  • strike ([float]) – Strike.

Returns:

Implied volatility.

Return type:

[float]