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

Free Trading School · Level 7 · Course 7.5

Setting up Python

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

Advanced · Backtesting in Python

Setting up Python

Wildflower Trading School · Lesson 7.5.1.2

Wildflower

Before any testing, you need the tools on your computer. By the end of this lesson, you'll have Python and the three add-ons this course uses installed. You'll have a notebook open, with your first lines of code run. And you'll know what to try when a step looks different on your screen.

1 of 9

What you'll learn

  • Install Python. Get it free from python.org, then check it with python --version.
  • Add the tools. Use python -m pip to install the notebook, pandas and matplotlib.
  • Start a notebook. Type jupyter notebook and keep the terminal open.
  • Run your first cell. Press Shift and Enter, and the result shows underneath.
  • Fix common snags. Open a new terminal, and install with python -m pip.

Exercise

  1. Install Python, the notebook, pandas and matplotlib.
  2. Open a notebook, run print("Hello, markets") and 5000.25 + 0.25, then save it from the File menu, under a name like python-practice.

Next: Python basics for traders.

Quick check

  1. 1. Why install libraries with python -m pip?

  2. 2. What does Shift and Enter do in a notebook?

  3. 3. Why keep the terminal open while you work?

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 “Python basics for traders” is waiting next time.

Read the full notes

Install from python.org, add the notebook, and matplotlib with python -m pip, start , and run your first cell with Shift and Enter.

  • Four pieces: (the language, free from python.org); (a page in your browser, running on your computer, where you type code and see the result under it); (a library for tables of prices); matplotlib (a library for charts).
  • 1. At python.org, Downloads: on Windows, Download Python install manager, then open it and choose Install; on a Mac, the installer named after the latest version.
  • 2. Open a and type python --version (Mac: python3). The first time on Windows, the install manager fetches the latest Python first and may offer to add a folder to your PATH; the Python docs call that optional.
  • 3. python -m pip install notebook pandas matplotlib. The -m pip part installs into the same Python you just checked.
  • 4. jupyter notebook (or python -m notebook). Your browser opens a page from your own computer (localhost). Click New, then Notebook; if asked for a kernel, choose Python 3. Keep the terminal open.
  • 5. Type in a cell and press Shift and Enter to run it. A notebook shows the last line's answer even without print. Snags: open a new terminal; install with python -m pip; other routes include Anaconda, VS Code and online notebooks (check your data's terms first).

Worked example

Made-up numbers

Your first two cells

Made-up price · one on a contract is 0.25

  1. print("Hello, markets") shows Hello, markets.
  2. 5000.25 + 0.25 shows 5000.5.
  3. Python drops the zero at the end: 5000.50 and 5000.5 are the same number.

Shift and Enter runs a cell and shows the result underneath.

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.