From 256ad67742c59f1db9bdb03f5bb33ebc470bb46c Mon Sep 17 00:00:00 2001 From: "Vasily.onl" Date: Fri, 23 May 2025 17:14:08 +0800 Subject: [PATCH] refactor --- cycles/backtest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cycles/backtest.py b/cycles/backtest.py index cad4a5f..e146d86 100644 --- a/cycles/backtest.py +++ b/cycles/backtest.py @@ -31,7 +31,8 @@ class Backtest: """ Runs the backtest using provided entry and exit strategy functions. - The method iterates over the main DataFrame (self.df), simulating trades based on the entry and exit strategies. It tracks balances, drawdowns, and logs each trade, including fees. At the end, it returns a dictionary of performance statistics. + The method iterates over the main DataFrame (self.df), simulating trades based on the entry and exit strategies. + It tracks balances, drawdowns, and logs each trade, including fees. At the end, it returns a dictionary of performance statistics. Parameters: - entry_strategy: function, determines when to enter a trade. Should accept (self, i) and return True to enter. @@ -48,6 +49,7 @@ class Backtest: self.current_date = self.df['timestamp'].iloc[i] + # check if we are in buy/sell position if self.position == 0: if entry_strategy(self, i): self.handle_entry()