Calculate Historical Volatility Using EWMA

Volatility is the most commonly used measure of risk. Volatility in this sense can either be historical volatility (one observed from past data), or it could implied volatility (observed from market prices of financial instruments.)

The historical volatility can be calculated in three ways, namely:

1. Simple volatility,
2. Exponentially Weighted Moving Average (EWMA)
3. GARCH

One of the major advantages of EWMA is that it gives more weight to the recent returns while calculating the returns.  In this article, we will look at how volatility is calculated using EWMA. So, let’s get started:

Step 1: Calculate log returns of the price series

If we are looking at the stock prices, we can calculate the daily lognormal returns, using the formula ln(Pi/Pi-1), where P represents each day’s closing stock price. We need to use the natural log because we want the returns to be continuously compounded.  We will now have daily returns for the entire price series.

Step 2: Square the returns

The next step is the take the square of long returns. This is actually the calculation of simple variance or volatility represented by the following formula:

Here, u represents the returns, and m represents the number of days.

Step 3: Assign weights

Assign weights such that recent returns have higher weight and older returns have lesser weight. For this we need a factor called Lambda (λ), which is a smoothing constant or the persistent parameter. The weights are assigned as (1- λ)λ0. Lambda must be less than 1. Risk metric uses lambda = 94%. The first weight will be (1-0.94) = 6%, the second weight will be 6%*0.94 = 5.64% and so on. In EWMA all the weights sum to 1, however they are declining with a constant ratio of λ.

Step 4: Multiply Returns-squared with the weights

Step 5: Take the summation of R2*w

This is the final EWMA variance. The volatility will be the square root of variance.

The following screenshot shows the calculations.

The above example that we saw is the approach described by RiskMetrics. The generalized form of EWMA can be represented as the following recursive formula:

You may find these interesting

Accelerate your finance career with cutting-edge data skills.
Join Finance Train Premium for unlimited access to a growing library of ebooks, projects and code examples covering financial modeling, data analysis, data science, machine learning, algorithmic trading strategies, and more applied to real-world finance scenarios.
I WANT TO JOIN
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

• Getting Started with R
• R Programming for Data Science
• Data Visualization with R
• Financial Time Series Analysis with R
• Quantitative Trading Strategies with R
• Derivatives with R
• Credit Risk Modelling With R
• Python for Data Science
• Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.