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.
Can you elaborate? Even after I use endpoints() to subset end-of-month prices before computing monthly returns, I got the same monthlyRTN, and thus, same SharpeRatio as before.
Unless you can see how Yahoo finance is calculating the Sharpe Ratio, don't waste your time trying to match their value. Are they using the risk free rate of return in the calculations? Are you (doesn't look like it)? As @GRULSTMRNN mentioned, what is your return period vs theirs?
I left out the risk free rate in this example because I wanted to keep it simple for the forum, but I do use it in my actual script. Right now, I'm using monthly returns. I have no idea how Yahoo calculates it. I am using Yahoo to check and confirm I am computing things correctly in my script, but it sounds like that is futile.
If you have no idea how they calculate it and what assumptions they make then wanting to match numbers is a useless pursuit. Even a different risk free rate completely distorts results. You may also improperly scale monthly results to annualized figures,not saying you do, just voicing a hunch. Figure out their comoutional assumptions then we can further help, otherwise asking further will not get you answers
I think that the 0.63 is an annual value. So you can't compare it to the monthly value you calculate. It would be better, as a first step, to use the daily returns to calculate an annual Sharpe ratio and see whether that is more in line with your desired Yahoo target value.
What is you risk free rate you are using? Is your base currency USD or which other currency? Rhetoric question: what RFR would you use for EUR or JPY as base? And why in the world is Yahoo Finance reporting so, so important to you?