Initialization

HftBacktest(data, tick_size, lot_size, maker_fee, taker_fee, order_latency, asset_type, queue_model=None, snapshot=None, start_position=0, start_balance=0, start_fee=0, trade_list_size=0, exchange_model=None)[source]

Create a HftBacktest instance.

Parameters:
  • data (str | ndarray[Any, dtype[ScalarType]] | DataFrame | List[str | ndarray[Any, dtype[ScalarType]] | DataFrame]) – Data to be fed.

  • tick_size (float) – Minimum price increment for the given asset.

  • lot_size (float) – Minimum order quantity for the given asset.

  • maker_fee (float) – Maker fee rate; a negative value indicates rebates.

  • taker_fee (float) – Taker fee rate; a negative value indicates rebates.

  • order_latency (OrderLatencyModel) – Order latency model. See Order Latency Models.

  • asset_type (AssetType) – Either Linear or Inverse. See Asset types.

  • queue_model (QueueModel | None) – Queue model with default set as models.queue.RiskAverseQueueModel. See Queue Models.

  • snapshot (str | ndarray[Any, dtype[ScalarType]] | DataFrame | None) – The initial market depth snapshot.

  • start_position (float) – Starting position.

  • start_balance (float) – Starting balance.

  • start_fee (float) – Starting cumulative fees.

  • trade_list_size (int) – Buffer size for storing market trades; the default value of 0 indicates that market trades will not be stored in the buffer.

  • exchange_model (Callable[[Reader, OrderBus, OrderBus, MarketDepth, State, OrderLatencyModel, QueueModel], JitClassType] | None) – Exchange model with default set as NoPartialFillExchange.

Returns:

JIT’ed SingleAssetHftBacktest

reset(hbt, data, tick_size=None, lot_size=None, maker_fee=None, taker_fee=None, snapshot=None, start_position=0, start_balance=0, start_fee=0, trade_list_size=None)[source]

Reset the HftBacktest for reuse. This can help reduce Ahead-of-Time (AOT) compilation time by using the cache=True option in the @njit decorator.

Parameters:
  • hbt (HftBacktest) – HftBacktest instance to be reset.

  • data (List[str | ndarray[Any, dtype[ScalarType]] | DataFrame] | str | ndarray[Any, dtype[ScalarType]] | DataFrame) – Data to be fed.

  • tick_size (float | None) – Minimum price increment for the given asset.

  • lot_size (float | None) – Minimum order quantity for the given asset.

  • maker_fee (float | None) – Maker fee rate; a negative value indicates rebates.

  • taker_fee (float | None) – Taker fee rate; a negative value indicates rebates.

  • snapshot (str | ndarray[Any, dtype[ScalarType]] | DataFrame | None) – The initial market depth snapshot.

  • start_position (float | None) – Starting position.

  • start_balance (float | None) – Starting balance.

  • start_fee (float | None) – Starting cumulative fees.

  • trade_list_size (int | None) – Buffer size for storing market trades; the default value of 0 indicates that market trades will not be stored in the buffer.