I'm confused and having issues using `SharpeRatio` from the `PerformanceAnalytics` package. After all was said and done, I can't seem to get my number to match the sharpe ratio posted on Yahoo Finance.
Here's my procedure (I'll try to keep it simple):
> getSymbols("XLU", src = "yahoo", auto.assign = TRUE, return.class = "xts")
> head(XLU)
XLU.Open XLU.High XLU.Low XLU.Close XLU.Volume XLU.Adjusted
2007-01-03 36.41 37.10 36.41 36.82 4229300 23.33392
2007-01-04 36.86 36.94 36.67 36.77 2958400 23.30223
2007-01-05 36.67 36.67 35.99 36.11 3784500 22.88396
2007-01-08 35.97 36.22 35.93 36.09 2415000 22.87128
2007-01-09 35.94 36.18 35.87 36.12 2342100 22.89030
2007-01-10 35.99 36.20 35.95 36.13 1918100 22.89664
> adj <- Ad(XLU)
> head(Ad(XLU))
XLU.Adjusted
2007-01-03 23.33392
2007-01-04 23.30223
2007-01-05 22.88396
2007-01-08 22.87128
2007-01-09 22.89030
2007-01-10 22.89664
> monthlyRTN <- monthlyReturn(Ad(XLU))
> monthlyRTN <- monthlyRTN["2016-08/2019-08"]
> head(monthlyRTN)
monthly.returns
2016-08-31 -0.055448911
2016-09-30 0.003613012
2016-10-31 0.008981693
2016-11-30 -0.054218282
2016-12-30 0.048991012
2017-01-31 0.012559332
> SharpeRatio(monthlyRTN)
monthly.returns
StdDev Sharpe (Rf=0%, p=95%): 0.2386500
VaR Sharpe (Rf=0%, p=95%): 0.1508941
ES Sharpe (Rf=0%, p=95%): 0.1304109
The 0.23865 is nowhere near the 0.63 posted on Yahoo Finance under Risk Statistics under 3 years. What am I missing?
Thanks.
Here's my procedure (I'll try to keep it simple):
> getSymbols("XLU", src = "yahoo", auto.assign = TRUE, return.class = "xts")
> head(XLU)
XLU.Open XLU.High XLU.Low XLU.Close XLU.Volume XLU.Adjusted
2007-01-03 36.41 37.10 36.41 36.82 4229300 23.33392
2007-01-04 36.86 36.94 36.67 36.77 2958400 23.30223
2007-01-05 36.67 36.67 35.99 36.11 3784500 22.88396
2007-01-08 35.97 36.22 35.93 36.09 2415000 22.87128
2007-01-09 35.94 36.18 35.87 36.12 2342100 22.89030
2007-01-10 35.99 36.20 35.95 36.13 1918100 22.89664
> adj <- Ad(XLU)
> head(Ad(XLU))
XLU.Adjusted
2007-01-03 23.33392
2007-01-04 23.30223
2007-01-05 22.88396
2007-01-08 22.87128
2007-01-09 22.89030
2007-01-10 22.89664
> monthlyRTN <- monthlyReturn(Ad(XLU))
> monthlyRTN <- monthlyRTN["2016-08/2019-08"]
> head(monthlyRTN)
monthly.returns
2016-08-31 -0.055448911
2016-09-30 0.003613012
2016-10-31 0.008981693
2016-11-30 -0.054218282
2016-12-30 0.048991012
2017-01-31 0.012559332
> SharpeRatio(monthlyRTN)
monthly.returns
StdDev Sharpe (Rf=0%, p=95%): 0.2386500
VaR Sharpe (Rf=0%, p=95%): 0.1508941
ES Sharpe (Rf=0%, p=95%): 0.1304109
The 0.23865 is nowhere near the 0.63 posted on Yahoo Finance under Risk Statistics under 3 years. What am I missing?
Thanks.