graph LR
TradingAlgorithm["TradingAlgorithm"]
AlgorithmSimulator["AlgorithmSimulator"]
DataPortal["DataPortal"]
Blotter["Blotter"]
MetricsTracker["MetricsTracker"]
TradingAlgorithm -- "uses" --> DataPortal
TradingAlgorithm -- "places orders through" --> Blotter
AlgorithmSimulator -- "executes strategy logic of" --> TradingAlgorithm
AlgorithmSimulator -- "fetches data from" --> DataPortal
DataPortal -- "provides data to" --> AlgorithmSimulator
DataPortal -- "provides data to" --> TradingAlgorithm
Blotter -- "receives orders from" --> TradingAlgorithm
Blotter -- "updates" --> MetricsTracker
MetricsTracker -- "receives updates from" --> AlgorithmSimulator
MetricsTracker -- "receives trade data from" --> Blotter
click TradingAlgorithm href "https://github.com/CodeBoarding/GeneratedOnBoardings/blob/main//zipline/TradingAlgorithm.md" "Details"
click AlgorithmSimulator href "https://github.com/CodeBoarding/GeneratedOnBoardings/blob/main//zipline/AlgorithmSimulator.md" "Details"
click DataPortal href "https://github.com/CodeBoarding/GeneratedOnBoardings/blob/main//zipline/DataPortal.md" "Details"
click Blotter href "https://github.com/CodeBoarding/GeneratedOnBoardings/blob/main//zipline/Blotter.md" "Details"
click MetricsTracker href "https://github.com/CodeBoarding/GeneratedOnBoardings/blob/main//zipline/MetricsTracker.md" "Details"
The zipline backtesting engine is built around a few critical components that orchestrate the simulation of trading strategies against historical market data. These components work in concert to provide a realistic and robust environment for strategy development and evaluation.
The central user-defined component where the trading strategy logic is implemented. It defines how the algorithm reacts to market data, places orders, and manages its state. It's the "brain" of the backtest, encapsulating the user's investment thesis.
Related Classes/Methods:
zipline.finance.trading_algorithm.TradingAlgorithm(0:0)
The core execution engine that drives the backtest. It iterates through market data bar by bar, advances the simulation clock, and triggers the TradingAlgorithm's lifecycle methods (before_trading_start, handle_data). It's the "heartbeat" that orchestrates the entire simulation process.
Related Classes/Methods:
The unified interface for accessing all historical and current market data (prices, adjustments, dividends, splits) for various assets. It abstracts the underlying data storage mechanisms, providing a consistent and efficient way for other components to retrieve necessary financial information. It acts as the "memory" or "knowledge base" of the system.
Related Classes/Methods:
Manages the lifecycle of orders, from creation to execution. It applies financial models (like slippage and commission) to simulate realistic trade costs and updates the portfolio state based on executed trades. This component is the "action arm," translating theoretical orders into simulated market actions.
Related Classes/Methods:
Collects, aggregates, and calculates various financial performance metrics (e.g., PNL, returns, risk, portfolio value) throughout the simulation. It maintains the overall financial state of the portfolio and account, providing the essential "reporting and analysis" for evaluating strategy performance.
Related Classes/Methods: