Question about Sharpe Ratio calculation

Created at 11 Oct 2022, 08:27
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Waxy's avatar

Waxy

Joined 12.05.2015

Question about Sharpe Ratio calculation
11 Oct 2022, 08:27


Hello Spotware,

I've been trying to replicate the result of Sharpe Ratio given by the backtester, but I've been unable to come with the same result, the formula I found online is:

Sharpe Ratio | Definition, interpretation & example

So my questions are:
1 - What value are you giving for "risk-free rate of return"
2 - The standard deviation is calculated from returns trade by trade, or maybe returns on a monthly, weekly or even daily basis?

Regards,


@Waxy
Replies

ME-Pepper
12 Oct 2022, 15:42 ( Updated at: 21 Dec 2023, 09:22 )

RE: Answer about Sharpe and Sortino Ratio calculation
      public static double SharpeSortino(bool isSortino, IEnumerable<double> vals)
      {
         if (vals.Count() < 2) return double.NaN;
         double average = vals.Average();
         double sd = Math.Sqrt(vals.Where(val => (!isSortino || val < average)).Select(val => (val - average) * (val - average)).Sum() / (vals.Count() - 1));
         return average / sd;
      }

And so can you call it:

         var SharpeRatio = SharpeSortino(false, History.Select(trade => trade.NetProfit));
         var SortinoRatio = SharpeSortino(true, History.Select(trade => trade.NetProfit));

This will give you the exact same results as Spotware is calculating it.

You are welcome

PS: The secret is the division by (vals.Count() - 1) and not just vals.Count for the standard deviation as described here:
(look for "sample standard deviation"


Waxy said:

Hello Spotware,

I've been trying to replicate the result of Sharpe Ratio given by the backtester, but I've been unable to come with the same result, the formula I found online is:

Sharpe Ratio | Definition, interpretation & example

So my questions are:
1 - What value are you giving for "risk-free rate of return"
2 - The standard deviation is calculated from returns trade by trade, or maybe returns on a monthly, weekly or even daily basis?

Regards,

 


@ME-Pepper

Waxy
13 Oct 2022, 10:45

RE: RE: Answer about Sharpe and Sortino Ratio calculation

Your example works great, thank you!


@Waxy