Setting Up a Research Environment: Python, Virtual Environments, Jupyter and VS Code
Install Python, create an isolated project environment, add pandas, numpy and matplotlib, and run your first notebook calculation.
What you will learn
- Which Python version to install in 2026 and why "one version behind the newest" is usually the safer choice.
- How to create a virtual environment so that each trading project has its own, reproducible set of packages.
- How to install pandas, numpy, matplotlib and Jupyter, and how to pin versions in a
requirements.txtfile. - How to organise a research folder so that data, notebooks and reusable code do not get mixed up.
Explanation
Python is a general-purpose programming language that has become the standard tool for quantitative research in finance because of its data libraries. The Systematic Trading & Backtesting course tested a rule in a spreadsheet; this course moves the same ideas into code.
Which version? As of late 2026 the newest Python series is 3.15, and pandas 3.0 (released January 2026) requires Python 3.11 or newer. A practical rule: install the latest version that is at least a few months old, because brand-new releases sometimes lack pre-built packages ("wheels") for scientific libraries. Always check the current download page, and on Windows tick "Add python to PATH" during installation. Verify with python --version in a terminal (on macOS and Linux you may need python3).
Virtual environments. A virtual environment (venv) is a private folder that holds its own copy of the Python packages for one project. Without it, upgrading pandas for project A can silently break project B. The built-in module creates one:
python -m venv .venv
Activate it with .venv\Scripts\activate (Windows) or source .venv/bin/activate (macOS/Linux). The prompt then shows (.venv), and from now on pip installs into this folder only. The pip tool is Python's package installer; PyPI (the Python Package Index) is the public repository it downloads from.
The core libraries. numpy provides fast numerical arrays; pandas builds labelled tables (DataFrames) on top of numpy and is the workhorse of this course; matplotlib draws charts; Jupyter gives you notebooks, documents that mix code, output and notes. Install them in one line:
pip install pandas numpy matplotlib jupyterlab pyarrow
The pyarrow package is optional but recommended by the pandas team because pandas 3.0 uses it for its new default string type and for faster file reading.
Reproducibility. After installing, run pip freeze > requirements.txt. The file lists exact versions, for example pandas==3.0.1. Later, pip install -r requirements.txt recreates the identical environment, so a backtest from today produces the same numbers; a result you cannot reproduce is not a result.
Notebook or script? Jupyter notebooks (started with jupyter lab) are ideal for exploration because each cell runs separately and shows its output. VS Code (Visual Studio Code, a free editor) opens the same .ipynb notebooks and plain .py scripts, offers a debugger and shows errors as you type. Select the interpreter inside .venv in VS Code, otherwise your imports will fail with "No module named pandas" even though you installed it.
A folder layout that scales:
data/raw/for downloaded files you never edit by hand,data/processed/for cleaned versions.notebooks/for exploration, numbered (01_load.ipynb,02_returns.ipynb).src/for reusable functions (indicators, metrics),tests/for the unit tests you will write in lesson 9.requirements.txtand a.gitignorethat excludes.venv/, large data files and any file holding API keys.
Worked example
Hypothetical example: a first notebook cell that replaces a position-size calculation you may have done by hand in the Risk & Trade Management course. Assumptions: account €10,000, risk 1% per trade, entry €50.00, stop €47.00. Fees, spread and slippage are ignored.
account = 10_000
risk_pct = 0.01
entry, stop = 50.0, 47.0
risk_eur = account * risk_pct
per_share = entry - stop
shares = int(risk_eur // per_share)
print(shares, shares * entry, shares * per_share)
Step by step: risk in euros = 10,000 × 0.01 = €100. Risk per share = 50 − 47 = €3. Shares = 100 ÷ 3 = 33.3, and the floor-division operator // rounds down to 33 (rounding up would exceed the risk budget). Position value = 33 × €50 = €1,650. Actual planned risk = 33 × €3 = €99. The output is 33 1650.0 99.0.
The underscore in 10_000 is only a readability aid. And planned risk is not maximum loss: a gap through the stop can lose more than €99.
Common mistake
pip install without an activated environment, sometimes with administrator rights. Months later two projects need different pandas versions, an upgrade breaks old notebooks, and nobody knows which versions produced last year's backtest. Create one .venv per project, commit requirements.txt, and never install into the system Python.Practice activity
On paper, write the exact sequence of terminal commands to: create a project folder called momentum_research, create and activate a virtual environment inside it, install pandas, numpy, matplotlib and JupyterLab, save the versions, and start JupyterLab. Then state what python -c "import pandas; print(pandas.__version__)" should print if the installation worked.
Show solution
mkdir momentum_researchthencd momentum_researchpython -m venv .venvsource .venv/bin/activate(macOS/Linux) or.venv\Scripts\activate(Windows)pip install pandas numpy matplotlib jupyterlabpip freeze > requirements.txtjupyter lab
The check command prints a version string such as 3.0.1 (your exact number depends on the release current when you install).
Limitations: company laptops and some Linux distributions restrict installation paths; if python is not found, use python3 or the full path shown by your installer.
Key takeaways
- Use a recent but not brand-new Python 3 release; pandas 3.0 needs Python 3.11 or newer.
- One virtual environment per project plus a pinned
requirements.txtmakes every backtest reproducible. - pandas, numpy, matplotlib and Jupyter are the four tools this course relies on; VS Code ties notebooks and scripts together.
- Separate raw data, processed data, notebooks and reusable code from the first day.
Next step
Lesson 2 covers the small amount of core Python you need before touching pandas: data types, lists, dictionaries, loops, functions and how to read an error message.
Self-check
Answer the questions, then check your answers. You can retry as often as you like.
Automatic self-check for your own revision. Your answers are checked in your browser and are not seen or assessed by us. It is not an exam and not a qualification.
Your progress
“Complete” only means you marked the lesson as done. It is not a test of your understanding. Progress and notes are saved only in this browser on this device — not in an account.