Engine: add stop loss integration (fixed & trailing) with tests
This commit is contained in:
27
backtest.py
27
backtest.py
@@ -33,12 +33,10 @@ def run_backtest_demo():
|
||||
# Configuración del backtest
|
||||
symbol = 'BTC/USDT'
|
||||
timeframe = '1h'
|
||||
days_back = 60 # 2 meses de datos
|
||||
|
||||
log.info(f"\n📊 Configuración:")
|
||||
log.info(f" Símbolo: {symbol}")
|
||||
log.info(f" Timeframe: {timeframe}")
|
||||
log.info(f" Periodo: {days_back} días")
|
||||
|
||||
# Conectar a base de datos
|
||||
storage = StorageManager(
|
||||
@@ -50,15 +48,13 @@ def run_backtest_demo():
|
||||
)
|
||||
|
||||
# Cargar datos
|
||||
log.info("\n📥 Cargando datos desde PostgreSQL...")
|
||||
end_date = datetime.now()
|
||||
start_date = end_date - timedelta(days=days_back)
|
||||
log.info("\n📥 Cargando TODOS los datos desde PostgreSQL...")
|
||||
|
||||
data = storage.load_ohlcv(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
start_date=None,
|
||||
end_date=None,
|
||||
use_cache=False
|
||||
)
|
||||
|
||||
@@ -68,8 +64,9 @@ def run_backtest_demo():
|
||||
return
|
||||
|
||||
log.success(f"✓ Datos cargados: {len(data)} velas")
|
||||
log.info(f" Desde: {data.index[0]}")
|
||||
log.info(f" Hasta: {data.index[-1]}")
|
||||
log.info(f" Desde: {data.index.min()}")
|
||||
log.info(f" Hasta: {data.index.max()}")
|
||||
log.info(f" Total días: {(data.index.max() - data.index.min()).days}")
|
||||
|
||||
# Crear estrategia
|
||||
strategy = MovingAverageCrossover(
|
||||
@@ -137,7 +134,6 @@ def compare_strategies_demo():
|
||||
# Configuración
|
||||
symbol = 'BTC/USDT'
|
||||
timeframe = '1h'
|
||||
days_back = 60
|
||||
|
||||
# Conectar a base de datos y cargar datos
|
||||
storage = StorageManager(
|
||||
@@ -148,10 +144,13 @@ def compare_strategies_demo():
|
||||
db_password=os.getenv('DB_PASSWORD'),
|
||||
)
|
||||
|
||||
end_date = datetime.now()
|
||||
start_date = end_date - timedelta(days=days_back)
|
||||
|
||||
data = storage.load_ohlcv(symbol, timeframe, start_date, end_date, use_cache=False)
|
||||
data = storage.load_ohlcv(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
start_date=None,
|
||||
end_date=None,
|
||||
use_cache=False
|
||||
)
|
||||
|
||||
if data.empty:
|
||||
log.error(f"❌ No hay datos disponibles")
|
||||
|
||||
Reference in New Issue
Block a user