Methodologies for Measuring Stock Price Return Volatility

Measuring Volatility

Volatility  is a key driver in Finance. In this section we will explore different measurements of volatility including Variance-Covariance, GARCH and Implied Volatility developed using the CBOE (2003) methodology. Below we start quite simply by demonstrating a practical method to estimate Variance-Covariance.

The Variance Covariance Matrix

In probability theory and statistics, the covariance matrix is a square matrix setting out the covariance between each pair of elements . In the matrix diagonal there are variances. The variance covariance matrix is a staple of portfolio theory but is also important for implementing practical aspects of data science like multiple regression. Below I will touch on estimating Portfolio Variance also which is important for theoretical finance and financial regulation given the prominence of Value at Risk models. In the videos below, I follow the late Simon Benninga's methodology set out here in his text book.  Simon is one of my great heroes and his text book has saved my skin  so many times when I had to explain tricky concepts to others and to myself.

This second video maps out how to use the Variance Covariance Matrix to estimate the Standard Deviation of an Asset Portfolio. Estimating the Variance of the portfolio is important for understanding the benefits of diversification and for also also estimating Value at Risk type metrics.  See below R code at bottom of page and video clip that demonstrates how to automate 

The R code produces the same variance-covariance matrix as set out by Simon Benninga. The data file Datavc can be obtained here.

read.csv("Datavc.csv")

prices <- read.csv("Datavc.csv")


prices

prices$GE


ger <- diff(log(prices$GE),1)

ger


ger <- diff(log(prices$GE),1)

msr <- diff(log(prices$MSFT),1)

jnjr <- diff(log(prices$JNJ),1)

kr <- diff(log(prices$K),1)

bar <- diff(log(prices$BA),1)

ibmr <- diff(log(prices$IBM),1)


portfolio.r <- data.frame(ger,msr,jnjr,kr,bar,ibmr)

portfolio.r


cov(portfolio.r)

R Notebook in Google Colab for estimating the Variance Covariance Matrix of Asset Price returns

Double click on Colab icon across to the left to open R Notebook and live R code will appear browser. Use the R code above and include (magic sauce):

%load_ext rpy2.ipython

This provides an alternative approach to implement R estimations. You need to download the stock price data using Excel data file here. Then save it as a csv file and title it as VarCovPriceData.csv. You need to upload it then to the sample data folder.

Python Notebook for estimating the Variance Covariance Matrix for Stock Price Returns.

Double click on Colab icon below  Python Notebook will open up in browser. The explanation of approach is available in video clip below also. You will need a gmail account to run google colab in your own google drive and it would be convenient to save your own copy. You will need to download the stock price data using the Excel data file here.

Google Colaboratory for the Variance Covariance Python Notebook

Double click on Colab icon - just across - and the Python Notebook opens up. You need to download the stock price data using Excel data file here. Then save it as a csv file and title it as VarCovPriceData.csv. You need to upload it then to the sample data folder and follow method demonstrated in video above.

Variance Covariance Matrix for Stock Price Returns in Googlesheets

I have included the video below just for completeness. Increasingly googlesheets has become part of the productivity ecosystem. Most excel functions and googlesheet functions are interoperable and for many tasks it is trivial to to move between excel and googlesheets.

Download Data from Yahoo Finance and estimate variance-covariance 

Below we describe how to download daily Price data from Yahoo finance for 10 stocks (for a 1-year period). We install the yfinance package and load in the data seamless from yahoo finance. We then calculate daily returns using those same annual observations (using the python and r code explained above). Finally, we estimate the variance-covariance matrix of the ten-asset portfolio. We also verify the R and Python Variance Covariance matrix estimation using a spreadsheet template suggested by Simon Benninga.