Interface TradeCostModel
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A pluggable per-trade cost model — the ONE definition of "what a trade
costs" shared by the backtest engines, so an execution-aware number and a
survivorship-aware number can come out of the same run:
flat(double)— a fixed all-in bps (the classic commission assumption, and the exact equivalent of the legacycommissionRateconfigs);institutional(double, double, double, int)— commission + half-spread + slippage + square-root market impact, with per-symbol ADV/vol estimated from the trailing bars viaMarketImpactModel.estimate(com.quantfinlib.core.BarSeries, int, int). This is the same four-component decompositionalpha.AlphaBacktestercharges, expressed at the shared seam — the impact term is what makes cost grow with book size, i.e. what turns "capacity" into a number.
The contract prices ONE side of a trade (a buy or a sell), all-in, in basis points of traded notional. Implementations must be pure functions of their arguments — engines may call them at any bar in any order.
-
Method Summary
Modifier and TypeMethodDescriptiondoubleAll-in one-way cost, in bps of traded notional, for tradingnotional(currency units, always positive) ofseriesat barindex.static TradeCostModelflat(double bps) Fixed all-in bps per trade — commission-only, size-independent.static TradeCostModelinstitutional(double commissionBps, double halfSpreadBps, double slippageBps, int impactWindow) The institutional four-component model.
-
Method Details
-
costBps
All-in one-way cost, in bps of traded notional, for tradingnotional(currency units, always positive) ofseriesat barindex. -
flat
Fixed all-in bps per trade — commission-only, size-independent. -
institutional
static TradeCostModel institutional(double commissionBps, double halfSpreadBps, double slippageBps, int impactWindow) The institutional four-component model. Impact needs trailing ADV/vol: bars beforeimpactWindowcharge the flat components only (rather than reading before bar 0), as do series without volume data — documented degradation, never a crash.- Parameters:
commissionBps- commission per sidehalfSpreadBps- half the quoted spread, paid on every tradeslippageBps- fixed implementation noiseimpactWindow- trailing bars for ADV/vol estimation (>= 2)
-