quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

Probabilistic Sharpe ratio uses the wrong kurtosis and can return a probability above 1

Open Astralchemist opened this issue 2 months ago • 1 comments

There are three problems in probabilistic_ratio in the stats module It is behind probabilistic_sharpe_ratio and the Prob Sharpe Ratio row in reports This is on main at fbd10da and in release 0.0.81

The kurtosis is counted wrong The formula comes from Bailey and Lopez de Prado and it needs raw kurtosis which is 3 for normal returns The kurtosis function in quantstats gives excess kurtosis which is 0 for normal returns The line then takes 3 off again so the standard error comes out too small This came in with 9493ed8 in June 2022 which fixed the sign of the skew term but also changed the kurtosis term The rubenbriones implementation that PR 195 pointed to gets it right because it asks scipy for raw kurtosis

How big it is Lopez de Prado has a worked example of a hedge fund with monthly returns that have a mean of 3.6 percent and a standard deviation of 7.9 percent and a skew of minus 2.448 and a raw kurtosis of 10.164 The published answer is 0.913 after 24 months and 0.953 after 36 months quantstats gives 0.919 and 0.958 For normal returns quantstats makes the standard error about 8 percent too small I checked that by simulating 100000 samples of 120 normal returns and measuring how much the Sharpe ratio really moves The fixed formula lands within half a percent of that The effect grows with the Sharpe ratio per period so it is small on daily data and bigger on monthly data

annualize can give a probability above 1 When annualize is True the result is multiplied by the square root of 252 So a probability of 0.958 comes back as 15.2 It also uses 252 even when periods is set to something else A probability cannot be annualized so the simplest fix is for annualize to do nothing

rf is used two different ways The docstring says rf is the annual risk free rate and the report passes it that way But the function takes rf straight off the Sharpe ratio per period instead of off the returns So in the report the Sharpe row and the Prob Sharpe Ratio row treat rf differently In one test with a year of daily returns and rf at 5 percent the Sharpe row goes from 1.14 to 0.74 which is right The Prob Sharpe Ratio row goes from 0.87 to 0.64 because it ends up testing whether the yearly Sharpe beats about 0.79 Measured on excess returns the way the Sharpe row does it the answer is 0.77

How I checked I built monthly return series with exactly the moments of the published example The fixed version matches the published answers to 3 decimals and matches the rubenbriones implementation to 6 decimals on the same data

The fix Add 3 to the kurtosis before it goes into the formula Pass rf to sharpe or sortino so the ratio is measured on excess returns and then compare it with zero Return the probability as it is when annualize is True I have a branch with the fix and 5 new tests that fail on main and pass with it and all 130 tests pass Happy to open a PR if you want it or you can take the change as it is

Astralchemist avatar Sep 25 '26 14:09 Astralchemist

Fixed in v0.0.82, now on PyPI.

Both parts were real. The raw-kurtosis formula was being fed excess kurtosis, and the estimator standard error did not match the Bailey & Lopez de Prado reference - at SR=0.2 it produced 0.99000 where the reference gives 1.02000.

0.0.82 uses kurtosis() + 3, the corrected sigma_sr, and routes rf into the underlying Sharpe/Sortino instead of discarding it. The annualize argument is now documented as inert, because it never affected the result. Thank you for the precise write-up.

ranaroussi avatar Sep 26 '26 08:09 ranaroussi