Class AntiGamingJitter

java.lang.Object
com.quantfinlib.execution.AntiGamingJitter

public final class AntiGamingJitter extends Object
Anti-gaming randomization for schedule-driven algos — a TWAP that fires identical children on a metronome is a gift to anyone watching the tape: predators detect the clock in a handful of intervals and lean on every child. The counter-measure is controlled jitter that keeps the schedule on track while removing the pattern:
  • Size jitter — each child ±sizeFraction, with the differences redistributed so the total is preserved exactly (the parent must complete; anti-gaming never changes what gets done, only how recognizable it looks);
  • Time jitter — each firing time ±timeFraction of its own interval, monotonicity preserved (children never reorder) and end time never exceeded.

Deterministic per seed: replayable in backtests, auditable in production (compliance can reconstruct exactly why each child fired when it did). Research/warm lane. Relationship to TwapScheduler.scheduleRandomized(long, long, int, double, long): that method jitters TWAP slice sizes at construction. This class is the generic overlay; it jitters any existing child plan (VWAP, benchmark-executor, hand-built) and adds the time dimension the schedulers do not randomize.

  • Constructor Summary

    Constructors
    Constructor
    Description
    AntiGamingJitter(long seed, double sizeFraction, double timeFraction)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long[]
    jitterSizes(long[] childQty)
    Jitters child sizes ±sizeFraction, preserving the total exactly and never producing a negative child.
    long[]
    jitterTimes(long[] timesNanos, long startNanos)
    Jitters firing times within their intervals.

    Methods inherited from class Object

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

    • AntiGamingJitter

      public AntiGamingJitter(long seed, double sizeFraction, double timeFraction)
      Parameters:
      seed - deterministic seed (replayable, auditable)
      sizeFraction - max relative size perturbation, in [0, 0.5]
      timeFraction - max relative time perturbation within each interval, in [0, 0.5]
  • Method Details

    • jitterSizes

      public long[] jitterSizes(long[] childQty)
      Jitters child sizes ±sizeFraction, preserving the total exactly and never producing a negative child. Perturbations are paired (child i gives what child i+1 takes), so the completion curve wanders inside a one-child envelope of the original.
    • jitterTimes

      public long[] jitterTimes(long[] timesNanos, long startNanos)
      Jitters firing times within their intervals. Each time moves back by at most timeFraction of the gap to its original predecessor (or to startNanos) and forward by at most timeFraction of the gap to its original successor; the last time never moves forward. Both bounds come from the original schedule only, and each is also held below half its gap, so two neighbours can never meet: consecutive outputs stay at least g (1 - 2 timeFraction) - 1 nanoseconds apart, where g is their original gap. Strictly increasing, first time not before startNanos, last not after the original end.