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 rf divided 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

  1. Check bsr and rf, as # Validation states.
  2. Take T, sr and v, the number of observations, the sample Sharpe ratio and its variance factor, through sharpe_ratio_moments. It drops the NaN entries of x.
  3. Multiply the excess sr - bsr by the square root of T - 1, and divide it by the square root of v, to get z.
  4. Evaluate the standard normal distribution function at z. A NaN from step 2 gives a NaN.

Arguments

  • x: Periodic return series, or a matrix with one return series in each column. A NaN entry is an observation that is not available, and the function drops it.
  • bsr: Benchmark Sharpe ratio per period, in the frequency of x. It defaults to 0.
  • rf: Risk-free rate. It defaults to 0, in the frequency of x.

Validation

  • isfinite(bsr).
  • isfinite(rf).

Returns

  • psr::Number: The probability, for a vector x. It is NaN when x has fewer than three entries that are not NaN, when its standard deviation is zero, or when its variance factor is not positive.
  • psr::Vector: One probability for each column, for a matrix X.

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.818392

Related

References

  • [289] D. H. Bailey and M. Lopez de Prado. The Sharpe ratio efficient frontier. Journal of Risk 15, 3–44 (2012). Equation 11.
source
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 rf divided 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

  1. Check alpha, bsr and rf, as # Validation states.
  2. Take sr and v, the sample Sharpe ratio and its variance factor, through sharpe_ratio_moments. It drops the NaN entries of x.
  3. Take the excess d = sr - bsr, and za, the quantile of the standard normal distribution at 1 - alpha.
  4. Add one to v times the square of za / d, to get n.
  5. When d is not positive and n is not NaN, replace n with Inf.

Arguments

  • x: Periodic return series, or a matrix with one return series in each column. A NaN entry is an observation that is not available, and the function drops it.
  • bsr: Benchmark Sharpe ratio per period, in the frequency of x. It defaults to 0.
  • rf: Risk-free rate. It defaults to 0, in the frequency of x.
  • alpha: Significance level. It defaults to 0.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 vector x. It is Inf when the sample Sharpe ratio does not exceed bsr. It is NaN in the cases where probabilistic_sharpe_ratio is NaN.
  • n::Vector: One length for each column, for a matrix X.

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)Inf

Related

References

  • [289] D. H. Bailey and M. Lopez de Prado. The Sharpe ratio efficient frontier. Journal of Risk 15, 3–44 (2012). Equation 13.
source
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) and N >= 1.
  • isfinite(sigma) and sigma >= 0.
  • isfinite(mu).

Returns

  • sr::Number: The approximate expected maximum Sharpe ratio, in the frequency of sigma and mu.

Examples

julia> round(expected_max_sharpe_ratio(100, 1.0); digits = 6)2.530603julia> expected_max_sharpe_ratio(1, 0.5, 0.2)0.2

Related

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.
source
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_ratio states it.
  • $\mathrm{SR}_{0}$: Expected maximum Sharpe ratio of $N$ trials whose true Sharpe ratios are zero, as expected_max_sharpe_ratio states 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

  1. Check srs, as # Validation states, and drop its NaN entries.
  2. Take M, the number of entries that remain, and sigma, their corrected sample standard deviation. When M = 1, sigma is zero.
  3. Take the number of trials ntrials, or M when it is nothing, and compute the expected maximum Sharpe ratio at a zero mean with expected_max_sharpe_ratio, to get bsr.
  4. Compute the probabilistic_sharpe_ratio of x against bsr.

Arguments

  • x: Periodic return series, or a matrix with one return series in each column. A NaN entry 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 to 0, in the frequency of x.
  • ntrials: Number of independent trials. It defaults to nothing, which counts every entry of srs that is not NaN as an independent trial. Correlated trials are fewer independent trials, and implied_independent_trials estimates their number.

Validation

Returns

  • dsr::Number: The probability, for a vector x. It is NaN in the cases where probabilistic_sharpe_ratio is NaN.
  • dsr::Vector: One probability for each column, for a matrix x.

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.82579

Related

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.
source
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, and rho > -1/(M - 1) when M > 1.
  • C is square.

Returns

  • n::Number: The implied number of independent trials.

Examples

julia> implied_independent_trials(10, 0.25)7.75

Related

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.
source

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).