Interface ExecutionModel

All Known Implementing Classes:
IcebergExecution, InstantExecution, LastLookExecution, SorExecution

public interface ExecutionModel
How parent orders turn into fills in an execution-aware backtest (ExecutionAwareBacktester). The engine calls execute(com.quantfinlib.orderbook.Side, long, com.quantfinlib.core.BarSeries, int) once per bar while a parent order is working; anything not filled carries over to the next bar.

Returned fill prices are all-in (fees and spread folded in), so the engine's cash accounting is simply price × quantity.

  • Method Summary

    Modifier and Type
    Method
    Description
    execute(Side side, long requestedQty, BarSeries series, int index)
    Executes up to requestedQty on this bar.
    default void
    onParentOrder(Side side, long totalQuantity, int signalIndex)
    Notification that a new parent order has been created (entry or exit).
    default double
    referencePrice(BarSeries series, int index)
    The price this model's fills are anchored to on the given bar — the engine budgets entry requests as cash / (referencePrice * (1 + worstCaseCostFraction())).
    default double
    Upper bound on this model's all-in cost as a fraction of referencePrice(com.quantfinlib.core.BarSeries, int) (spread + fees + slippage).
  • Method Details

    • onParentOrder

      default void onParentOrder(Side side, long totalQuantity, int signalIndex)
      Notification that a new parent order has been created (entry or exit). Stateful models (e.g. IcebergExecution) reset per-parent state here.
    • execute

      List<Execution> execute(Side side, long requestedQty, BarSeries series, int index)
      Executes up to requestedQty on this bar. Must never fill more than requested; may fill less (or nothing) — the remainder is retried on subsequent bars.
    • referencePrice

      default double referencePrice(BarSeries series, int index)
      The price this model's fills are anchored to on the given bar — the engine budgets entry requests as cash / (referencePrice * (1 + worstCaseCostFraction())). Default: the bar close. A model that fills off a different price point (e.g. LastLookExecution fills at the OPEN) must override this, or a gap between close and its actual anchor lets a fully-filled request overdraw cash.
    • worstCaseCostFraction

      default double worstCaseCostFraction()
      Upper bound on this model's all-in cost as a fraction of referencePrice(com.quantfinlib.core.BarSeries, int) (spread + fees + slippage). The engine uses it to size entries so that a fully-filled parent can never overdraw cash — a model whose fills can cost more than referencePrice * (1 + worstCaseCostFraction()) MUST override one or both methods, or the backtest silently trades on margin it doesn't have. Wrappers must DELEGATE both to the model that actually prices the fills. Default 1%.