How pmorissette/bt works
Project Type and Purpose
• bt is a Python library/framework for flexible backtesting of quantitative trading strategies.
• It is not a full‐stack web app but a modular, reusable codebase that lets users define, run, and analyze backtests using Algos, AlgoStacks, and Node trees.
File Structure Analysis
Top-level directories and files:
• bt/ ← core package
– core.py ← Strategy, Node, AlgoStack definitions
– algos.py ← prebuilt algorithm components
– backtest.py ← Backtest runner and Result objects
– __init__.py ← package exports
• tests/ ← unit and regression tests
• examples/ ← runnable examples (.py, .ipynb)
• docs/ ← Sphinx documentation, themes, notebooks
• CI config (.github/) ← build, deploy, regression workflows
• setup.py, pyproject.toml, Makefile ← build & development setup
Key Architectural Concepts from README
– Tree Structure: hierarchies of Nodes, each with its own price index
– Algorithm Stacks: modular Algo components that can be composed
– Backtest Engine: orchestrates data, executes Algos, builds Results
– Charting/Reporting: post-run visualization functions
Main Components
A. User Layer
• User Code / Example Notebooks
• Strategy Definitions (Algo stacks, Node trees)
B. bt API Layer
• bt.core
– Node & Tree
– Algo & AlgoStack
• bt.algos (prebuilt logic blocks)
• bt.backtest.Backtest & Result
C. Data Layer
• Data Ingestion (pandas, ffn)
• Price Indices per Node
D. Execution Engine
• Backtest runner: iterates over time, invokes Algos on Nodes
E. Output Layer
• Results object: statistics, metrics
• Charting module: plotting functions
F. External Dependencies
• numpy, pandas, ffn
• Matplotlib or other plotting libs
G. Supporting Infrastructure
• Tests (pytest)
• Documentation (Sphinx)
• CI/CD (.github workflows)
Relationships and Data Flows
• From bt API to Data Layer (request price data).
• From Data Layer into Execution Engine (feed time‐series data to Algos).
• Execution Engine updates Node states and produces Results.
• Results flow into Charting/Reporting modules for visualization back to User.
• Tests verify each module; CI automates build, test, deploy.
Architectural Patterns and Principles
– Modular composition: Algos and AlgoStacks as pluggable strategy blocks
– Tree/hierarchical processing: each Node processes its AlgoStack
– Layered design: clear separation between API, engine, data, and output