Sharpe ratio inference
PortfolioOptimisers.probabilistic_sharpe_ratio — Function
probabilistic_sharpe_ratio(x::VecNum; bsr::Number = 0, rf::Number = 0)
probabilistic_sharpe_ratio(X::MatNum; bsr::Number = 0, rf::Number = 0)Compute the Probabilistic Sharpe Ratio, the probability that the true Sharpe ratio of a return series is greater than a benchmark.
The Probabilistic Sharpe Ratio of [289] corrects the sample Sharpe ratio for the length of the series and for the skewness and the kurtosis of its returns. Fat tails make a Sharpe ratio that is not zero less precise, and negative skewness makes a positive Sharpe ratio less precise. When the Sharpe ratio is above the benchmark, a less precise Sharpe ratio has a smaller probability. Every quantity is per period, so x, bsr and rf must have the same frequency, and the function annualises none of them. The matrix method computes one probability for each column.
Mathematical definition
\[\begin{align} \mathrm{PSR}\left(\mathrm{SR}^{*}\right) &= \Phi\left(\dfrac{\left(\widehat{\mathrm{SR}} - \mathrm{SR}^{*}\right) \sqrt{T - 1}}{\sqrt{1 - \hat{\gamma}_{3} \widehat{\mathrm{SR}} + \dfrac{\hat{\gamma}_{4} - 1}{4} \widehat{\mathrm{SR}}^{2}}}\right)\,. \end{align}\]
Where:
- $\mathrm{PSR}$: Probabilistic Sharpe Ratio.
- $\mathrm{SR}^{*}$: Benchmark Sharpe ratio per period.
- $\Phi$: Distribution function of the standard normal distribution, and $\Phi^{-1}$ its quantile function.
- $\widehat{\mathrm{SR}}$: Sample Sharpe ratio per period of $\boldsymbol{x}$, the excess of its sample mean over the risk-free rate
rfdivided by its corrected sample standard deviation. - $T$: Number of observations.
- $\hat{\gamma}_{3}$: Sample skewness of $\boldsymbol{x}$, its third central moment divided by the cube of its biased sample standard deviation.
- $\hat{\gamma}_{4}$: Sample kurtosis of $\boldsymbol{x}$, its fourth central moment divided by the square of its biased sample variance. It is $3$ for a normal distribution.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
The denominator is the square root of the variance factor of sharpe_ratio_variance_factor. A Sharpe ratio equal to the benchmark gives a probability of $1/2$.
Algorithm
- Check
bsrandrf, as# Validationstates. - Take
T,srandv, the number of observations, the sample Sharpe ratio and its variance factor, throughsharpe_ratio_moments. It drops theNaNentries ofx. - Multiply the excess
sr - bsrby the square root ofT - 1, and divide it by the square root ofv, to getz. - Evaluate the standard normal distribution function at
z. ANaNfrom step 2 gives aNaN.
Arguments
x: Periodic return series, or a matrix with one return series in each column. ANaNentry is an observation that is not available, and the function drops it.bsr: Benchmark Sharpe ratio per period, in the frequency ofx. It defaults to0.rf: Risk-free rate. It defaults to0, in the frequency ofx.
Validation
isfinite(bsr).isfinite(rf).
Returns
psr::Number: The probability, for a vectorx. It isNaNwhenxhas fewer than three entries that are notNaN, when its standard deviation is zero, or when its variance factor is not positive.psr::Vector: One probability for each column, for a matrixX.
Examples
julia> x = [0.012, -0.004, 0.007, 0.015, -0.011, 0.009, 0.003, -0.002, 0.011, 0.006];julia> round(probabilistic_sharpe_ratio(x); digits = 6)0.920149julia> round(probabilistic_sharpe_ratio(x; bsr = 0.2); digits = 6)0.818392Related
deflated_sharpe_ratiominimum_track_record_lengthsharpe_ratio_momentsperformance_summary: The standard error of its Sharpe ratio reads the same variance factor.
References
- [289] D. H. Bailey and M. Lopez de Prado. The Sharpe ratio efficient frontier. Journal of Risk 15, 3–44 (2012). Equation 11.
PortfolioOptimisers.minimum_track_record_length — Function
minimum_track_record_length(x::VecNum; bsr::Number = 0, rf::Number = 0,
alpha::Number = 0.05)
minimum_track_record_length(X::MatNum; bsr::Number = 0, rf::Number = 0,
alpha::Number = 0.05)Compute the Minimum Track Record Length, the number of observations that a return series needs for its Sharpe ratio to exceed a benchmark at a confidence level.
The Minimum Track Record Length of [289] is the least number of observations at which the probabilistic_sharpe_ratio of the series reaches 1 - alpha, for the sample moments of the series. It is a number of observations, not a number of years. The matrix method computes one length for each column.
Mathematical definition
\[\begin{align} \mathrm{MinTRL} &= 1 + \left(1 - \hat{\gamma}_{3} \widehat{\mathrm{SR}} + \dfrac{\hat{\gamma}_{4} - 1}{4} \widehat{\mathrm{SR}}^{2}\right) \left(\dfrac{\Phi^{-1}(1 - \alpha)}{\widehat{\mathrm{SR}} - \mathrm{SR}^{*}}\right)^{2}\,. \end{align}\]
Where:
- $\mathrm{MinTRL}$: Minimum Track Record Length, a number of observations.
- $\alpha$: Significance level, so $1 - \alpha$ is the confidence level.
- $\hat{\gamma}_{3}$: Sample skewness of $\boldsymbol{x}$, its third central moment divided by the cube of its biased sample standard deviation.
- $\widehat{\mathrm{SR}}$: Sample Sharpe ratio per period of $\boldsymbol{x}$, the excess of its sample mean over the risk-free rate
rfdivided by its corrected sample standard deviation. - $\hat{\gamma}_{4}$: Sample kurtosis of $\boldsymbol{x}$, its fourth central moment divided by the square of its biased sample variance. It is $3$ for a normal distribution.
- $\Phi$: Distribution function of the standard normal distribution, and $\Phi^{-1}$ its quantile function.
- $\mathrm{SR}^{*}$: Benchmark Sharpe ratio per period.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
The length solves $\mathrm{PSR}(\mathrm{SR}^{*}) = 1 - \alpha$ for $T$. When $\widehat{\mathrm{SR}} \leq \mathrm{SR}^{*}$, the Probabilistic Sharpe Ratio is at most $1/2$ for every $T$, so no length is enough and the length is $+\infty$.
Algorithm
- Check
alpha,bsrandrf, as# Validationstates. - Take
srandv, the sample Sharpe ratio and its variance factor, throughsharpe_ratio_moments. It drops theNaNentries ofx. - Take the excess
d = sr - bsr, andza, the quantile of the standard normal distribution at1 - alpha. - Add one to
vtimes the square ofza / d, to getn. - When
dis not positive andnis notNaN, replacenwithInf.
Arguments
x: Periodic return series, or a matrix with one return series in each column. ANaNentry is an observation that is not available, and the function drops it.bsr: Benchmark Sharpe ratio per period, in the frequency ofx. It defaults to0.rf: Risk-free rate. It defaults to0, in the frequency ofx.alpha: Significance level. It defaults to0.05, a confidence level of 95 %.
Validation
0 < alpha < 1/2. The quantile $\Phi^{-1}(1 - \alpha)$ is then positive, which the closed form needs.isfinite(bsr).isfinite(rf).
Returns
n::Number: The length, for a vectorx. It isInfwhen the sample Sharpe ratio does not exceedbsr. It isNaNin the cases whereprobabilistic_sharpe_ratioisNaN.n::Vector: One length for each column, for a matrixX.
Examples
julia> x = [0.012, -0.004, 0.007, 0.015, -0.011, 0.009, 0.003, -0.002, 0.011, 0.006];julia> round(minimum_track_record_length(x); digits = 6)13.316333julia> minimum_track_record_length(x; bsr = 1.0)InfRelated
References
- [289] D. H. Bailey and M. Lopez de Prado. The Sharpe ratio efficient frontier. Journal of Risk 15, 3–44 (2012). Equation 13.
PortfolioOptimisers.expected_max_sharpe_ratio — Function
expected_max_sharpe_ratio(N::Number, sigma::Number, mu::Number = 0)Approximate the expected maximum of the Sharpe ratios of N independent trials.
The best of several trials has a Sharpe ratio that the selection itself inflates. The approximation of [290] reads the trial Sharpe ratios as independent draws of one normal distribution. deflated_sharpe_ratio uses it at mu = 0 as the benchmark that the selected trial must exceed. Trials with similar parameters have correlated Sharpe ratios, and then implied_independent_trials gives a smaller N.
Mathematical definition
\[\begin{align} \mathbb{E}\left[\max_{n} \widehat{\mathrm{SR}}_{n}\right] &\approx \mu + \sigma \max\left(0,\, (1 - \gamma) \Phi^{-1}\left(1 - \dfrac{1}{N}\right) + \gamma \Phi^{-1}\left(1 - \dfrac{1}{N e}\right)\right)\,. \end{align}\]
Where:
- $\widehat{\mathrm{SR}}_{n}$: Sharpe ratio of trial $n$.
- $\mu$: Mean of the Sharpe ratios of the trials.
- $\sigma$: Dispersion of the Sharpe ratios of the trials, their standard deviation.
- $\gamma$: Euler-Mascheroni constant, about $0.5772$.
- $\Phi$: Distribution function of the standard normal distribution, and $\Phi^{-1}$ its quantile function.
- $N$: Number of independent trials of the search. It can be fractional, and it is at least one.
- $e$: Euler's number.
The maximum of $N \geq 1$ draws is at least one draw, so its expectation is at least $\mu$. The floor at zero keeps that bound. The source states the approximation for $N \gg 1$ and has no floor. Without the floor, the approximation falls below $\mu$ for $N < 1.2836$, and it is $-\infty$ at $N = 1$. For one trial, or for trials with no dispersion, the expected maximum is $\mu$.
Arguments
N: Number of independent trials. A fractional value is an effective number of trials.sigma: Standard deviation of the Sharpe ratios of the trials.mu: Mean of the Sharpe ratios of the trials.
Validation
isfinite(N)andN >= 1.isfinite(sigma)andsigma >= 0.isfinite(mu).
Returns
sr::Number: The approximate expected maximum Sharpe ratio, in the frequency ofsigmaandmu.
Examples
julia> round(expected_max_sharpe_ratio(100, 1.0); digits = 6)2.530603julia> expected_max_sharpe_ratio(1, 0.5, 0.2)0.2Related
References
- [290] D. H. Bailey and M. Lopez de Prado. The deflated Sharpe ratio: correcting for selection bias, backtest overfitting, and non-normality. The Journal of Portfolio Management 40, 94–107 (2014). Equation 1.
PortfolioOptimisers.deflated_sharpe_ratio — Function
deflated_sharpe_ratio(x::VecNum_MatNum, srs::VecNum; rf::Number = 0,
ntrials::Option{<:Number} = nothing)Compute the Deflated Sharpe Ratio, the probability that the true Sharpe ratio of the best of several trials is greater than zero.
The Deflated Sharpe Ratio of [290] is the probabilistic_sharpe_ratio of the selected trial against the expected_max_sharpe_ratio of the search. So it corrects for the number and the dispersion of the trials, and for the skewness and the kurtosis of the selected returns. The selected trial meets a confidence level of 95 % when the ratio is at least 0.95. Every quantity is per period, so srs must have the frequency of x and the same risk-free rate.
Mathematical definition
\[\begin{align} \mathrm{DSR} &= \mathrm{PSR}\left(\mathrm{SR}_{0}\right)\,,\\ \mathrm{SR}_{0} &= \sigma \max\left(0,\, (1 - \gamma) \Phi^{-1}\left(1 - \dfrac{1}{N}\right) + \gamma \Phi^{-1}\left(1 - \dfrac{1}{N e}\right)\right)\,. \end{align}\]
Where:
- $\mathrm{DSR}$: Deflated Sharpe Ratio.
- $\mathrm{PSR}$: Probabilistic Sharpe Ratio of the selected trial, as
probabilistic_sharpe_ratiostates it. - $\mathrm{SR}_{0}$: Expected maximum Sharpe ratio of $N$ trials whose true Sharpe ratios are zero, as
expected_max_sharpe_ratiostates it. - $\sigma$: Dispersion of the Sharpe ratios of the trials, their standard deviation. It is the corrected sample standard deviation of
srs. - $\gamma$: Euler-Mascheroni constant, about $0.5772$.
- $\Phi$: Distribution function of the standard normal distribution, and $\Phi^{-1}$ its quantile function.
- $N$: Number of independent trials of the search.
- $e$: Euler's number.
Algorithm
- Check
srs, as# Validationstates, and drop itsNaNentries. - Take
M, the number of entries that remain, andsigma, their corrected sample standard deviation. WhenM = 1,sigmais zero. - Take the number of trials
ntrials, orMwhen it isnothing, and compute the expected maximum Sharpe ratio at a zero mean withexpected_max_sharpe_ratio, to getbsr. - Compute the
probabilistic_sharpe_ratioofxagainstbsr.
Arguments
x: Periodic return series, or a matrix with one return series in each column. ANaNentry is an observation that is not available, and the function drops it. It holds the selected trial. Every column of a matrix meets the same benchmark.srs: Sharpe ratios per period of every trial of the search, the selected trial included. Their number and their dispersion set the benchmark.rf: Risk-free rate. It defaults to0, in the frequency ofx.ntrials: Number of independent trials. It defaults tonothing, which counts every entry ofsrsthat is notNaNas an independent trial. Correlated trials are fewer independent trials, andimplied_independent_trialsestimates their number.
Validation
- No entry of
srsis infinite. - At least one entry of
srsis notNaN. - The checks of
expected_max_sharpe_ratioonntrials, and the checks ofprobabilistic_sharpe_ratioonrf.
Returns
dsr::Number: The probability, for a vectorx. It isNaNin the cases whereprobabilistic_sharpe_ratioisNaN.dsr::Vector: One probability for each column, for a matrixx.
Examples
julia> x = [0.012, -0.004, 0.007, 0.015, -0.011, 0.009, 0.003, -0.002, 0.011, 0.006];julia> round(deflated_sharpe_ratio(x, [0.1, 0.3, 0.5, 0.2, 0.4]); digits = 6)0.82579Related
References
- [290] D. H. Bailey and M. Lopez de Prado. The deflated Sharpe ratio: correcting for selection bias, backtest overfitting, and non-normality. The Journal of Portfolio Management 40, 94–107 (2014). Equation 2.
PortfolioOptimisers.implied_independent_trials — Function
implied_independent_trials(M::Integer, rho::Number)
implied_independent_trials(C::MatNum)Estimate the number of independent trials among M trials whose returns have the mean correlation rho.
The estimate of [290] interpolates between one trial, when every pair of trials is perfectly correlated, and M trials, when no pair is correlated. Give the result as ntrials to deflated_sharpe_ratio. The matrix method reads M and rho from the correlation matrix C of the returns of the trials.
Mathematical definition
\[\begin{align} \hat{\rho} &= \dfrac{2}{M (M - 1)} \sum_{i=1}^{M} \sum_{j=i+1}^{M} \rho_{ij}\,,\\ \hat{N} &= \hat{\rho} + (1 - \hat{\rho}) M\,. \end{align}\]
Where:
- $\hat{N}$: Implied number of independent trials.
- $\hat{\rho}$: Mean correlation between the returns of two different trials.
- $M$: Number of trials.
- $\rho_{ij}$: Correlation between the returns of trials $i$ and $j$, entry $(i, j)$ of $\mathbf{C}$.
- $\mathbf{C}$: Correlation matrix of the returns of the trials, $M \times M$.
The source takes a correlation matrix that is positive definite, so $\boldsymbol{1}^{\intercal} \mathbf{C} \boldsymbol{1} = M + M (M - 1) \hat{\rho} > 0$ and $\hat{\rho} > -1/(M - 1)$. A singular correlation matrix can reach the bound, and the function refuses it. The estimate is $1$ at $\hat{\rho} = 1$ and $M$ at $\hat{\rho} = 0$.
Arguments
M: Number of trials.rho: Mean correlation between the returns of two different trials.C: Correlation matrix of the returns of the trials. The diagonal does not enter the mean.
Validation
M >= 1.rho <= 1, andrho > -1/(M - 1)whenM > 1.Cis square.
Returns
n::Number: The implied number of independent trials.
Examples
julia> implied_independent_trials(10, 0.25)7.75Related
References
- [290] D. H. Bailey and M. Lopez de Prado. The deflated Sharpe ratio: correcting for selection bias, backtest overfitting, and non-normality. The Journal of Portfolio Management 40, 94–107 (2014). Equations 8 and 9.
References
- [289]
- D. H. Bailey and M. Lopez de Prado. The Sharpe ratio efficient frontier. Journal of Risk 15, 3–44 (2012).
- [290]
- D. H. Bailey and M. Lopez de Prado. The deflated Sharpe ratio: correcting for selection bias, backtest overfitting, and non-normality. The Journal of Portfolio Management 40, 94–107 (2014).