Portfolio is the account behind a backtest. It holds the open and closed trades, reprices them
each pulse, and tracks equity over time. Most of the time you read it through the strategy:
self.current_equity, self.pnl, self.trades, self.open_trades.
Equity
Equity starts atinitial_equity and moves by the net PnL of all trades, pulse by pulse:
portfolio.equity_history (one value per pulse). It is post-fee: any fees
charged on a pulse are already subtracted.
Three ways to read PnL
PnL comes in one dollar figure and two percentages. They differ only in the denominator, so pick the one that answers your question.
All three exist on
Strategy, on TradesSummary (a tagged group of trades), and on each Trade.
Per-trade percentages use a different base
Trade.pnl_pct is fixed to that trade’s equity at open (a snapshot from when it was booked),
so it answers “how did this trade do relative to the book when I put it on”. Strategy.pnl_pct
and TradesSummary.pnl_pct use the current equity. When you want one stable base everywhere,
use pnl_pct_of_initial_equity - it means the same thing on a trade, a group, and the strategy.Gross vs net
Two histories look similar but are not:equity_historyis net of fees - it is the money in the account.pulse_total_pnl_historyis gross of fees - the per-pulse market PnL before fees are taken out.
NoFeeCalculator, the two agree.
See Fees for how fees are charged and Metrics and Stats for how returns are
summarised.
Trades
self.trades is every trade; self.open_trades is the ones still on. Each Trade keeps its own
history (abs_pnl_history, delta_history, …) and carries the tags you gave it, which you can
use to query or close groups:

