The purpose of the R-code is to read MSFT historical prices from Yahoo, and calculate its return for daily open prices.
#load packages
library(quantmod)
library(PerformanceAnalytics)
getSymbols("MSFT") #read data
#Call function to analyze open price
table.AnnualizedReturns(MSFT[,1]) #End of the code
The result always shows its return is infinity as follows:
MSFT.Open
Annualized Return Inf
Annualized Std Dev 136.4471
Annualized Sharpe (Rf=0%) Inf
I appreciate if one can help me identify the mistake causing infinity.
I think you need to convert prices to returns first to use 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