Skip to main content

Portfolio

The book of a backtest: its trades, open positions, per-pulse PnL, equity curve and fees. init_stats seeds the history lists and must run before the first pulse, which marks the open trades, queues their fee events, closes what is due and nets the pulse’s fees against equity. The portfolio keeps no greek aggregate: book exposure is the sum of Trade.delta_contract over open_trades, computed where it is needed. Parameters Attributes

Portfolio.trades

property
Get the list of all trades in the portfolio. Returns

Portfolio.open_trades

property
Get the list of open trades in the portfolio. Returns

Portfolio.pulse_total_pnl

property
Get the per-pulse total profit and loss (PnL) of the portfolio. Sum of pulse_abs_pnl across all open trades for the most recent pulse. Returns

Portfolio.pulse_total_pnl_history

property
Get the history of per-pulse total PnL of the portfolio. Length matches datetimes (one entry per pulse). Returns

Portfolio.daily_datetimes

property
Unique calendar dates the portfolio has been pulsed, in chronological order.

Portfolio.daily_total_pnl_history

property
Per-calendar-date total PnL (sum of per-pulse values within each date). Returns

Portfolio.equity_history

property
Get the history of equity values of the portfolio. Returns

Portfolio.datetimes

property
Get the list of datetimes for which the portfolio has been updated. Returns

Portfolio.current_equity

property
Get the current equity of the portfolio. Returns

Portfolio.initial_equity

property
Get the portfolio’s starting capital (a stable sizing denominator). Returns

Portfolio.equity_pct_change

property
Get the percentage change in equity since the last update. Returns

Portfolio.equity_pct_change_history

property
Get the history of percentage changes in equity. Returns

Portfolio.pulse_fees

property
Total fees charged on the most recent pulse (entry + rebalance + exit). Read off the history rather than off an accumulator: pulse() used to zero the accumulator on its way out, so this could only ever answer 0.0 however much was charged.

Portfolio.pulse_fees_history

property
Per-pulse fees. Length matches datetimes (one entry per pulse).

Portfolio.total_fees

property
Cumulative fees charged since init_stats.

Portfolio.init_stats

Initialize the portfolio with the given pulse index and initial equity.

Portfolio.add_trade

Add a trade to the portfolio and initialize its statistics. Parameters

Portfolio.pulse

Pulse the portfolio to update all open trades and calculate the current equity. Parameters

Portfolio.close_all

Sets a flag to close all trades after the pulse.

Portfolio.__charge_exit_fee

Queue an exit event for a freshly-closed trade. trade._close_price is guaranteed to be set by _instant_trade_close immediately prior. The event is drained alongside entries/rebalances at end of pulse().

Portfolio.__close_trades

Close all trades that have set flag _close_on_pulse_end. Parameters
Last modified on November 4, 2026