Level 7 · Course 7.5
Backtesting in Python (optional)
0 of 15 lessons done
Join free to tick off each lesson as you go and get your certificate.
Module 1
Getting started
- Why use Python for testingWhat Python can do that a chart tester can't, and who it is worth the effort for.
- Setting up PythonInstall Python and a notebook, step by step.
- Python basics for tradersNumbers, lists and loops, using price examples.
- Loading price data with pandasReading a file of bars into a table.
- Where test data comes fromThe data you may use, its limits, and why bad data gives false results.
Module 2
Building a test
- Calculating indicatorsMoving averages and average true range in a few lines.
- Writing entry and exit rulesTurning your rules into a column of signals.
- Simulating trades with stops and targetsWalking through bars one at a time to see which level was hit first.
- Costs, tick values and contract sizeMaking the test match a futures contract.
- Avoiding look-ahead bugsShifting data so a signal can't use the bar it hasn't seen.
Module 3
Results and checks
- Results table and equity curveCalculating the numbers from Level 4 and plotting the curve.
- Splitting data into build and testKeeping some data hidden until the end.
- Walk-forward testing in codeMoving the test window forward and repeating.
- Shuffling trades to see the rangeRunning thousands of reorderings to see the range of results the same trades could give.
- Checking your code against a chartComparing a few trades with the chart by hand to catch mistakes.
Course quiz
10 questions on the whole course. Pick your answers, then check them. You pass with 80% or more.
1. You want to shuffle your trades 2,000 times. By hand each shuffle takes 3 minutes. About how many hours is that?
2. A daily file should cover 2 years, at about 261 weekdays a year. It has 300 rows. What does that tell you?
3. One close in your file reads 404.05, when the prices around it are near 4,000. What is the risk?
4. A bar has a high of 4,990 and a low of 4,975. The close before was 4,960. What is the true range?
5. Over six days the close is below, below, above, above, below, above its average. How many crosses up are there?
6. In the walk-forward loop, one bar touches both the stop and the target. What does the code count?
7. Long 1 MES at 5,000.00, out at 5,010.50. Fees are $1.50 and slippage is 1 tick each way, at $1.25 a tick. What is the net result?
8. A rule tested on random made-up prices shows a strong edge. What does that most likely point to?
9. A column of R results has 4 wins totaling 9R and 6 losses of 1R each. What is the expectancy?
10. Shuffled trades give a 5% point drawdown of −12R. One R is $250. How much is that in dollars?
0 of 10 answered.
Every lesson is free and open. Sign up free to save your progress
Next course
Trading futures carries risk. You can lose money.