Testing for Portfolio Alpha

library(quantmod)
env <- new.env()
Symbols <- c("SPY", "QQQ", "XLF", "TLT", "IBM", "AAPL", "XOM", "BP", "DDD")
getSymbols(Symbols = Symbols, env = env, from = "2013-01-01")
## [1] "SPY"  "QQQ"  "XLF"  "TLT"  "IBM"  "AAPL" "XOM"  "BP"   "DDD"
args <- eapply(env = env, FUN = function(x) {
    ClCl(x)
})[Symbols]
returns <- na.omit(do.call(what = merge, args = args))
colnames(returns) <- Symbols

srets <- as.matrix(returns)
X <- cbind(1, srets[, 1])
alpha <- 0
beta <- 0

for (i in 1:dim(srets)[2]) {
    alpha[i] <- (solve(t(X) %*% X) %*% t(X) %*% srets[1:(dim(srets)[1]), i])[1]
    beta[i] <- (solve(t(X) %*% X) %*% t(X) %*% srets[1:(dim(srets)[1]), i])[2]
}

t.test(alpha)
## 
##  One Sample t-test
## 
## data:  alpha
## t = -2.859, df = 8, p-value = 0.02118
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -5.190e-04 -5.559e-05
## sample estimates:
##  mean of x 
## -0.0002873

plot(density(alpha), main = "Empirical Density Function", xlab = "alpha")

plot of chunk unnamed-chunk-1


ab <- rbind(alpha, beta)

ab <- as.data.frame(ab)

names(ab) <- Symbols

attach(ab)

t.test(alpha[beta > 1], alpha[beta < 1])
## 
##  Welch Two Sample t-test
## 
## data:  alpha[beta > 1] and alpha[beta < 1]
## t = -0.2572, df = 1.151, p-value = 0.8353
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.003737  0.003537
## sample estimates:
##  mean of x  mean of y 
## -0.0003649 -0.0002651