Skip to content

replacementAI/A-Backtest-A-Day

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Backtest A Day

Everyday I will backtest a different quant strategy for the markets!

Types of Strategies

Best Long Only vs Long/Short Backtested Strategies

Best Sector Rotation Strategies

image

Best Precious Metal Strategies

image

Best Agriculture Commodity Strategies

image

Methodology

The main metric I will be using to measure a strategy is the sharpe ratio. What is the sharpe ratio?

Sharpe Ratio

The sharpe ratio is the average return of a strategy divided by its risk. Meaning if a strategy has high returns, and low risk, then it will have a high sharpe ratio. Why this metric and not total profit? Because total profit only keeps track of returns of a strategy, not risk, while sharpe ratio is calculated with both, allowing you to sleep better at night, instead of wondering if you are going to make 100% or lose 100% tomorrow.

How to use strategy yourself

  1. Either download the notebook or copy the code into a Python script
  2. Remove the end date parameter from yf.download()
  3. Print the last row of weighted_signal using print(weighted_signal.iloc[-1]) (I will update the notebooks to already have this)
  4. Go long the positive weights and (if the strategy is L/S,) short the negative weights

Other

First I will the evaluate the sharpe of each lookback of a strategy in a 5-fold cross validation to determine the best* parameters, then I will plot the cumulative return of the lookback with the highest sharpe. These backtests DO NOT take fees/slippage into account, in my opinion this isnt a problem for the long-only strategies, but needs to be considered for long/short strategies.

Abbreviations

  • TS = Time Series
  • L\S = Long Short
  • XS = Cross Sectional
  • Vol = Volatility
  • MOM = Momentum
  • STR = Short-term Reversal

Credits

Code was provided by @quant_arb on Twitter, I added the cross-validation to try to better pick parameters.