问题
I am trying to quantify a stock's beta (bench marked vs. SPY) in R using the PerformanceAnalytics CAPM.beta() function and the results aren't even close to the values I am seeing online at Yahoo/Google Finance. The code:
require(PerformanceAnalytics)
start_date <- "2013-08-24"
acad <- getSymbols("ACAD", from = start_date, auto.assign = F)
spy <- getSymbols("SPY", from = start_date, auto.assign = F)
CAPM.beta(acad[,6], spy[,6])
For the above example, Yahoo/Finviz/Google all list ACAD's beta at 2.6 to more than 3.0. While I am not sure what the lookback period is for each site, changing the value in the above code produces a beta value of less than 1 for 1,2,3 yr lookbacks.
Similarly, by trying to calculate the beta using lm(), I am getting ie 0.39 beta for ACAD ~ SPY 2 year lookback:
m <- lm(acad[,6] ~ spy[,6] + 0)
beta <- coef(m)[1]
beta
what am I missing?
回答1:
Beta is calculated in terms of returns, often montly. You do want the intercept term (alpha) in the model fit when using lm
.
start_date <- "2012-07-01"
acad <- getSymbols("ACAD", from = start_date, auto.assign = F)
spy <- getSymbols("SPY", from = start_date, auto.assign = F)
r<-function(x) {m<-to.monthly(x[,6])[,4];diff(m)/lag(m)}
coef(lm(r(acad)[2:37]~r(spy)[2:37]))
#> (Intercept) r(spy)[2:37]
#> 0.08601629 2.62485092
Beta calculated for 36 months of adjusted month-end close is about 2.6 in this case.
来源:https://stackoverflow.com/questions/32186233/r-calculating-a-stocks-beta-using-performanceanalytics-capm-beta-function-or