From 128454910624709c25d96691afddcf3991213466 Mon Sep 17 00:00:00 2001 From: Simon Moisy Date: Thu, 29 May 2025 11:04:03 +0800 Subject: [PATCH] progress print --- cycles/backtest.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cycles/backtest.py b/cycles/backtest.py index 2fddd08..2c5386c 100644 --- a/cycles/backtest.py +++ b/cycles/backtest.py @@ -1,5 +1,6 @@ import pandas as pd import numpy as np +import time from cycles.supertrend import Supertrends from cycles.market_fees import MarketFees @@ -42,9 +43,17 @@ class Backtest: entry_time = None current_trade_min1_start_idx = None - min1_df['timestamp'] = pd.to_datetime(min1_df.index) + min1_df.index = pd.to_datetime(min1_df.index) + min1_timestamps = min1_df.index.values + last_print_time = time.time() for i in range(1, len(_df)): + current_time = time.time() + if current_time - last_print_time >= 5: + progress = (i / len(_df)) * 100 + print(f"\rProgress: {progress:.1f}%", end="", flush=True) + last_print_time = current_time + price_open = _df['open'].iloc[i] price_close = _df['close'].iloc[i] date = _df['timestamp'].iloc[i] @@ -90,6 +99,8 @@ class Backtest: drawdown = (max_balance - balance) / max_balance drawdowns.append(drawdown) + print("\rProgress: 100%\r\n", end="", flush=True) + # If still in position at end, sell at last close if position == 1: exit_result = Backtest.handle_exit(coin, _df['close'].iloc[-1], entry_price, entry_time, _df['timestamp'].iloc[-1])