This repository contains a daily-bar backtesting framework for Assignment 5. Our focus is on disciplined engineering practices: isolated components, fast deterministic tests, high coverage, and continuous integration.
backtester/price_loader.py– In-memory store that returns syntheticpandas.Seriesprices for a single symbol.backtester/strategy.py–MovingAverageStrategyproduces long/flat/short signals via configurable short- and long-window moving averages.backtester/broker.py– Executes market orders, enforces validation rules, and exposes current equity.backtester/engine.py– Runs the end-of-day loop that reads the signal fromt-1, trades att, and records equity over time.
assignment-5/
├── backtester/
│ ├── broker.py
│ ├── engine.py
│ ├── price_loader.py
│ └── strategy.py
├── tests/
│ ├── conftest.py
│ ├── test_broker.py
│ ├── test_engine.py
│ ├── test_price_loader.py
│ └── test_strategy.py
├── .github/workflows/ci.yml
├── requirements.txt
└── README.md
Install the Python dependencies (tested with Python 3.11):
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # macOS/Linux
pip install -r requirements.txtRequired packages:
- pandas
- numpy
- pytest
- coverage
coverage run --source=backtester -m pytest -q
coverage report --fail-under=90
coverage html # writes htmlcov/index.htmlcoverage.png captures a sample passing report. Add --maxfail=1 or -k filters as needed during development.
.github/workflows/ci.yml provisions Python 3.11 on Ubuntu, installs dependencies, executes the pytest suite under coverage, and fails the workflow if line coverage falls below 90%. The suite completes in well under the 60-second requirement on GitHub-hosted runners.
- Tests use only deterministic synthetic data; no network or external API calls occur.
MovingAverageStrategyserves as the example strategy- Files remain pure ASCII to avoid encoding surprises on Windows-based grading environments.