- ago
I'm trying to figure out how to calculate the Sharpe Ratio for an individual stock. The numerator is easy enough to calculate. One computes the risk-free adjusted mean of all the profits (or losses).

numerator = Mean(PositionProfit - Tbill%rate/100/252TdaysPerYr*PositionExposure)

But to get the denominator, I need the standard deviation of the return. But what am I really taking the standard deviation of here?

UPDATE: Apparently, one takes the standard deviation of all the non-adjusted position profits. So we are computing the Z-score of the profit after subtracting off the zero-risk Treasury rate contribution. Of course one needs to normalize all the units (time and rates) when making these calculations.

The problem is my numbers don't exactly agree with WL's Sharpe Ratio, although they are somewhat close.

The discussion in the link below employs the geometric mean. I prefer the median instead since we are dealing with a skewed population. I think WL uses the arithmetic mean. https://quant.stackexchange.com/questions/55050/questions-about-sharpe-ratio-calculation
0
117
1 Replies

Reply

Bookmark

Sort
- ago
#1
Well, apparently PositionExposure is not a term in the Sharpe Ratio calculation as I thought above. I'm not sure I like that, but that's the way it is. The link below illustrates a nice cookbook example. https://corporatefinanceinstitute.com/resources/financial-modeling/sharpe-ratio-calculator/

However, when I place their method into WL (see code below), the Sharpe Ratio I get doesn't compare with what WL returns in the Basic Score Card. So which calculation is right?
CODE:
   using MathNet.Numerics.Statistics;    . . .    public override void BacktestComplete()    {       double[] returns = new double[GetPositions().Count];       int i = 0;       foreach (Position position in GetPositions())          returns[i++] = position.ProfitPercent;       double mean = true ? Statistics.Mean(returns) : Statistics.Median(returns);       mean -= Backtester.RiskFreeRateOfReturn; //excess return cal       WriteToDebugLog((mean / Statistics.StandardDeviation(returns)) + "=Sharpe Ratio");       WriteToDebugLog(Backtester.RiskFreeRateOfReturn + "=riskFree");    }



Here are the positions of FG that created this Sharpe Ratio result. You can import them into Excel.
CODE:
Position   Symbol   Quantity   "Entry Date"   "Entry Price"   "Exit Date"   "Exit Price"   Profit   "Profit %"   "Bars Held"   "Entry Signal"   "Exit Signal"   "MFEPct"   "MAEPct"    Long   FG   3600   8/28/2017   11.11   9/13/2017   11.2765   599.4000000000035   1.4986498649865074   11   Voss predictor buy   Voss predictor sell   1.7101710171017215   -2.25022502250225    Long   FG   3900   3/20/2018   10.28   3/28/2018   10.41   507.00000000000307   1.2645914396887237   6   Voss predictor buy   Voss predictor sell   2.2373540856031173   -2.6264591439688676    Long   FG   4400   9/20/2018   9.06   9/26/2018   8.82   -1056.000000000001   -2.6490066225165587   4   Voss predictor buy   Voss predictor sell   0.8830022075055197   -3.6423841059602657    Long   FG   5800   1/4/2019   6.98   1/14/2019   7.5   3015.9999999999977   7.44985673352435   6   Voss Money Flow buy   Voss predictor sell   9.025787965616045   -1.146131805157594    Long   FG   5600   8/8/2019   7.08   8/20/2019   7.75   3751.9999999999995   9.46327683615819   8   Voss predictor buy   Voss predictor sell   11.299435028248585   -10.868644067796607    Long   FG   4100   2/3/2020   9.69   2/6/2020   10.28   2418.9999999999995   6.088751289989679   3   Voss Money Flow buy   Voss predictor sell   6.088751289989679   -0.05159958720329211    Long   FG   3300   2/7/2020   12.28   2/12/2020   12.18   -329.9999999999988   -0.8143322475570003   3   Voss predictor buy   Voss predictor sell   0.40716612377850736   -1.6693811074918574    Long   FG   4800   6/1/2020   8.34   12/8/2022   18.55   49008.00000000001   122.42206235011992   6   Voss predictor buy   Voss predictor sell   163.78896882494004   -2.877697841726621    Long   FG   2000   12/16/2022   19.75   12/29/2022   19.83   159.9999999999966   0.40506329113923184   8   Voss predictor buy   Voss predictor sell   11.97468354430379   -3.7974683544303796    Long   FG   2000   1/12/2023   20.25   1/23/2023   20.95   1399.9999999999986   3.456790123456787   6   Voss predictor buy   Voss predictor sell   7.555555555555562   -3.4074074074074137    Long   FG   1400   10/9/2023   28.03   10/16/2023   28.93   1259.999999999998   3.210845522654294   5   Voss predictor buy   Voss predictor sell   4.031394933999283   -0.4816268283981504    Long   FG   1300   10/30/2023   30.03   11/7/2023   31.97   2521.9999999999973   6.460206460206454   6   Voss predictor buy   Voss predictor sell   9.82350982350981   -0    Long   FG   1000   5/6/2024   40.14   5/22/2024   42.21   2070.0000000000005   5.156950672645741   12   Voss Money Flow buy   Voss predictor sell   7.9270054808171375   -3.7369207772795217    Long   FG   800   11/22/2024   47.59   Open   0   591.9999999999959   1.554948518596333   5   Voss predictor buy      6.640050430762758   -1.092666526581221   

The calculation isn't that complicated, which makes me think it's not the calculation method that's causing these differences.

In addition, ...
CODE:
WriteToDebugLog(Backtester.RiskFreeRateOfReturn + "=riskFree");
returns zero in Initialize. When does this value become valid? Is it not until BacktestComplete?
0

Reply

Bookmark

Sort