Skip to main content
When the built-in calculators do not match a venue, subclass FeeCalculator and implement one method. The mechanics (per-pulse batch, three event types, how fees net against equity) are covered in Fees; this page is the applied recipe.

The contract

A calculator implements a single method:
It receives every fee-bearing event collected during the pulse and must return one non-negative fee per event, in the same order and length. Each FeeEvent is a frozen dataclass with four fields:

A minimum-floor calculator

A common venue rule is “a percentage of notional, but never less than a fixed floor per transaction”.

Per-event-type fees

The event_type lets you charge entries, rebalances, and exits differently; for example a flat fee on entry and exit while waiving rebalances:
Return one fee per event, in orderThe portfolio sums the returned list positionally and nets it against equity. Returning a list of a different length, or reordering it, breaks the alignment. Use the datafeed argument when a scheme needs contract metadata or a market lookup.

Inject it

The calculator plugs in at any of three points, exactly like the built-ins:

Read the results back

After the run the fee totals are on the portfolio and in Stats:
strategy.stats.fee_stats is a FeeStats with total_fees, fee_drag_pct, avg_fee_per_trade, fees_pct_of_gross_pnl, max_pulse_fees, and max_pulse_fees_datetime. See Fees for the per-pulse history and the impact charts. Related: Fees · Fees notebook · Metrics and Stats
Last modified on November 4, 2026