R代码:为什么预期的回报无穷大?

时间:2016-03-21 10:44:01

标签: r quantmod quantitative-finance performanceanalytics

R代码的目的是从雅虎读取MSFT历史价格,并计算其每日开盘价的回报。

#load packages
library(quantmod)
library(PerformanceAnalytics)

getSymbols("MSFT") #read data

#Call function to analyze open price
table.AnnualizedReturns(MSFT[,1]) #End of the code

结果始终显示其返回值为无穷大,如下所示:

                          MSFT.Open
Annualized Return               Inf
Annualized Std Dev         136.4471
Annualized Sharpe (Rf=0%)       Inf

我很感激,如果有人能帮助我找出造成无限的错误。

1 个答案:

答案 0 :(得分:2)

我认为您需要首先将价格转换为使用table.AnnulizedReturns

#load packages
library(quantmod)
library(PerformanceAnalytics)

getSymbols("MSFT") #read data

#Call function to analyze open price

r <- Return.calculate(MSFT[,1]) #Returns

table.AnnualizedReturns(na.omit(r)) #End of the code

                          MSFT.Open
Annualized Return            0.0683
Annualized Std Dev           0.2735
Annualized Sharpe (Rf=0%)    0.2498