Class TickBacktester
java.lang.Object
com.quantfinlib.backtest.tick.TickBacktester
- All Implemented Interfaces:
TickTradingContext,TickFileReader.ReplayHandler
public final class TickBacktester
extends Object
implements TickFileReader.ReplayHandler, TickTradingContext
Event-driven tick-level backtester: replays a captured QFLT tick file
through a
TickStrategy with microstructure-aware fills — the level
below the bar-based engines, where queue position decides whether your
passive order actually trades.
Fill model (trade-print data, no book snapshots):
- Market orders fill instantly at the last trade price ± half the configured spread — the aggressor pays the spread.
- Limit orders fill fully when a print trades through the
limit price. Prints at the limit price accumulate: the order
starts behind
defaultQueueAheadsimulated resting quantity and fills (partially) only as traded volume works that queue off — passive fills must be earned, not assumed. - Orders placed while handling a tick are eligible from the next tick, never against the print that triggered them.
Equity is sampled every equitySampleEvery ticks; metrics are
computed on that sampled curve with periodsPerYear left at the
bar-engine default, so compare Sharpe-style numbers only between runs with
the same sampling interval.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordtickSize > 0snaps limit-order matching to the exchange price grid (prices within the same tick are one level); 0 falls back to epsilon equality — use a real tick size with real market data.static final record -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(long orderId) Cancels a working limit order.doublecash()doublelastPrice(int symbolId) Last traded price for the symbol (NaN before its first tick).voidvoidonTick(int symbolId, double price, double size, long timestampNanos) longposition(int symbolId) run(TickStrategy strategy, Path tickFile, TickBacktester.Config config) Replays the tick file through the strategy and returns the result.longsubmitLimit(int symbolId, Side side, double price, long quantity) Places a passive limit order.longsubmitMarket(int symbolId, Side side, long quantity) Immediate execution at the last trade price plus half the configured spread (aggressor pays the spread).symbolName(int symbolId) Symbol name for an id from the tick file.
-
Method Details
-
run
public static TickBacktester.TickBacktestResult run(TickStrategy strategy, Path tickFile, TickBacktester.Config config) throws IOException Replays the tick file through the strategy and returns the result.- Throws:
IOException
-
onSymbol
- Specified by:
onSymbolin interfaceTickFileReader.ReplayHandler
-
onTick
public void onTick(int symbolId, double price, double size, long timestampNanos) - Specified by:
onTickin interfaceTickFileReader.ReplayHandler
-
submitLimit
Description copied from interface:TickTradingContextPlaces a passive limit order. It fills when a later tick trades through the price, or partially as traded volume at the price works off the simulated queue ahead of it.- Specified by:
submitLimitin interfaceTickTradingContext- Returns:
- order id for
TickTradingContext.cancel(long)
-
submitMarket
Description copied from interface:TickTradingContextImmediate execution at the last trade price plus half the configured spread (aggressor pays the spread). Returns a negative id if no price has been seen for the symbol yet.- Specified by:
submitMarketin interfaceTickTradingContext
-
cancel
public boolean cancel(long orderId) Description copied from interface:TickTradingContextCancels a working limit order. False if unknown or already filled.- Specified by:
cancelin interfaceTickTradingContext
-
position
public long position(int symbolId) - Specified by:
positionin interfaceTickTradingContext
-
cash
public double cash()- Specified by:
cashin interfaceTickTradingContext
-
lastPrice
public double lastPrice(int symbolId) Description copied from interface:TickTradingContextLast traded price for the symbol (NaN before its first tick).- Specified by:
lastPricein interfaceTickTradingContext
-
symbolName
Description copied from interface:TickTradingContextSymbol name for an id from the tick file.- Specified by:
symbolNamein interfaceTickTradingContext
-