Class FuturesRollAlgo

java.lang.Object
com.quantfinlib.execution.FuturesRollAlgo

public final class FuturesRollAlgo extends Object
The futures roll — the trade every futures position must do and most do badly: move from the expiring front contract to the back over the roll window, following the LIQUIDITY MIGRATION rather than fighting it. Rolling everything on day one pays wide back-month spreads; waiting for expiry pays the congestion of everyone else's last day. The algo tracks a migration curve — the cumulative fraction of open interest that has moved by each day — and rolls in step:
  target(day) = round(position · curve[day]);  due = target − rolled

The default curve is the classic roll S-shape (slow start, concentrated middle, complete before the final day's scramble). Each day's due quantity executes as a CALENDAR SPREAD — sell front / buy back for a long — which is exactly a SpreadExecutionAlgo with ratio 1 and the calendar spread's own legging cap. Deterministic, single-threaded, research/warm lane.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FuturesRollAlgo(long positionContracts, double[] cumulativeMigration)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    defaultMigration(int days)
    The classic S-curve over days roll days: slow start, concentrated middle, fully complete at the end — smoothstep 3x² − 2x³ sampled at each day's close.
    boolean
     
    long
    dueOnDay(int day)
    Contracts due on day (0-based): the migration target minus what has already rolled.
    void
    onRolled(long contracts)
    Records rolled contracts (calendar-spread fills).
    long
     
    int
     
    long
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FuturesRollAlgo

      public FuturesRollAlgo(long positionContracts, double[] cumulativeMigration)
      Parameters:
      positionContracts - contracts to roll (positive; direction is the caller's ticket), > 0
      cumulativeMigration - cumulative fraction migrated by end of each roll day: non-decreasing, in [0, 1] (a zero early entry = nothing due yet), final entry exactly 1
  • Method Details

    • defaultMigration

      public static double[] defaultMigration(int days)
      The classic S-curve over days roll days: slow start, concentrated middle, fully complete at the end — smoothstep 3x² − 2x³ sampled at each day's close.
    • dueOnDay

      public long dueOnDay(int day)
      Contracts due on day (0-based): the migration target minus what has already rolled. Falling behind earlier days simply makes later days' due larger — the roll always catches up to the curve.
    • onRolled

      public void onRolled(long contracts)
      Records rolled contracts (calendar-spread fills).
    • rolled

      public long rolled()
    • remaining

      public long remaining()
    • done

      public boolean done()
    • rollDays

      public int rollDays()