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 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 and Value at Risk which are important for theoretical finance and financial regulation. 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
Value at risk (VaR) is a measure of the risk of loss for a single asset or portfolio of assets. It estimates how much a portfolio could lose (with a given probability), given historical flux, in a set time period such as a day. VaR is characteristically used by financial institutions and regulators to calibrate the equity position required to cover possible losses. VaR measures the worst expected loss under normal market conditions over a specific time interval at a given confidence level. “VaR answers the question: how much can I lose with x% probability over a pre-set horizon” (J. P. Morgan, RiskMetrics—Technical Document).
A worked example below from John C Hull which follows an exam style question. For complete spreadsheet - please follow link.
The two videos below use data from John C Hull. Please follow link. If that link is not working please use this excel link. Here a much bigger data set is used and I takes John Hull's example and I apply the matrix multiplication approach that was outlined by Simon Benninga. In the original Benninga case the data was annual. Here below the data was daily so - we do not expect the value of the portfolio to grow significantly for the shorter time frame.
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)