mlfinlab.backtest_statistics.backtests

Implements the Haircut Sharpe Ratios and Profit Hurdles algorithms.

Module Contents

Classes

CampbellBacktesting

This class implements the Haircut Sharpe Ratios and Profit Hurdles algorithms described in the following paper:

class CampbellBacktesting(simulations=2000)

This class implements the Haircut Sharpe Ratios and Profit Hurdles algorithms described in the following paper: Campbell R. Harvey and Yan Liu, Backtesting, (Fall 2015). Journal of Portfolio Management, 2015; The code is based on the code provided by the authors of the paper.

The Haircut Sharpe Ratios algorithm lets the user adjust the observed Sharpe Ratios to take multiple testing into account and calculate the corresponding haircuts. The haircut is the percentage difference between the original Sharpe ratio and the new Sharpe ratio.

The Profit Hurdle algorithm lets the user calculate the required mean return for a strategy at a given level of significance, taking multiple testing into account.

haircut_sharpe_ratios(sampling_frequency, num_obs, sharpe_ratio, annualized, autocorr_adjusted, rho_a, num_mult_test, rho)

Calculates the adjusted Sharpe ratio due to testing multiplicity.

This algorithm lets the user calculate Sharpe ratio adjustments and the corresponding haircuts based on the key parameters of returns from the strategy. The adjustment methods are Bonferroni, Holm, BHY (Benjamini, Hochberg and Yekutieli) and the Average of them. The algorithm calculates adjusted p-value, adjusted Sharpe ratio and the haircut.

The haircut is the percentage difference between the original Sharpe ratio and the new Sharpe ratio.

Parameters:
  • sampling_frequency – (str) Sampling frequency [‘D’,’W’,’M’,’Q’,’A’] of returns.

  • num_obs – (int) Number of returns in the frequency specified in the previous step.

  • sharpe_ratio – (float) Sharpe ratio of the strategy. Either annualized or in the frequency specified in the previous step.

  • annualized – (bool) Flag if Sharpe ratio is annualized.

  • autocorr_adjusted – (bool) Flag if Sharpe ratio was adjusted for returns autocorrelation.

  • rho_a – (float) Autocorrelation coefficient of returns at the specified frequency (if the Sharpe ratio wasn’t corrected).

  • num_mult_test – (int) Number of other strategies tested (multiple tests).

  • rho – (float) Average correlation among returns of strategies tested.

Returns:

(np.array) Array with adjuted p-value, adjusted Sharpe ratio, and haircut as rows for Bonferroni, Holm, BHY and average adjustment as columns.

profit_hurdle(num_mult_test, num_obs, alpha_sig, vol_anu, rho)

Calculates the required mean monthly return for a strategy at a given level of significance.

This algorithm uses four adjustment methods - Bonferroni, Holm, BHY (Benjamini, Hochberg and Yekutieli) and the Average of them. The result is the Minimum Average Monthly Return for the strategy to be significant at a given significance level, taking into account multiple testing.

This function doesn’t allow for any autocorrelation in the strategy returns.

Parameters:
  • num_mult_test – (int) Number of tests in multiple testing allowed (number of other strategies tested).

  • num_obs – (int) Number of monthly observations for a strategy.

  • alpha_sig – (float) Significance level (e.g., 5%).

  • vol_anu – (float) Annual volatility of returns(e.g., 0.05 or 5%).

  • rho – (float) Average correlation among returns of strategies tested.

Returns:

(np.ndarray) Minimum Average Monthly Returns for [Independent tests, Bonferroni, Holm, BHY and Average for Multiple tests].