I include the Python Backtester in my latest book “The Ultimate Algorithmic Trading System Toolbox” book. A good tutorial on how to use it would be to program the Turtle Algorithm in three different parts. Here is part 1:
Entry Description: Buy on stop at highest high of last twenty days. Short on lowest low of last twenty days.
Exit Description: Exit long on stop at lowest low of last ten days. Exit short on highest high of past ten days.
Position Sizing: Risk 2% of simulated 100K account on each trade. Calculate market risk by utilizing the ten day ATR. Size(shares or contracts) = $2,000/ATR in dollars.
Python code to input into the backtester:
This snippet only contains the necessary code to use in the Python Backtester – it is not in its entirety.
This algorithm utilizes a fixed fractional approach to position sizing. Two percent or $2000 is allocated on each trade and perceived market risk is calculated by the ten-day average true range (ATR.) So if we risk $2000 and market risk is $1000 then 2 contracts are traded. In Part 2, I will introduce the N risk stop and the LAST TRADE LOSER Filter.