I'm supposed to use the downloaded daily prices from March 1, 2015 to March 1, 2017 for EBAY, GOOG, TEVA to compute the sample covariance matrix for the arithmetic returns.
This is what I have:
library(zoo)
library(tseries)
library(fBasics)
for(ticker in c("ebay", "goog", "teva", "ge")){
Prices = get.hist.quote(instrument = ticker, start = "2015-03-01",
end = "2017-03-01", quote = "Close",
provider = "yahoo",origin = "1970-01-01",
compression = "d", retclass = "zoo")}
return = diff(Prices)/lag(Prices, k=-1)
covariance = cov(return)
However, when I print covariance, I get a 1 by 1 matrix...I know that my loop is overwriting the tickers in Prices so it is only using prices from the last ticker for the rest of the code. I've tried to use the list function, to correct this, but that didn't change my end result for the covariance. I believe I"m suppose to end up with a 4x4 matrix, but I don't really understand how to get that.