feat: finalize portfolio system and quantitative validation- Finalized MA_Crossover(30,100) and TrendFiltered_MA(30,100,ADX=15)
- Implemented portfolio engine with risk-based allocation (50/50) - Added equity-based metrics for system-level evaluation - Validated portfolio against standalone strategies - Reduced max drawdown and volatility at system level - Quantitative decision closed before paper trading phase
This commit is contained in:
64
src/strategies/breakout.py
Normal file
64
src/strategies/breakout.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# src/strategies/breakout.py
|
||||
import pandas as pd
|
||||
|
||||
from src.strategies.base import Strategy
|
||||
from src.core.strategy import Signal
|
||||
|
||||
class DonchianBreakout(Strategy):
|
||||
"""
|
||||
Estrategia de ruptura de canales Donchian
|
||||
|
||||
Señales:
|
||||
- BUY: El precio rompe el máximo de los últimos N periodos
|
||||
- SELL: El precio rompe el mínimo de los últimos N periodos
|
||||
- HOLD: En cualquier otro caso
|
||||
|
||||
Parámetros:
|
||||
lookback: Ventana de cálculo del canal
|
||||
|
||||
Valores por defecto:
|
||||
lookback = 20
|
||||
≈ 1 día en timeframe 1h
|
||||
Parámetro clásico del sistema Turtle
|
||||
|
||||
Notas:
|
||||
- Es una estrategia de momentum puro
|
||||
- No intenta comprar barato, compra fortaleza
|
||||
- Filtra ruido al exigir ruptura real
|
||||
"""
|
||||
|
||||
def __init__(self, lookback: int = 20):
|
||||
params = {
|
||||
"lookback": lookback
|
||||
}
|
||||
|
||||
super().__init__(name="DonchianBreakout", params=params)
|
||||
|
||||
self.lookback = lookback
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def init_indicators(self, data: pd.DataFrame) -> pd.DataFrame:
|
||||
data["donchian_high"] = data["high"].rolling(self.lookback).max()
|
||||
data["donchian_low"] = data["low"].rolling(self.lookback).min()
|
||||
return data
|
||||
|
||||
def generate_signal(self, idx: int) -> Signal:
|
||||
if idx < self.lookback:
|
||||
return Signal.HOLD
|
||||
|
||||
high = self.data["high"]
|
||||
low = self.data["low"]
|
||||
close = self.data["close"]
|
||||
|
||||
max_high = high.iloc[idx - self.lookback : idx].max()
|
||||
min_low = low.iloc[idx - self.lookback : idx].min()
|
||||
|
||||
price = close.iloc[idx]
|
||||
|
||||
if price > max_high:
|
||||
return Signal.BUY
|
||||
elif price < min_low:
|
||||
return Signal.SELL
|
||||
|
||||
return Signal.HOLD
|
||||
Reference in New Issue
Block a user