From 2fd73085b81ca3f657e1ff363e39b39459b74db1 Mon Sep 17 00:00:00 2001 From: Simon Moisy Date: Wed, 21 May 2025 17:06:16 +0800 Subject: [PATCH] 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. --- cycles/backtest.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cycles/backtest.py b/cycles/backtest.py index 1ef8bd5..f90800b 100644 --- a/cycles/backtest.py +++ b/cycles/backtest.py @@ -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 \ No newline at end of file