R 计算股票的 beta(使用 PerformanceAnalytics CAPM.beta() 函数或 lm() 函数产生意外结果) [英] R calculating a stock's beta (using PerformanceAnalytics CAPM.beta() function or lm() function producing unexpected results)

查看:34
本文介绍了R 计算股票的 beta(使用 PerformanceAnalytics CAPM.beta() 函数或 lm() 函数产生意外结果)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PerformanceAnalytics CAPM.beta() 函数在 R 中量化股票的 beta(基准测试与 SPY),结果甚至不接近我在 Yahoo/Google Finance 在线看到的值.代码:

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])

对于上面的例子,雅虎/Finviz/Google 都列出了 ACAD 的 beta 为 2.6 到 3.0 以上.虽然我不确定每个站点的回溯期是多少,但更改上述代码中的值会产生小于 1 的 1、2、3 年回溯的 beta 值.

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.

同样,通过尝试使用 lm() 计算 beta,我得到了 0.39 beta 的 ACAD ~ SPY 2 年回顾:

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

我错过了什么?

推荐答案

Beta 是根据回报计算的,通常是每月一次.您确实希望在使用 lm 时模型拟合中的截距项 (alpha).

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 

在这种情况下,针对 36 个月调整后的月末收盘计算的 Beta 值约为 2.6.

Beta calculated for 36 months of adjusted month-end close is about 2.6 in this case.

这篇关于R 计算股票的 beta(使用 PerformanceAnalytics CAPM.beta() 函数或 lm() 函数产生意外结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆