R calculating a stock's beta (using Performanc

2019-05-11 10:13发布

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条回答
冷血范
2楼-- · 2019-05-11 10:47

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.

查看更多
登录 后发表回答