Expand description
Perpetual-futures funding cashflows for the replay engine.
Perp exchanges settle funding at fixed timestamps (KuCoin and Binance
USDT perps every 8 hours, on the 00:00 / 08:00 / 16:00 UTC grid). At
each settlement an open position pays or receives rate × notional:
a positive rate means longs pay shorts (a long’s cashflow is
negative, a short collects), a negative rate mirrors. A strategy that
holds across settlements — the platform’s funding-capture edge most of
all — has this cashflow as a first-order PnL term, so a backtest that
omits it overstates (or understates) the edge.
FundingModel plugs the settlement schedule into
BacktestConfig the same way
FeeModel / SlippageModel
do. It defaults to FundingModel::None — existing backtests are
bit-for-bit unchanged unless a model is configured.
§Settlement semantics (parity with the live paper ledger)
The live paper bot accrues funding over a hold as the settlements in
(entry, exit] — strictly after entry, up to and including exit — each
paying the position −direction × rate × notional. The replay engine
applies the same window per candle: settlements in
(previous_candle_time, candle_time] are booked against the position
as it stood entering the candle, at the last-known mark. A position
opened exactly on a settlement timestamp does not pay that settlement;
a position closed exactly on one does.
Enums§
- Funding
Model - Pluggable perp funding-rate schedule. Defaults to
Self::None.
Constants§
- EIGHT_
HOURS_ MS - Eight hours in milliseconds — the funding interval of KuCoin and Binance USDT perps (settling on the 00:00 / 08:00 / 16:00 UTC grid, which is exactly the epoch-aligned 8 h grid).