Refactor backtest logic for improved index retrieval

- Updated the method for determining the start index of the current trade to directly use the DataFrame index, enhancing clarity and performance.
- Removed the deprecated get_current_min1_end_idx method to streamline the codebase.
This commit is contained in:
Simon Moisy 2025-05-21 17:06:16 +08:00
parent 806697116d
commit 2fd73085b8

View File

@ -66,7 +66,7 @@ class Backtest:
trade_log.append(trade_log_entry)
continue
# Update the start index for next check
current_trade_min1_start_idx = Backtest.get_current_min1_end_idx(min1_df, date)
current_trade_min1_start_idx = min1_df.index[min1_df.index <= date][-1]
# Entry: only if not in position and signal changes to 1
if position == 0 and prev_mt != 1 and curr_mt == 1:
@ -213,10 +213,4 @@ class Backtest:
coin = 0
position = 0
entry_price = 0
return usd, coin, position, entry_price, trade_log_entry
@staticmethod
def get_current_min1_end_idx(min1_df, date):
# Implement the logic to find the end index of the current 1-minute candle
# This is a placeholder and should be replaced with the actual implementation
return min1_df.index[min1_df.index <= date][-1]
return usd, coin, position, entry_price, trade_log_entry