Implied Volatility
PortfolioOptimisers.ImpliedVolatilityAlgorithm — Type
abstract type ImpliedVolatilityAlgorithm <: AbstractAlgorithmAbstract 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 matrixobservations × assets. The caller divides it by $\sqrt{\mathrm{ppy}}$ before the call.X: Asset returns matrixobservations × assets.ivpa: Implied volatility premium adjustment factor. It isnothingwhen the caller gives no factor, so an algorithm that needs a factor must raise an error onnothing.
Returns
rv_p::VecNum: The predicted realised volatility of each asset, in the units ofX.
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.64Related
PortfolioOptimisers.ImpliedVolatilityRegression — Type
struct ImpliedVolatilityRegression{__T_ve, __T_ws, __T_re} <: ImpliedVolatilityAlgorithmPredicts 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 isdiv(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()) -> ImpliedVolatilityRegressionKeywords correspond to the struct's fields.
Validation
ws > 1. A window of one row has no dispersion. Its corrected standard deviation isNaN, and its uncorrected one is zero, which has no logarithm.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ve: Recursively updated throughfactory.
Examples
julia> ImpliedVolatilityRegression()ImpliedVolatilityRegression ve ┼ SimpleVariance │ me ┼ SimpleExpectedReturns │ │ w ┴ nothing │ w ┼ nothing │ corrected ┴ Bool: true ws ┼ Int64: 20 re ┼ LinearModel │ kwargs ┴ @NamedTuple{}: NamedTuple()Related
ImpliedVolatilityAlgorithmImpliedVolatilityPremiumImpliedVolatilitypredict_realised_vols: the model and the steps of the branch this tag selects.realised_volimplied_volfactory
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.
PortfolioOptimisers.ImpliedVolatilityPremium — Type
struct ImpliedVolatilityPremium <: ImpliedVolatilityAlgorithmDivides 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() -> ImpliedVolatilityPremiumExamples
julia> ImpliedVolatilityPremium()ImpliedVolatilityPremium()Related
ImpliedVolatilityAlgorithmImpliedVolatilityRegressionImpliedVolatilitypredict_realised_vols: the closed form of the branch this tag selects.
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.
PortfolioOptimisers.ImpliedVolatility — Type
struct ImpliedVolatility{__T_ce, __T_alg, __T_ppy, __T_cache} <: AbstractCovarianceEstimatorCovariance 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. Thecovandcormethods divide the implied volatilities bysqrt(ppy)before the algorithm reads them.
cache: Optional partial-fit state. It isnothinguntilpartial_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.factorykeeps it unchanged, because a factory call resolves the configuration, not the sample.port_opt_viewcopies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone.obs_weights_viewremoves 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) -> ImpliedVolatilityKeywords 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
ceis not anAbstractVarianceEstimator. A variance estimator has nocovorcor, soassert_covariance_estimatorraises anArgumentErrorthat namesce.ppy > 0.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ce: Recursively updated throughfactory.alg: Recursively updated throughfactory.cache: Carried unchanged throughfactory.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
ce: Recursively viewed throughport_opt_view.cache: Sliced to the selected assets throughport_opt_view.
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: 252Related
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
ivpais notnothing. This method is the branch that fails, and it raises anArgumentError.
Related
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 matrixobservations × 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
ivpais finite and strictly positive. A factor that is not positive makes a negative volatility, andStatsBase.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, somatrix_processing!finds no defect, and no later step sees it. - A vector
ivpahas one entry for each asset. A vector of a different length raises aDimensionMismatchfrom the broadcast.
Returns
rv::AbstractArray: The predicted realised volatilities, which are the last row ofivdivided byivpa.
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.24Related
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.
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
- Read
TandNfromsize(X), and setchunktodiv(T, alg.ws). - Check that
chunkexceeds four. - Call
realised_volwithalg.ve. The result isrv, the realised volatility of each window. - Call
implied_volonivwith the samechunk,TandN. The result replacesiv, and holds the implied volatility at the last row of each window. The window count comes fromX, so the function readsivover the rows of the returns sample. - Check that
rvandivhave 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. SetT2to their number of rows, which ischunk. - Replace
rvandivby their natural logarithms. - Make
ovec, the intercept column of ones, of lengthT2 - 1. - For each asset
i, make the design matrixX_tfromovecand the firstT2 - 1rows ofivandrv. Make the responsey_tfrom the rows2:T2ofrv, and the prediction rowX_pfrom the rowT2. - Fit
alg.reonX_tandy_t, with the first column named to it byfactory(alg.re, InterceptColumn(1)), so that a penalised target such asElasticNetdoes not shrink the intercept. Predict fromX_pwith the fit, and setrv_p[i]to the exponential of the prediction. - 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 matrixobservations × assets.X: Asset returns matrixobservations × assets, from which the function computes the realised volatility. It also sets the number of windows, soivmust have as many rows asX.::Any: The place ofivpa. The method does not read it.
Validation
chunk > 4. The fit haschunk - 1rows for three coefficients, so it has a residual only whenchunk > 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 thewsrows 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.
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 ofXin one year.
So each diagonal entry of $\hat{\mathbf{\Sigma}}$ is the square of the predicted realised volatility of that asset, not one.
Algorithm
- Refuse a call with no
ivthroughassert_implied_volatility. OrientXandivtoobservations × assetswithdims_oriented. It checksdims, and it transposes both matrices whendimsis2. - Check that
Xandivhave the same size, so that rowtofivis the implied volatility of observationtofX. Refuse a gap inXwithassert_finite_sample. Refuse a gap or a negative entry inivwithassert_nonempty_nonneg_finite_val. - Call
Statistics.cor(library_covariance_estimator(ce.ce), X; dims = 1, mean = mean, iv = iv, kwargs...). The result issigma, the base correlation matrix. The call forwards the orientediv, so a base estimator that reads its own implied volatility series receives it. A nestedImpliedVolatilityis such an estimator. Each other estimator of the library takesivinto its ownkwargs...and does not read it. - Divide
ivbysqrt(ce.ppy). This converts the annual implied volatility to the frequency ofX. - Call
predict_realised_volswithce.alg. The result replacesiv, and holds one predicted realised volatility for each asset. The implied volatilities are the second argument, and the returns are the third. - Scale
sigmain place withStatsBase.cor2cov!, which applies the closed form above.
Arguments
ce: Implied volatility covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 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 ofX.ivpa: Optional implied volatility premium adjustment factor.ImpliedVolatilityPremiumneeds it.kwargs...: More keyword arguments for the base estimator.
Validation
ivis notnothing. Otherwiseassert_implied_volatilitythrows anIsNothingError.dims in (1, 2).dims_orientedchecks it.size(X) == size(iv), one implied volatility for each return.- Each entry of
Xis finite. Otherwise the method throws anIsNonFiniteError. 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
ivis finite and not negative. Otherwise the method throws aDomainError. The method refuses a gap inivfor the same reason as a gap inX.ImpliedVolatilityPremiumturns a negative entry into a negative volatility, andStatsBase.cor2cov!hides its sign.ImpliedVolatilityRegressiontakes the logarithm of the entry on the last row of each window, and refuses a zero there, throughpredict_realised_vols. - The checks of
ce.alg, throughpredict_realised_vols.ImpliedVolatilityPremiumneeds anivpathat is notnothing, with each entry finite and strictly positive.
Returns
sigma::MatNum: Covariance matrixassets x assets.
Related
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
- Refuse a call with no
ivthroughassert_implied_volatility. OrientXandivtoobservations × assetswithdims_oriented. It checksdims, and it transposes both matrices whendimsis2. - Check that
Xandivhave the same size, so that rowtofivis the implied volatility of observationtofX. Refuse a gap inXwithassert_finite_sample. Refuse a gap or a negative entry inivwithassert_nonempty_nonneg_finite_val. - Call
Statistics.cor(library_covariance_estimator(ce.ce), X; dims = 1, mean = mean, iv = iv, kwargs...). The result isrho, the base correlation matrix. The call forwards the orientediv, so a base estimator that reads its own implied volatility series receives it. A nestedImpliedVolatilityis such an estimator. - Call
predict_realised_volswithce.algandiv / sqrt(ce.ppy), and discard the result. The call runs only for its errors. It dividesivbysqrt(ce.ppy), ascovdoes. - Normalise
rhoin place withcov2cor_nan!. It divides the entry in rowiand columnjby the square roots of the diagonal entriesiandj. 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, becausematrix_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 isNaNon the diagonal, such as an asset with a zero variance: its diagonal entry staysNaN.
Arguments
ce: Implied volatility covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 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 ofX.ivpa: Optional implied volatility premium adjustment factor.ImpliedVolatilityPremiumneeds it.kwargs...: More keyword arguments for the base estimator.
Validation
ivis notnothing. Otherwiseassert_implied_volatilitythrows anIsNothingError.dims in (1, 2).dims_orientedchecks it.size(X) == size(iv), one implied volatility for each return.- Each entry of
Xis finite. Otherwise the method throws anIsNonFiniteError. 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
ivis finite and not negative. Otherwise the method throws aDomainError. The method refuses a gap inivfor the same reason as a gap inX.ImpliedVolatilityPremiumturns a negative entry into a negative volatility, andStatsBase.cor2cov!hides its sign.ImpliedVolatilityRegressiontakes the logarithm of the entry on the last row of each window, and refuses a zero there, throughpredict_realised_vols. - The checks of
ce.alg, throughpredict_realised_vols.ImpliedVolatilityPremiumneeds anivpathat is notnothing, with each entry finite and strictly positive.
Returns
rho::MatNum: Correlation matrixassets x assets.
Related
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...) -> MatNumFits 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
- Refuse a call with no
ivthroughassert_implied_volatility. Checkdims, and orientXandivtoobservations × assets. - Check that
Xandivhave the same size. - Find the Coverage Universe of
Xandivwithcoverage_mask. When the caller givesactive_mask,coverage_mask_sourceputs it in the place of the active mask ofpnl. - Slice
X,ivandivpato the Coverage Universe. - Call the two-argument method on the slices.
- Expand the matrix with
expand_moment.
Arguments
ce: Covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.pnl: OptionalAssetPanel. The Coverage Universe of the fit comes from its active mask. If it isnothing, 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 surfaceobservations × assets.ivpa: Implied volatility premium adjustment factor, ornothing.active_mask: The active mask ofX, of the shape ofX, ornothing. When it is notnothing, it takes the place of the active mask ofpnl.kwargs...: More keyword arguments for the two-argument method.
Validation
ivis notnothing. Otherwiseassert_implied_volatilitythrows anIsNothingError.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
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).