summaryrefslogtreecommitdiff
path: root/cli/src/trading_cli/commands/backtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/trading_cli/commands/backtest.py')
-rw-r--r--cli/src/trading_cli/commands/backtest.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/cli/src/trading_cli/commands/backtest.py b/cli/src/trading_cli/commands/backtest.py
index ad21f8f..c17c61f 100644
--- a/cli/src/trading_cli/commands/backtest.py
+++ b/cli/src/trading_cli/commands/backtest.py
@@ -35,11 +35,12 @@ def backtest():
def run(strategy, symbol, timeframe, balance, output_format, file_path):
"""Run a backtest for a strategy."""
try:
- from strategy_engine.plugin_loader import load_strategies
from backtester.engine import BacktestEngine
- from backtester.reporter import format_report, export_csv, export_json
- from shared.db import Database
+ from backtester.reporter import export_csv, export_json, format_report
+ from strategy_engine.plugin_loader import load_strategies
+
from shared.config import Settings
+ from shared.db import Database
from shared.models import Candle
except ImportError as e:
click.echo(f"Error: Could not import required modules: {e}", err=True)
@@ -66,20 +67,19 @@ def run(strategy, symbol, timeframe, balance, output_format, file_path):
click.echo(f"Error: No candles found for {symbol} {timeframe}", err=True)
sys.exit(1)
- candles = []
- for row in reversed(candle_rows): # get_candles returns DESC, we need ASC
- candles.append(
- Candle(
- symbol=row["symbol"],
- timeframe=row["timeframe"],
- open_time=row["open_time"],
- open=row["open"],
- high=row["high"],
- low=row["low"],
- close=row["close"],
- volume=row["volume"],
- )
+ candles = [
+ Candle(
+ symbol=row["symbol"],
+ timeframe=row["timeframe"],
+ open_time=row["open_time"],
+ open=row["open"],
+ high=row["high"],
+ low=row["low"],
+ close=row["close"],
+ volume=row["volume"],
)
+ for row in reversed(candle_rows) # get_candles returns DESC, we need ASC
+ ]
engine = BacktestEngine(strat, Decimal(str(balance)))
result = engine.run(candles)
@@ -111,10 +111,11 @@ def run(strategy, symbol, timeframe, balance, output_format, file_path):
def walk_forward(strategy, symbol, timeframe, balance, windows):
"""Run walk-forward analysis to detect overfitting."""
try:
- from strategy_engine.plugin_loader import load_strategies
from backtester.walk_forward import WalkForwardEngine
- from shared.db import Database
+ from strategy_engine.plugin_loader import load_strategies
+
from shared.config import Settings
+ from shared.db import Database
from shared.models import Candle
except ImportError as e:
click.echo(f"Error: Could not import required modules: {e}", err=True)