Skip to content

0a1b/backtrader-momentum-strategy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

backtrader-momentum-strategy

Momentum Strategy implemented in Backtrader for newbies

I take it you are interested in stock trading and you don't just want to put you money in TQQQ but you want to use a more sound strategy. So did I and the one which is easy to understand and implement was Momentum strategy (Gary Antonnaci/Andreas F. Clenow). The returns generated by the strategy when used multiple years on the NASDAQ 100 stocks outperforms the index greatly depending on the parameters chosen. This holds true over most periods valdated by a walk forward analysis. Momentum mostly works well during Boom periods. One can have a glimpse of the returnss by checking out the heatmap of my profile picture. There you can see a heatmap over different parameter combinations with a peak performance of 8182% and a minimum of 1500%. This was calculated with a static set of stocks taken from the nasdaq 100 in 2009. It might be even higher when incorporating newly added stocks, but I am having trouble with the survivorship free coding.

Since it is based on Teddy Kokers Momentum Strategy as well as two Backtrader blog posts, I would like to express my thankfulness to Teddy Koker and the creator of Backtrader, Daniel Rodriguez!

Features:

  • momentum strategy tweaked with respect to
    • Rate of Change (relative increase in given time)
    • time interval of trading (weekly, monthly etc.)
    • trailing stop loss
    • change the number of stocks selected from the universe
    • excel output of all stock over time rankings
  • working pyfolio
  • fundatmental screening (revenue growth over x years or P/S / revenue growth (PSG)
  • working quantstat
  • working multiprocessing (works only in linux)
  • working heatmap which can depict different variable combinations & investment performance KPIs, both chosen by the user
  • working optunity implementation
  • working walk-forward-analysis to better get a sense of the degree of overoptimisation

disclaimer: All of the features have been working at one point of time... if I broke it in between, please leave a note.

In the beginning i didn't like to use it but some grafical features, i.e. pyfolio, only work within Jupyter so please do not give up here. I will add a series of versions and each of them works according to what I remeber. I think this might help to understand the features I added later on better.

Help needed: If someone manages to get this data to work: https://github.com/teddykoker/quant/tree/master/survivorship-free/data within the provided code, I would be super happy to know how. I haven't tried to add additional informaiton to the data so backtrader knows how long each symbol can be used, but hopefully there is an easier way. I tried to make it work in the "Sur" strategy, but failed big time.

Since sharing ist caring: Here the super lazy version 1.1: https://colab.research.google.com/drive/1agpdXHxUUeA-C0PQHY38BB_V2w1F5Wo9?usp=sharing One just has to copy it and set up the folder structure in ones google drive.

Update: Colab version fixed. Datareader fix with yFinance.

About

Momentum Strategy implemented in Backtrader for newbies

Resources

Stars

Watchers

Forks

Packages

No packages published