diff --git a/src/multi_swarm/agents/falsification.py b/src/multi_swarm/agents/falsification.py index df50e68..df9d783 100644 --- a/src/multi_swarm/agents/falsification.py +++ b/src/multi_swarm/agents/falsification.py @@ -72,10 +72,12 @@ class FalsificationAgent: periods_per_year=8760, sharpe_var=1.0, ) - # +1.0 sull'equity curve evita divisione per zero in max_drawdown / - # total_return: l'engine produce equity in valore assoluto partendo da - # 0, ma le metriche sono definite su serie strettamente positive. - equity_pos = result.equity_curve + 1.0 + # Normalizza l'equity sul prezzo iniziale (notional di una position size 1). + # L'engine produce equity in unita' di P&L assoluto partendo da 0; per + # max_drawdown e total_return serve una serie strettamente positiva + # interpretabile come "wealth ratio" rispetto al notional iniziale. + notional = float(ohlcv["close"].iloc[0]) + equity_pos = (result.equity_curve / notional) + 1.0 return FalsificationReport( sharpe=sr, dsr=dsr, diff --git a/src/multi_swarm/agents/hypothesis.py b/src/multi_swarm/agents/hypothesis.py index 3825366..6db27cb 100644 --- a/src/multi_swarm/agents/hypothesis.py +++ b/src/multi_swarm/agents/hypothesis.py @@ -43,9 +43,23 @@ con i seguenti verbi disponibili: Comparatori: gt, lt, eq Dati: feature, indicator, crossover, crossunder -Indicatori disponibili: sma , rsi , atr , macd, realized_vol . +Indicatori disponibili (calcolati implicitamente sul prezzo close): + sma , rsi , atr , macd, realized_vol . Feature disponibili: open, high, low, close, volume. +REGOLE STRETTE DI SINTASSI: +- (indicator ) restituisce una serie numerica. Es. + (indicator rsi 14), (indicator sma 50), (indicator macd 12 26 9). +- (feature ) restituisce la colonna OHLCV. Es. (feature close). +- Gli indicatori NON sono annidabili: NON puoi scrivere + (sma (indicator realized_vol 30) 150) o (indicator rsi (feature high) 14). + Le funzioni sma/rsi/etc. ESISTONO SOLO come argomenti di indicator, + non sono verbi indipendenti. +- Costanti numeriche (es. 70.0, 30, 0.02) sono valide come 2° operando di gt/lt/eq. +- crossover/crossunder accettano due espressioni-serie: + (crossover (feature close) (indicator sma 20)) — corretto. + (crossover (sma close 20) (sma close 50)) — ERRATO (sma non è verbo). + Le regole sono valutate in ordine; la prima che matcha vince per ogni timestamp. La default action se nessuna regola matcha è 'flat'. @@ -55,7 +69,8 @@ senza spiegazioni. Esempio formato: ```lisp (strategy (when (gt (indicator rsi 14) 70.0) (entry-short)) - (when (lt (indicator rsi 14) 30.0) (entry-long))) + (when (lt (indicator rsi 14) 30.0) (entry-long)) + (when (crossover (feature close) (indicator sma 50)) (entry-long))) ``` """