"""PORT02 — Fade master (default). Report backtest del portafoglio."""
import sys
from pathlib import Path

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

from scripts.portfolios._defs import PORTFOLIOS  # noqa: E402

CODE = "PORT02"


def run():
    p = PORTFOLIOS[CODE]
    r = p.backtest()
    print("=" * 80)
    print(f"  {p.code} — {p.label} | pesi={p.weighting} caps={p.caps} leva={p.leverage}x")
    print("=" * 80)
    print(f"  FULL ret {r.full['ret']:+.0f}%  CAGR {r.full['cagr']:.0f}%  "
          f"DD {r.full['dd']:.1f}%  Sharpe {r.full['sharpe']:.2f}")
    print(f"  OOS  ret {r.oos['ret']:+.0f}%  DD {r.oos['dd']:.1f}%  Sharpe {r.oos['sharpe']:.2f}")
    print("  per anno:", {y: round(v) for y, v in sorted(r.yearly.items())})
    print("  rischio % per sleeve:", {k: round(v, 1) for k, v in
          sorted(r.risk.items(), key=lambda x: -x[1])})


if __name__ == "__main__":
    run()
