Implied Volatility

PortfolioOptimisers.ImpliedVolatilityAlgorithm — Type
abstract type ImpliedVolatilityAlgorithm <: AbstractAlgorithm

Abstract supertype for all implied volatility algorithms.

A subtype predicts the realised volatility of each asset for the period that follows the sample.

Interfaces

To add an implied volatility algorithm, subtype ImpliedVolatilityAlgorithm and add this method:

Required method name

  • predict_realised_vols(alg::ImpliedVolatilityAlgorithm, iv::MatNum, X::MatNum, ivpa::Any): Returns the predicted realised volatility of each asset for the period that follows the sample.

Arguments

The implied volatilities are the second positional argument, and the returns are the third. The two matrices have the same size, so a call that swaps them raises no error and returns a wrong answer.

  • alg: The instance of the concrete subtype.
  • iv: Implied volatility matrix observations × assets. The caller divides it by $\sqrt{\mathrm{ppy}}$ before the call.
  • X: Asset returns matrix observations × assets.
  • ivpa: Implied volatility premium adjustment factor. It is nothing when the caller gives no factor, so an algorithm that needs a factor must raise an error on nothing.

Returns

  • rv_p::VecNum: The predicted realised volatility of each asset, in the units of X.

Examples

The example below defines a minimal algorithm that returns the last row of iv.

julia> struct MyImpliedVolatilityAlgorithm <: PortfolioOptimisers.ImpliedVolatilityAlgorithm endjulia> function PortfolioOptimisers.predict_realised_vols(::MyImpliedVolatilityAlgorithm,                                                          iv::PortfolioOptimisers.MatNum, ::Any,                                                          ::Any)           return vec(iv[end, :])       endjulia> cov(ImpliedVolatility(; alg = MyImpliedVolatilityAlgorithm(), ppy = 1),           [0.1 0.2; 0.3 0.1; 0.2 0.4]; iv = [0.5 0.6; 0.4 0.7; 0.3 0.8])2×2 Matrix{Float64}:  0.09       -0.0785584 -0.0785584   0.64

Related

source
PortfolioOptimisers.ImpliedVolatilityRegression — Type
struct ImpliedVolatilityRegression{__T_ve, __T_ws, __T_re} <: ImpliedVolatilityAlgorithm

Predicts realised volatility by a log-linear regression on implied volatility and on the realised volatility of the window before.

ImpliedVolatilityRegression splits the sample into windows of ws rows that do not overlap. For each asset, it regresses the realised volatility of a window on the implied volatility at the end of the window before, and on the realised volatility of the window before. It then predicts the realised volatility of the next window from the last window. The regression is Equation 5 of [75], and both series enter it as natural logarithms. This type selects a method of predict_realised_vols, and the docstring of that method states the model, the steps and the number of windows that the fit needs.

Fields

  • ve: Variance estimator.
  • ws: Number of rows in each window. The number of windows is div(size(X, 1), ws), and the regression needs more than four windows.
  • re: Regression model target.

Constructors

ImpliedVolatilityRegression(;    ve::AbstractVarianceEstimator = SimpleVariance(),    ws::Number = 20,    re::AbstractRegressionTarget = LinearModel()) -> ImpliedVolatilityRegression

Keywords correspond to the struct's fields.

Validation

  • ws > 1. A window of one row has no dispersion. Its corrected standard deviation is NaN, and its uncorrected one is zero, which has no logarithm.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • ve: Recursively updated through factory.

Examples

julia> ImpliedVolatilityRegression()ImpliedVolatilityRegression  ve ┼ SimpleVariance     │          me ┼ SimpleExpectedReturns     │             │   w ┴ nothing     │           w ┼ nothing     │   corrected ┴ Bool: true  ws ┼ Int64: 20  re ┼ LinearModel     │   kwargs ┴ @NamedTuple{}: NamedTuple()

Related

References

  • [75] B. J. Christensen and N. R. Prabhala. The relation between implied and realized volatility. Journal of Financial Economics 50, 125–150 (1998). Section 3.1, Equation 5.
source
PortfolioOptimisers.ImpliedVolatilityPremium — Type
struct ImpliedVolatilityPremium <: ImpliedVolatilityAlgorithm

Divides the last implied volatility of each asset by a volatility risk premium adjustment factor.

The method follows [76]. The library has no copy of that work, so no check compares the division with it.

The adjustment factor is not a field of this type. The caller gives it as the ivpa keyword of the cov and cor methods of ImpliedVolatility, as a scalar or as one value per asset. The factor is mandatory, and ivpa = nothing raises an ArgumentError. Each entry must be finite and strictly positive, or the method raises a DomainError. A factor that is not positive makes a negative volatility, and StatsBase.cor2cov! hides its sign. This type selects a method of predict_realised_vols, and the docstring of that method states the closed form and the checks.

Constructors

ImpliedVolatilityPremium() -> ImpliedVolatilityPremium

Examples

julia> ImpliedVolatilityPremium()ImpliedVolatilityPremium()

Related

References

  • [76] T. Egbers and L. Swinkels. Can implied volatility predict returns on the currency carry trade?. Journal of Banking & Finance 59, 14–26 (2015). Pages 14 to 26. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
source
PortfolioOptimisers.ImpliedVolatility — Type
struct ImpliedVolatility{__T_ce, __T_alg, __T_ppy, __T_cache} <: AbstractCovarianceEstimator

Covariance estimator that scales a correlation matrix by the realised volatilities that it predicts from implied volatilities.

ImpliedVolatility estimates the correlation matrix of the returns with a base estimator. It predicts the realised volatility of each asset from the implied volatilities, and scales the correlation matrix by those volatilities. Two algorithms make the prediction. ImpliedVolatilityRegression fits a regression of realised volatility on implied volatility. ImpliedVolatilityPremium divides the implied volatility by a factor that the caller gives.

The estimator applies no matrix processing to its result. Wrap it in PortfolioOptimisersCovariance to repair, denoise or detone the matrix, as for every other covariance estimator.

Fields

  • ce: Covariance estimator.
  • alg: Implied volatility algorithm that predicts the realised volatility of each asset.
  • ppy: Periods per year of the returns. It converts the annual implied volatility to the frequency of the returns. The cov and cor methods divide the implied volatilities by sqrt(ppy) before the algorithm reads them.
  • cache: Optional partial-fit state. It is nothing until partial_fit! writes one. When the caller gives no data matrix, the batch verb of the estimator reads it. Each propagation channel does one thing with it. factory keeps it unchanged, because a factory call resolves the configuration, not the sample. port_opt_view copies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone. obs_weights_view removes it, because a state has no slice on the observation axis. Only a type with an observation-weights field has that channel. A type with no such field falls through to the identity method, so it keeps its state. A family whose state has no exact asset slice removes it on both axes and names the reason.

Constructors

ImpliedVolatility(;    ce::StatsBase.CovarianceEstimator = Covariance(),    alg::ImpliedVolatilityAlgorithm = ImpliedVolatilityRegression(),    ppy::Number,    cache::Option{<:AbstractPartialFitState} = nothing) -> ImpliedVolatility

Keywords correspond to the struct's fields. ppy has no default. The implied volatility is annual, and ppy converts it to the period of the returns. No single value is correct for all data frequencies, so the caller must give it, for example ppy = 252 for daily returns.

Validation

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • ce: Recursively updated through factory.
  • alg: Recursively updated through factory.
  • cache: Carried unchanged through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> ImpliedVolatility(; ppy = 252)ImpliedVolatility   ce ┼ Covariance      │    me ┼ SimpleExpectedReturns      │       │   w ┴ nothing      │    ce ┼ GeneralCovariance      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)      │       │    w ┴ nothing      │   alg ┼ FullMoment()      │     w ┴ nothing  alg ┼ ImpliedVolatilityRegression      │   ve ┼ SimpleVariance      │      │          me ┼ SimpleExpectedReturns      │      │             │   w ┴ nothing      │      │           w ┼ nothing      │      │   corrected ┴ Bool: true      │   ws ┼ Int64: 20      │   re ┼ LinearModel      │      │   kwargs ┴ @NamedTuple{}: NamedTuple()  ppy ┴ Int64: 252

Related

source
PortfolioOptimisers.predict_realised_vols — Method
predict_realised_vols(::ImpliedVolatilityPremium, iv::MatNum, ::Any, ivpa::Nothing)

Raises an ArgumentError, because the premium algorithm needs an implied volatility premium adjustment factor.

The adjustment factor is not a field of ImpliedVolatilityPremium. A caller that selects that algorithm and gives no ivpa reaches this method.

Arguments

The implied volatilities are the second positional argument, and the returns are the third.

  • ::ImpliedVolatilityPremium: Implied volatility premium algorithm.
  • iv: Implied volatility matrix. The method does not read it.
  • ::Any: Asset returns matrix. The method does not read it.
  • ivpa::Nothing: nothing, because the caller gave no implied volatility premium adjustment factor.

Validation

  • ivpa is not nothing. This method is the branch that fails, and it raises an ArgumentError.

Related

source
PortfolioOptimisers.predict_realised_vols — Method
predict_realised_vols(::ImpliedVolatilityPremium, iv::MatNum, ::Any,
                      ivpa::Num_VecNum)

Predicts the realised volatility of each asset as its last implied volatility divided by the premium adjustment factor.

The method reads the last row of iv itself, not the last row of a window. So it needs no window size and no returns. The division follows [76]. The library has no copy of that work, so no check compares the formula with it.

Mathematical definition

\[\begin{align} \hat{\sigma}^{\mathrm{rv}}_i &= \frac{\sigma^{\mathrm{iv}}_{T,\,i}}{\mathrm{ivpa}_i}\,. \end{align}\]

Where:

  • $\hat{\sigma}^{\mathrm{rv}}_i$: Predicted realised volatility of asset $i$ for the period that follows the sample.
  • $\sigma^{\mathrm{iv}}_{T,\,i}$: Implied volatility of asset $i$ at the last observation.
  • $\mathrm{ivpa}_i$: Implied volatility premium adjustment factor for asset $i$. A scalar applies to every asset.
  • $T$: Number of observations.

Arguments

The implied volatilities are the second positional argument, and the returns are the third.

  • ::ImpliedVolatilityPremium: Implied volatility premium algorithm.
  • iv: Implied volatility matrix observations × assets. The method reads its last row.
  • ::Any: Asset returns matrix. The method does not read it.
  • ivpa: Implied volatility premium adjustment factor, a scalar or a vector.

Validation

  • Each entry of ivpa is finite and strictly positive. A factor that is not positive makes a negative volatility, and StatsBase.cor2cov! hides its sign. That function squares the factor on the diagonal. So a negative scalar gives the same matrix as its absolute value, and a negative entry of a vector flips the sign of each covariance of that asset only. Both results stay positive definite, so matrix_processing! finds no defect, and no later step sees it.
  • A vector ivpa has one entry for each asset. A vector of a different length raises a DimensionMismatch from the broadcast.

Returns

  • rv::AbstractArray: The predicted realised volatilities, which are the last row of iv divided by ivpa.

Examples

julia> PortfolioOptimisers.predict_realised_vols(ImpliedVolatilityPremium(),                                                 [0.1 0.2; 0.3 0.1; 0.2 0.4; 0.1 0.1;                                                  0.4 0.2; 0.2 0.3], nothing, 1.25)2-element Vector{Float64}: 0.16 0.24

Related

References

  • [76] T. Egbers and L. Swinkels. Can implied volatility predict returns on the currency carry trade?. Journal of Banking & Finance 59, 14–26 (2015). Pages 14 to 26. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
source
PortfolioOptimisers.predict_realised_vols — Method
predict_realised_vols(alg::ImpliedVolatilityRegression, iv::MatNum, X::MatNum, ::Any)

Predicts the realised volatility of each asset from a regression on its implied and realised volatilities.

For each asset, the function regresses the realised volatility of a window on the implied volatility and the realised volatility of the window before. It then predicts the next window from the last window. The windows are the blocks of realised_vol and the rows of implied_vol, so the two series read the same rows of the sample.

Mathematical definition

Write $C$ for the number of windows, $\mathrm{div}(T, w_s)$. For asset $i$, fit the log-linear model over the windows $c = 1, \ldots, C-1$:

\[\begin{align} \ln \sigma^{\mathrm{rv}}_{c+1,\,i} &= \beta_0 + \beta_1 \ln \sigma^{\mathrm{iv}}_{c,\,i} + \beta_2 \ln \sigma^{\mathrm{rv}}_{c,\,i} + \varepsilon_c\,. \end{align}\]

Then predict from the last window:

\[\begin{align} \hat{\sigma}^{\mathrm{rv}}_i &= \exp\!\left(\hat{\beta}_0 + \hat{\beta}_1 \ln \sigma^{\mathrm{iv}}_{C,\,i} + \hat{\beta}_2 \ln \sigma^{\mathrm{rv}}_{C,\,i}\right)\,. \end{align}\]

Where:

  • $\hat{\sigma}^{\mathrm{rv}}_i$: Predicted realised volatility of asset $i$ for the period that follows the sample.
  • $\sigma^{\mathrm{rv}}_{c,\,i}$: Realised volatility of asset $i$ over window $c$.
  • $\sigma^{\mathrm{iv}}_{c,\,i}$: Implied volatility of asset $i$ at the last row of window $c$.
  • $\beta_0, \beta_1, \beta_2$: Regression coefficients.
  • $\varepsilon_c$: Regression residual.
  • $T$: Number of observations.

The fit has $C - 1$ rows and three coefficients, and the method needs $C > 4$. At $C = 3$ the fit has fewer rows than coefficients, so the coefficients have no unique value. At $C = 4$ the fit passes through each row and has no residual, so the data cannot estimate $\varepsilon_c$. The fit has more rows than coefficients only when $C > 4$. The oracle accepts $C = 3$. The library refuses $C = 3$ and $C = 4$.

This is Equation 5 of [75]. It regresses the log realised volatility of period $t$ on the log implied volatility at the start of $t$ and on the log realised volatility of period $t - 1$. Section 2.2 of that work defines both as natural logarithms. It defines the realised volatility as the sample standard deviation of the returns of the period. Section 3.3 of that work forecasts one period ahead from the fitted equation, and it states no back-transformation. The exponential of the fitted logarithm is the choice of this library.

Algorithm

  1. Read T and N from size(X), and set chunk to div(T, alg.ws).
  2. Check that chunk exceeds four.
  3. Call realised_vol with alg.ve. The result is rv, the realised volatility of each window.
  4. Call implied_vol on iv with the same chunk, T and N. The result replaces iv, and holds the implied volatility at the last row of each window. The window count comes from X, so the function reads iv over the rows of the returns sample.
  5. Check that rv and iv have the same size, and that each of their entries is positive. Check that the returns of each asset are not all equal over each window. Set T2 to their number of rows, which is chunk.
  6. Replace rv and iv by their natural logarithms.
  7. Make ovec, the intercept column of ones, of length T2 - 1.
  8. For each asset i, make the design matrix X_t from ovec and the first T2 - 1 rows of iv and rv. Make the response y_t from the rows 2:T2 of rv, and the prediction row X_p from the row T2.
  9. Fit alg.re on X_t and y_t, with the first column named to it by factory(alg.re, InterceptColumn(1)), so that a penalised target such as ElasticNet does not shrink the intercept. Predict from X_p with the fit, and set rv_p[i] to the exponential of the prediction.
  10. Return rv_p.

Arguments

The implied volatilities are the second positional argument, and the returns are the third. The two matrices have the same size, so a call that swaps them raises no error and returns a wrong answer.

  • alg: Implied volatility regression algorithm. It gives the variance estimator, the window size and the regression target.
  • iv: Implied volatility matrix observations × assets.
  • X: Asset returns matrix observations × assets, from which the function computes the realised volatility. It also sets the number of windows, so iv must have as many rows as X.
  • ::Any: The place of ivpa. The method does not read it.

Validation

  • chunk > 4. The fit has chunk - 1 rows for three coefficients, so it has a residual only when chunk > 4.
  • size(rv) == size(iv), one realised volatility for each implied volatility.
  • Each implied volatility on the last row of a window is positive. Otherwise the function throws a DomainError, because the fit takes its logarithm. An entry on a row that ends no window is not read.
  • Each window has a positive realised volatility, and the returns of each asset are not all equal over it. Otherwise the function throws a DomainError. Constant returns over the ws rows of a window have a realised volatility of zero. In floating point, the round-off of their mean can leave a very small positive value instead, which depends on the order of the summation. So the function also compares the returns themselves.

Returns

  • rv_p::Vector{<:Number}: The predicted realised volatility of each asset for the next window.

Related

References

  • [75] B. J. Christensen and N. R. Prabhala. The relation between implied and realized volatility. Journal of Financial Economics 50, 125–150 (1998). Section 2.2, Equation 2, and Section 3.1, Equation 5.
source
Statistics.cov — Method
Statistics.cov(ce::ImpliedVolatility, X::MatNum; dims::Int = 1, mean = nothing,
               iv::Option{<:MatNum} = nothing, ivpa::Option{<:Num_VecNum} = nothing, kwargs...)

Returns the covariance matrix of X, scaled by the realised volatilities that ce.alg predicts from iv.

This method computes the correlation matrix of X with the base estimator ce.ce. It predicts the realised volatilities from iv with the algorithm ce.alg, and converts the correlation matrix to a covariance matrix with those volatilities. The method applies no matrix processing. A PortfolioOptimisersCovariance that wraps the estimator applies it.

Mathematical definition

\[\begin{align} \hat{\mathbf{\Sigma}} &= \mathrm{diag}(\hat{\boldsymbol{\sigma}}^{\mathrm{rv}}) \hat{\boldsymbol{\rho}} \,\mathrm{diag}(\hat{\boldsymbol{\sigma}}^{\mathrm{rv}})\,. \end{align}\]

Where:

  • $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
  • $\hat{\boldsymbol{\rho}} = \operatorname{cor}(\mathbf{X})$: Correlation matrix of the asset returns, from ce.ce.
  • $\hat{\boldsymbol{\sigma}}^{\mathrm{rv}}$: Predicted realised volatilities, from $\mathbf{iv} / \sqrt{\mathrm{ppy}}$. $\mathrm{ppy}$ is ce.ppy, the number of periods of X in one year.

So each diagonal entry of $\hat{\mathbf{\Sigma}}$ is the square of the predicted realised volatility of that asset, not one.

Algorithm

  1. Refuse a call with no iv through assert_implied_volatility. Orient X and iv to observations × assets with dims_oriented. It checks dims, and it transposes both matrices when dims is 2.
  2. Check that X and iv have the same size, so that row t of iv is the implied volatility of observation t of X. Refuse a gap in X with assert_finite_sample. Refuse a gap or a negative entry in iv with assert_nonempty_nonneg_finite_val.
  3. Call Statistics.cor(library_covariance_estimator(ce.ce), X; dims = 1, mean = mean, iv = iv, kwargs...). The result is sigma, the base correlation matrix. The call forwards the oriented iv, so a base estimator that reads its own implied volatility series receives it. A nested ImpliedVolatility is such an estimator. Each other estimator of the library takes iv into its own kwargs... and does not read it.
  4. Divide iv by sqrt(ce.ppy). This converts the annual implied volatility to the frequency of X.
  5. Call predict_realised_vols with ce.alg. The result replaces iv, and holds one predicted realised volatility for each asset. The implied volatilities are the second argument, and the returns are the third.
  6. Scale sigma in place with StatsBase.cor2cov!, which applies the closed form above.

Arguments

  • ce: Implied volatility covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.
  • mean: Optional precomputed mean. The method gives it to the base estimator.
  • iv: Annual implied volatility matrix, with the orientation and the size of X.
  • ivpa: Optional implied volatility premium adjustment factor. ImpliedVolatilityPremium needs it.
  • kwargs...: More keyword arguments for the base estimator.

Validation

  • iv is not nothing. Otherwise assert_implied_volatility throws an IsNothingError.
  • dims in (1, 2). dims_oriented checks it.
  • size(X) == size(iv), one implied volatility for each return.
  • Each entry of X is finite. Otherwise the method throws an IsNonFiniteError. The panel method removes an asset with a gap from the Coverage Universe, and this check keeps the plain call in agreement with it. Without the check, a plain call reads past the gap and gives a value for an asset that the panel method does not price.
  • Each entry of iv is finite and not negative. Otherwise the method throws a DomainError. The method refuses a gap in iv for the same reason as a gap in X. ImpliedVolatilityPremium turns a negative entry into a negative volatility, and StatsBase.cor2cov! hides its sign. ImpliedVolatilityRegression takes the logarithm of the entry on the last row of each window, and refuses a zero there, through predict_realised_vols.
  • The checks of ce.alg, through predict_realised_vols. ImpliedVolatilityPremium needs an ivpa that is not nothing, with each entry finite and strictly positive.

Returns

  • sigma::MatNum: Covariance matrix assets x assets.

Related

source
Statistics.cor — Method
Statistics.cor(ce::ImpliedVolatility, X::MatNum; dims::Int = 1, mean = nothing,
               iv::Option{<:MatNum} = nothing, ivpa::Option{<:Num_VecNum} = nothing, kwargs...)

Returns the base correlation matrix of X, after the same checks as the covariance method.

This method computes the correlation matrix of X with the base estimator ce.ce, and normalises it. The method applies no matrix processing. A PortfolioOptimisersCovariance that wraps the estimator applies it.

A correlation has no scale, so the predicted realised volatilities cannot change it. The result is the base correlation of X. The volatility model runs in cor too, because cor must refuse each configuration that cov refuses. So a ce.alg that cannot answer the call raises an error here, as it does in cov. The method discards the prediction. It does not multiply rho by the prediction and then divide the prediction out again.

That round trip is the identity only in exact arithmetic. In floating point, the round-off of one multiplication and one division moves an off-diagonal entry. A predicted volatility of zero also makes the division compute zero divided by zero. So one asset with a last implied volatility of zero turns a full row and column of the correlation into NaN. Then the matrix processing of a wrapper raises an error on a matrix that has no defect of its own.

Algorithm

  1. Refuse a call with no iv through assert_implied_volatility. Orient X and iv to observations × assets with dims_oriented. It checks dims, and it transposes both matrices when dims is 2.
  2. Check that X and iv have the same size, so that row t of iv is the implied volatility of observation t of X. Refuse a gap in X with assert_finite_sample. Refuse a gap or a negative entry in iv with assert_nonempty_nonneg_finite_val.
  3. Call Statistics.cor(library_covariance_estimator(ce.ce), X; dims = 1, mean = mean, iv = iv, kwargs...). The result is rho, the base correlation matrix. The call forwards the oriented iv, so a base estimator that reads its own implied volatility series receives it. A nested ImpliedVolatility is such an estimator.
  4. Call predict_realised_vols with ce.alg and iv / sqrt(ce.ppy), and discard the result. The call runs only for its errors. It divides iv by sqrt(ce.ppy), as cov does.
  5. Normalise rho in place with cov2cor_nan!. It divides the entry in row i and column j by the square roots of the diagonal entries i and j. It also copies the lower triangle into the upper triangle, clamps each off-diagonal entry into [-1, 1], and sets each diagonal entry to one. A wrapper needs that diagonal of ones, because matrix_processing! reads the diagonal to find whether the matrix is a correlation matrix or a covariance matrix. The one exception is an asset whose base correlation is NaN on the diagonal, such as an asset with a zero variance: its diagonal entry stays NaN.

Arguments

  • ce: Implied volatility covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.
  • mean: Optional precomputed mean. The method gives it to the base estimator.
  • iv: Annual implied volatility matrix, with the orientation and the size of X.
  • ivpa: Optional implied volatility premium adjustment factor. ImpliedVolatilityPremium needs it.
  • kwargs...: More keyword arguments for the base estimator.

Validation

  • iv is not nothing. Otherwise assert_implied_volatility throws an IsNothingError.
  • dims in (1, 2). dims_oriented checks it.
  • size(X) == size(iv), one implied volatility for each return.
  • Each entry of X is finite. Otherwise the method throws an IsNonFiniteError. The panel method removes an asset with a gap from the Coverage Universe, and this check keeps the plain call in agreement with it. Without the check, a plain call reads past the gap and gives a value for an asset that the panel method does not price.
  • Each entry of iv is finite and not negative. Otherwise the method throws a DomainError. The method refuses a gap in iv for the same reason as a gap in X. ImpliedVolatilityPremium turns a negative entry into a negative volatility, and StatsBase.cor2cov! hides its sign. ImpliedVolatilityRegression takes the logarithm of the entry on the last row of each window, and refuses a zero there, through predict_realised_vols.
  • The checks of ce.alg, through predict_realised_vols. ImpliedVolatilityPremium needs an ivpa that is not nothing, with each entry finite and strictly positive.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Related

source
Statistics.cov — Method
Statistics.cov(ce::ImpliedVolatility, X::MatNum, pnl::Option{<:AssetPanel};
               dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing,
               ivpa::Option{<:Num_VecNum} = nothing,
               active_mask::Option{<:AbstractMatrix{<:Bool}} = nothing,
               kwargs...) -> MatNum
Statistics.cor(ce::ImpliedVolatility, X::MatNum, pnl::Option{<:AssetPanel};
               dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing,
               ivpa::Option{<:Num_VecNum} = nothing,
               active_mask::Option{<:AbstractMatrix{<:Bool}} = nothing,
               kwargs...) -> MatNum

Fits an implied volatility estimate on the Coverage Universe, and expands it to the full asset universe.

ImpliedVolatility has its own method of the reduce-and-expand root of its verb. The reason is that it reads two per-asset inputs that the root does not know. One is the implied volatility surface iv, observations × assets. The other is the premium ivpa, which has one number for each asset when it is a vector. Both take the slice that X takes, so the three inputs describe the same universe.

The surface can also make that universe smaller. An implied volatility holds NaN where it has no value, as a return does. So the Coverage Universe of this fit is the one that coverage_mask finds from X and iv. The fit excludes an asset whose returns are complete but whose implied volatilities are not. expand_moment then writes NaN into the row and the column of that asset.

Algorithm

  1. Refuse a call with no iv through assert_implied_volatility. Check dims, and orient X and iv to observations × assets.
  2. Check that X and iv have the same size.
  3. Find the Coverage Universe of X and iv with coverage_mask. When the caller gives active_mask, coverage_mask_source puts it in the place of the active mask of pnl.
  4. Slice X, iv and ivpa to the Coverage Universe.
  5. Call the two-argument method on the slices.
  6. Expand the matrix with expand_moment.

Arguments

  • ce: Covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • pnl: Optional AssetPanel. The Coverage Universe of the fit comes from its active mask. If it is nothing, the rule reads only the finiteness of the returns.
  • dims: Dimension along which the computation runs.
  • mean: Optional precomputed centre of the data.
  • iv: Implied volatility surface observations × assets.
  • ivpa: Implied volatility premium adjustment factor, or nothing.
  • active_mask: The active mask of X, of the shape of X, or nothing. When it is not nothing, it takes the place of the active mask of pnl.
  • kwargs...: More keyword arguments for the two-argument method.

Validation

  • iv is not nothing. Otherwise assert_implied_volatility throws an IsNothingError.
  • dims in (1, 2).
  • size(X) == size(iv).
  • The Coverage Universe holds at least one asset.

Returns

  • sigma::MatNum: The covariance matrix or the correlation matrix on the full asset universe.

Related

source

References

[75]
B. J. Christensen and N. R. Prabhala. The relation between implied and realized volatility. Journal of Financial Economics 50, 125–150 (1998).
[76]
T. Egbers and L. Swinkels. Can implied volatility predict returns on the currency carry trade? Journal of Banking & Finance 59, 14–26 (2015).