Key Features
- Trade Management: Keeps track of both open and closed trades
- PnL Calculation: Continuously monitors your absolute profit and loss
- Equity Tracking: Records your complete equity history throughout the backtest
- Position Management: Automatically handles opening and closing trades
Creating a Portfolio
A portfolio is initialized with an initial equity amount. This represents your starting capital for the backtesting simulation:Output
Adding Trades to Portfolio
When trades are executed (usually by the broker), they need to be added to the portfolio for tracking. The portfolio will initialize trade statistics and begin monitoring their performance:Output
Portfolio Tracking Over Time
The portfolio tracks performance by pulsing through time, updating trade values and calculating PnL at each timestamp:Output
Per-pulse vs daily PnL
portfolio.pulse_total_pnl is the PnL delta since the previous pulse, and portfolio.pulse_total_pnl_history has one entry per pulse (length matches portfolio.datetimes).
For intraday cadence, pulses share calendar dates. portfolio.daily_total_pnl_history aggregates the per-pulse values into one entry per unique date (sum of pulses), and portfolio.daily_datetimes lists those dates. For daily-cadence runs the two histories are numerically identical and an internal fast-path skips aggregation.
Closing Trades
The portfolio can close all trades, but they are tagged to be closed after the current pulse to ensure daily PnL updates are properly recorded. When trades are closed, they’re removed from the open trades list but remain in the total trades history:Output
Portfolio History and Analysis
The portfolio maintains complete historical records that can be used for performance analysis:Output
Stats component that computes all of the main metrics.
