Setting up a professional Python trading environment
Isolate your project, install the core quant stack, pin it in a requirements.txt, and prove it all works with a one-file sanity check.
Before a single strategy, you need a workshop. In Python that means an isolated environment with a known set of libraries β so the code you write today still runs in six months, and so the version of pandas you tested against is the one that runs live. Skipping this step is the number-one reason a script that "worked yesterday" mysteriously breaks.
Create an isolated environment
Two tools dominate. venv ships with Python and is perfect for pure-Python work. conda (via Miniconda) is heavier but handles compiled scientific packages and non-Python dependencies more gracefully. For this course, venv is all you need.
# Make a project folder and step into it
mkdir algopro-lab && cd algopro-lab
# Create a virtual environment named ".venv"
python3 -m venv .venv
# Activate it (macOS / Linux)
source .venv/bin/activate
# On Windows PowerShell: .venv\Scripts\Activate.ps1
# Your prompt now shows (.venv) β you are isolated.
# Upgrade pip itself first; old pip causes half of all install errors.
python -m pip install --upgrade pipPrefer conda? The equivalent is conda create -n algopro python=3.11 then conda activate algopro. Either way the principle is identical: a named, throwaway sandbox you can delete and rebuild at will.
The core quant stack
You can build every strategy in this course from a small, stable set of libraries. Resist the urge to install fifty packages you saw in a blog post β each dependency is a future maintenance cost.
- numpy β fast numerical arrays and vectorised maths. The bedrock everything else sits on.
- pandas β labelled, time-indexed tables (
DataFrame). This is where price data lives. - matplotlib β plotting, so you can *see* your data instead of guessing.
- yfinance β free historical stock, ETF, FX and index data from Yahoo Finance.
- ccxt β a unified API to 100+ crypto exchanges for OHLCV and (later) live orders.
- jupyter β an interactive notebook for exploration; think of it as a lab bench, not production.
pip install numpy pandas matplotlib yfinance ccxt jupyterlab
# Freeze the EXACT versions you just got into a lockfile.
# This is what makes your work reproducible on any machine.
pip freeze > requirements.txtA sanity-check script
Never assume an install worked β prove it. This tiny script imports each library, prints its version, and pulls a handful of real bars. If it runs clean, your workshop is open for business.
import sys
def check():
import numpy as np
import pandas as pd
import matplotlib
import yfinance as yf
print(class="s">"Python :", sys.version.split()[class="n">0])
print(class="s">"numpy :", np.__version__)
print(class="s">"pandas :", pd.__version__)
print(class="s">"mpl :", matplotlib.__version__)
class="c"># Pull ~class="n">1 month of daily Apple bars as a live smoke test.
df = yf.download(class="s">"AAPL", period=class="s">"1mo", interval=class="s">"1d", progress=False)
assert not df.empty, class="s">"No data returned β check your connection."
print(fclass="s">"\nPulled {len(df)} daily bars for AAPL")
print(df.tail(class="n">3).round(class="n">2))
if __name__ == class="s">"__main__":
check()
print(class="s">"\nEnvironment OK")Run it with python check_env.py. Seeing three rows of Apple prices and "Environment OK" means numpy, pandas, matplotlib, and your internet-backed data source all work together. From here on, every lesson assumes this environment is active.