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.

@FunctionalInterface public interface TradeCostModel
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 legacy commissionRate configs);
  • institutional(double, double, double, int): commission + half-spread + slippage + square-root market impact, with per-symbol ADV/vol estimated from the trailing bars via MarketImpactModel.estimate(BarSeries, int, int). This is the same four-component decomposition alpha.AlphaBacktester charges, 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 Type
    Method
    Description
    double
    costBps(BarSeries series, int index, double notional)
    All-in one-way cost, in bps of traded notional, for trading notional (currency units, always positive) of series at bar index.
    flat(double bps)
    Fixed all-in bps per trade — commission-only, size-independent.
    institutional(double commissionBps, double halfSpreadBps, double slippageBps, int impactWindow)
    The institutional four-component model.
  • Method Details

    • costBps

      double costBps(BarSeries series, int index, double notional)
      All-in one-way cost, in bps of traded notional, for trading notional (currency units, always positive) of series at bar index.
    • flat

      static TradeCostModel flat(double bps)
      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 from the bars before the trade bar (MarketImpactModel.estimate(BarSeries, int, int)): bars up to impactWindow charge 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 side
      halfSpreadBps - half the quoted spread, paid on every trade
      slippageBps - fixed implementation noise
      impactWindow - trailing bars for ADV/vol estimation (>= 2)