This commit is contained in:
Vasily.onl 2025-05-23 17:14:08 +08:00
parent f67b6b8ebd
commit 256ad67742

View File

@ -31,7 +31,8 @@ class Backtest:
""" """
Runs the backtest using provided entry and exit strategy functions. 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: Parameters:
- entry_strategy: function, determines when to enter a trade. Should accept (self, i) and return True to enter. - 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] self.current_date = self.df['timestamp'].iloc[i]
# check if we are in buy/sell position
if self.position == 0: if self.position == 0:
if entry_strategy(self, i): if entry_strategy(self, i):
self.handle_entry() self.handle_entry()