Skip to content

finm-python-for-finance/assignment-5

Repository files navigation

Assignment 5 – Testing & CI in Financial Engineering

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.

Components

  • backtester/price_loader.py – In-memory store that returns synthetic pandas.Series prices for a single symbol.
  • backtester/strategy.pyMovingAverageStrategy produces 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 from t-1, trades at t, and records equity over time.

Project Structure

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

Setup

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.txt

Required packages:

  • pandas
  • numpy
  • pytest
  • coverage

Running Tests and Coverage

coverage run --source=backtester -m pytest -q
coverage report --fail-under=90
coverage html  # writes htmlcov/index.html

coverage.png captures a sample passing report. Add --maxfail=1 or -k filters as needed during development.

Continuous Integration

.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.

Notes

  • Tests use only deterministic synthetic data; no network or external API calls occur.
  • MovingAverageStrategy serves as the example strategy
  • Files remain pure ASCII to avoid encoding surprises on Windows-based grading environments.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages