Skip to content
Wildflower
Join free
Backtesting in Python (optional)

Free Trading School · Level 7 · Course 7.5

Why use Python for testing

Lesson 1 of 15 in Backtesting in Python (optional)Module 1: Getting started

Advanced · Backtesting in Python

Why use Python for testing

Wildflower Trading School · Lesson 7.5.1.1

Wildflower

This course is optional. It's for people who want to write their own backtests in Python, a free programming language. You can skip it and still follow every other course in the Advanced level. By the end of this lesson, you'll know what Python can do that a chart's own tester can't. You'll also know what it costs to learn, and who it's worth the effort for.

1 of 9

What you'll learn

  • Compare three ways to test. Hand testing, a chart tester, or your own Python code.
  • Repeat the slow checks. Code reruns the Level 4 checks as often as you like.
  • Count the costs. Python takes time to learn, and its bugs can look like results.
  • Make your rules exact first. Code hides vague words, so sharpen them by hand.
  • Bring your own strategy. Code checks rules you already have. It won't find new ones.

Exercise

  1. Pick one check from Level 4 that you'd like to run more times than you could by hand.
  2. Then read your rules and mark any word that still needs judgement.
  3. If you find some, sharpen them by hand before coding.

Next: Setting up Python.

Quick check

  1. 1. What does Python let you do that's slow by hand?

  2. 2. Your rules still say 'enter when the move looks strong'. What's the better next step?

  3. 3. Why does this course end by checking code against a chart?

0 of 3 answered.

Finished this lesson?

Tick it off and keep your place

Make a free account and we'll remember where you are, so “Setting up Python” is waiting next time.

Read the full notes

lets you write your own and run the Level 4 checks thousands of times, but it costs time to learn, needs your own data, and its bugs look like results. It's worth it once your rules are exact.

  • This course is optional. It's for people who want to write their own in Python, a free programming language. Every other Advanced course works without it.
  • Three ways to run the same rules over past prices: by hand with and a log (Hand testing versus computer testing); a chart platform's own tester, such as TradingView's Strategy Tester running ; or your own Python code reading a file of prices.
  • What Python adds: the Level 4 checks run as often as you like (Walk-forward testing, Shuffling trade order); tests from files for any market you have data for; every assumption visible; every trade in a table you can question.
  • What it costs: time to learn; finding and checking your own data; bugs that look like results; no chart unless you check one yourself. Testing many versions still brings the many-tests problem.
  • Worth it when your rules are already exact (The two-person test) and you want checks your tester can't run easily. Not yet if rules still need judgement: code hides vagueness. Code tests rules; it doesn't find a strategy. More: Systematic vs discretionary trading.

Worked example

Made-up numbers

Shuffling by hand versus in code

Made-up numbers · 10,000 shuffles · 5 minutes each by hand

  1. 10,000 × 5 = 50,000 minutes
  2. 50,000 ÷ 60 = about 833 hours
  3. At an hour an evening, that's over two years of evenings.
  4. In Python, the same shuffles take a few seconds.

The code takes time to learn once; after that, the slow checks become quick.

Your turn

Drill

Made-up numbers · 2,000 shuffles · 6 minutes each by hand

Trading is risky. You can lose money. Test results are hypothetical, and a test can't tell you what will happen next. This lesson explains how testing works. It isn't advice.