R 代码:为什么预期的 return 无穷大?
R-code: Why is the expected return infinity?
R 代码的目的是从 Yahoo 读取 MSFT 历史价格,并计算其 return 每日开盘价。
#load packages
library(quantmod)
library(PerformanceAnalytics)
getSymbols("MSFT") #read data
#Call function to analyze open price
table.AnnualizedReturns(MSFT[,1]) #End of the code
结果总是显示其return为无穷大如下:
MSFT.Open
Annualized Return Inf
Annualized Std Dev 136.4471
Annualized Sharpe (Rf=0%) Inf
如果有人能帮助我找出导致无穷大的错误,我将不胜感激。
我认为您需要先将价格转换为 returns 才能使用 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
R 代码的目的是从 Yahoo 读取 MSFT 历史价格,并计算其 return 每日开盘价。
#load packages
library(quantmod)
library(PerformanceAnalytics)
getSymbols("MSFT") #read data
#Call function to analyze open price
table.AnnualizedReturns(MSFT[,1]) #End of the code
结果总是显示其return为无穷大如下:
MSFT.Open
Annualized Return Inf
Annualized Std Dev 136.4471
Annualized Sharpe (Rf=0%) Inf
如果有人能帮助我找出导致无穷大的错误,我将不胜感激。
我认为您需要先将价格转换为 returns 才能使用 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