"""TR01 — EMA Trend Following (long-only), timeframe 4h.

Cavalca i trend rialzisti, si mette in cash nei downtrend. Niente short
(shortare cripto perde OOS nel campione 2018-2026). Complementare a DIP01:
DIP01 guadagna nei regimi di reversione, TR01 nei regimi di trend.

Logica:
    1. EMA fast (20) e EMA slow (100) sul close
    2. LONG quando EMA_fast > EMA_slow (uptrend), altrimenti CASH
    3. posizione continua, decisione a close[i] (no look-ahead);
       fee solo sui cambi di stato (poche operazioni = fee non letali)

Validazione (netto, fee 0.10% RT, leva 3x, pos 15%, OOS = ultimo 30%):
    robusto FULL+OOS su 5/8 asset: BNB(+14), BTC(+27), DOGE(+53), SOL(+7), XRP(+29) OOS.
    ETH ~flat, ADA/LTC negativi OOS -> preferire BNB/BTC/DOGE/SOL/XRP.
Dettagli in scripts/analysis/honest_final.py / honest_trend.py.
"""
from __future__ import annotations

import sys
from pathlib import Path

PROJECT_ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(PROJECT_ROOT))

from scripts.analysis.honest_trend import (  # noqa: E402
    simulate_position, ema_dual_signal, oos as trend_oos,
)
from scripts.analysis.honest_lab import get_df

ASSETS = ["BNB", "BTC", "DOGE", "SOL", "XRP"]
FAST, SLOW, TF = 20, 100, "4h"


def run():
    print("=" * 90)
    print(f"  TR01 EMA TREND {FAST}/{SLOW} long-only | {TF} | netto fee 0.10% RT leva 3x pos 15%")
    print("=" * 90)
    print(f"  {'Asset':<6s}{'Flip':>6s}{'FULL%':>9s}{'OOS%':>9s}{'DD%':>6s}{'Exp%':>6s}{'AnniPos':>9s}")
    for a in ASSETS:
        df = get_df(a, TF)
        sig = ema_dual_signal(df, FAST, SLOW, long_only=True)
        f = simulate_position(sig, df)
        o = trend_oos(sig, df)
        print(f"  {a:<6s}{f['flips']:>6d}{f['ret']:>+9.0f}{o['ret']:>+9.0f}"
              f"{f['dd']:>6.0f}{f['exposure']:>6.0f}{str(f['pos_years'])+'/'+str(f['n_years']):>9s}")


if __name__ == "__main__":
    run()
