Class FuturesRollAlgo
java.lang.Object
com.quantfinlib.execution.FuturesRollAlgo
The futures roll: the trade every futures position must do and most
do badly. It moves 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]defaultMigration(int days) The classic S-curve overdaysroll days: slow start, concentrated middle, fully complete at the end — smoothstep3x² − 2x³sampled at each day's close.booleandone()longdueOnDay(int day) Contracts due onday(0-based): the migration target minus what has already rolled.voidonRolled(long contracts) Records rolled contracts (calendar-spread fills).longintrollDays()longrolled()
-
Constructor Details
-
FuturesRollAlgo
public FuturesRollAlgo(long positionContracts, double[] cumulativeMigration) - Parameters:
positionContracts- contracts to roll (positive; direction is the caller's ticket), > 0cumulativeMigration- 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 overdaysroll days: slow start, concentrated middle, fully complete at the end — smoothstep3x² − 2x³sampled at each day's close. -
dueOnDay
public long dueOnDay(int day) Contracts due onday(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()
-