Skip to content

Instantly share code, notes, and snippets.

@shabbychef
Last active December 12, 2015 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shabbychef/4728866 to your computer and use it in GitHub Desktop.
Save shabbychef/4728866 to your computer and use it in GitHub Desktop.
check out SPY, TLT, GLD, AAPL...
require(quantmod)
getSymbols(c("SPY","TLT","GLD","AAPL"))
allofem <- merge(SPY[,"SPY.Adjusted"],TLT[,"TLT.Adjusted"],GLD[,"GLD.Adjusted"],AAPL[,"AAPL.Adjusted"])
mo.pry <- to.monthly(allofem,OHLC=FALSE)
mo.ret <- diff(log(mo.pry))
sub.ret <- mo.ret[(dim(mo.ret)[1]-59):dim(mo.ret)[1],]
mu <- apply(sub.ret,2,mean,na.rm=TRUE)
Sg <- cov(sub.ret,use="complete.obs")
w <- solve(Sg,mu)
n <- dim(sub.ret)[1]
p <- dim(sub.ret)[2]
T2 <- n * w %*% mu
df1 <- p
df2 <- n - p
Fs <- T2 * df2 / (df1 * (n-1))
Fpv <- pf(Fs,df1,df2,lower.tail=FALSE)
require(rrcov)
T2.test(as.matrix(sub.ret))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment