Exponentially Weighted Covariance

The Exponentially Weighted Covariance weighs the products of the deviations from the mean return by weights that fall geometrically with the age of a period, so recent periods count most and the matrix follows changes in volatility and correlation, the weighting of RiskMetrics (J.P. Morgan/Reuters, 1996).

The formula for the Exponentially Weighted Covariance starts from the smoothing factor alpha of the span n, the number of periods over which the weights spread, and the weights \(w_{t}\) of the T periods:

\[\alpha = \frac{2}{n + 1}\] \[w_{t} = \frac{(1 - \alpha)^{T - t}}{\sum_{s=1}^{T} (1 - \alpha)^{T - s}}\]

It weighs the products of the deviations of the returns \(r_{i , t}\) of every pair of assets from their averages \(m_{i}\):

\[\Sigma_{i,j} = \sum_{t=1}^{T} w_{t} \cdot (r_{i,t} - m_{i}) \cdot (r_{j,t} - m_{j})\]

A short span reacts quickly to a change in market conditions and is noisier; RiskMetrics uses a decay factor 1 - alpha of 0.94 for daily returns, a span of about 32 periods.

Its parameters can be set, and it can be shown as a correlation matrix. The covariance matrix holds the variance of every asset and the covariance of every pair, the risk input of the mean-variance analysis of Markowitz (1952). With N assets it holds N (N + 1) / 2 numbers to estimate, and when N is not small compared to the number of periods T, the sample estimate is noisy and ill-conditioned: its smallest eigenvalues come out too small, and an optimizer that inverts it puts large weights on the combinations of assets that only look safe in the sample. The estimators differ in how they deal with this: by shrinking towards a structured target, by cleaning the eigenvalues, by weighting recent periods, by counting only large moves or by resisting outliers. Every estimate is annualized with the number of periods in a year.

Also known as: EWMA covariance, RiskMetrics covariance, exponential covariance.

In the Finance Toolkit this is get_covariance_estimate with method="exponential", the same function as Covariance Estimate.

Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_covariance_estimate:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT", "JNJ", "XOM"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.portfolio.get_covariance_estimate(method="exponential")

Which returns:

References

  • Paper J.P. Morgan/Reuters (1996). “RiskMetrics Technical Document.” 4th edition, New York.
  • Library Referenced against PyPortfolioOpt’s exp_cov (Exponentially Weighted Covariance)
  • Library Referenced against skfolio’s RegimeAdjustedEWCovariance (Regime Adjusted Exponentially Weighted Covariance, its defaults)
Share