Skip to content

Commit

Permalink
Fix an issue where a proper start timestamp cannot be found. #37
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaz001 committed Sep 3, 2023
1 parent 7299d9a commit 08216b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion hftbacktest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
'correct'
)

__version__ = '1.6.4'
__version__ = '1.6.5'


# JIT'ed latency models
Expand Down
36 changes: 20 additions & 16 deletions hftbacktest/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,35 @@ def __init__(self, local, exch):
#: Whether a backtest has finished.
self.run = True
#: Current timestamp
self.current_timestamp = self.local.next_data[0, COL_LOCAL_TIMESTAMP]
self.current_timestamp = self.start_timestamp

@property
def start_timestamp(self):
# fixme: deprecated.
# it returns the timestamp of the first row of the data that is currently processed.
if len(self.local.data) > 0:
return self.local.data[0, COL_LOCAL_TIMESTAMP]
else:
if len(self.local.next_data) > 0:
return self.local.next_data[0, COL_LOCAL_TIMESTAMP]
else:
return 0
for i in range(len(self.local.data)):
timestamp = self.local.data[i, COL_LOCAL_TIMESTAMP]
if timestamp > 0:
return timestamp
for i in range(len(self.local.next_data)):
timestamp = self.local.next_data[i, COL_LOCAL_TIMESTAMP]
if timestamp > 0:
return timestamp
return 0

@property
def last_timestamp(self):
# fixme: deprecated.
# it returns the timestamp of the last row of the data that is currently processed.
if len(self.local.data) > 0:
return self.local.data[-1, COL_LOCAL_TIMESTAMP]
else:
if len(self.local.next_data) > 0:
return self.local.next_data[-1, COL_LOCAL_TIMESTAMP]
else:
return 0
for i in range(len(self.local.data) - 1, -1, -1):
timestamp = self.local.data[i, COL_LOCAL_TIMESTAMP]
if timestamp > 0:
return timestamp
for i in range(len(self.local.next_data) - 1, -1, -1):
timestamp = self.local.next_data[i, COL_LOCAL_TIMESTAMP]
if timestamp > 0:
return timestamp
return 0

@property
def position(self):
Expand Down Expand Up @@ -488,5 +492,5 @@ def reset(
lot_size,
snapshot
)
self.current_timestamp = self.local.next_data[0, COL_LOCAL_TIMESTAMP]
self.current_timestamp = self.start_timestamp
self.run = True

0 comments on commit 08216b2

Please sign in to comment.