From f2451732e16bf955ca8731a93622e6e8f5b03311 Mon Sep 17 00:00:00 2001 From: nkaz001 Date: Wed, 23 Aug 2023 11:13:20 -0400 Subject: [PATCH] Fix invalid clear_upto price issue in convert method for DEPTH_CLEAR_EVENT. --- hftbacktest/data/utils/tardis.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hftbacktest/data/utils/tardis.py b/hftbacktest/data/utils/tardis.py index 9407813..18a7ab1 100644 --- a/hftbacktest/data/utils/tardis.py +++ b/hftbacktest/data/utils/tardis.py @@ -12,7 +12,7 @@ def convert( input_files: List[str], output_filename: Optional[str] = None, buffer_size: int = 100_000_000, - ss_buffer_size: int = 1_000, + ss_buffer_size: int = 10_000, base_latency: float = 0, method: Literal['separate', 'adjust'] = 'separate' ) -> NDArray: @@ -121,7 +121,10 @@ def convert( if is_snapshot: # End of the snapshot. is_snapshot = False + # Add DEPTH_CLEAR_EVENT before refreshing the market depth by the snapshot. + + ss_bid = ss_bid[:ss_bid_rn] # Clear the bid market depth within the snapshot bid range. tmp[row_num] = [ DEPTH_CLEAR_EVENT, @@ -133,11 +136,11 @@ def convert( ] row_num += 1 # Add DEPTH_SNAPSHOT_EVENT for the bid snapshot - ss_bid = ss_bid[:ss_bid_rn] tmp[row_num:row_num + len(ss_bid)] = ss_bid[:] row_num += len(ss_bid) ss_bid = None + ss_ask = ss_ask[:ss_ask_rn] # Clear the ask market depth within the snapshot ask range. tmp[row_num] = [ DEPTH_CLEAR_EVENT, @@ -149,7 +152,6 @@ def convert( ] row_num += 1 # Add DEPTH_SNAPSHOT_EVENT for the ask snapshot - ss_ask = ss_ask[:ss_ask_rn] tmp[row_num:row_num + len(ss_ask)] = ss_ask[:] row_num += len(ss_ask) ss_ask = None