#!/usr/bin/env python """export_series.py — esporta la serie del book live per il motore nel browser. La pagina interattiva (`pagina_simulatore.html`) simula nel browser, quindi le serve la sequenza dei ritorni giornalieri VERI del book: gli stessi che usa `r0807_growth_yearly.py`, cioe' TP01 75% + SKH01 25% alle ancore canoniche, gia' de-luckati x0.89 sul drift da `r0726_venue_risk`. Esporta anche le costanti che il motore deve condividere col Python (bersaglio, cambio, aliquote, lunghezza dei blocchi): se una di queste vivesse in due posti, prima o poi divergerebbe. uv run python scripts/web/export_series.py --out /tmp/series.json """ from __future__ import annotations import argparse import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT)) sys.path.insert(0, str(ROOT / "scripts" / "research")) import r0725_capcurve as CC # noqa: E402 import r0726_venue_risk as VR # noqa: E402 import r0727_lumpsum_split as LS # noqa: E402 import r0727_tasse as TX # noqa: E402 def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--out", required=True) a = ap.parse_args() s = VR.venue_series()["Deribit"] r = s.values.astype(float) dati = dict( n=len(r), start=str(s.index[0].date()), end=str(s.index[-1].date()), start_usd=LS.START, target=LS.TARGET, eurusd=CC.EURUSD, deluck=VR.DELUCK, tax=0.33, patrimoniale=TX.PATRIMONIALE, carry=TX.CARRY_ANNI, block=20, r=[round(x, 8) for x in r], ) Path(a.out).write_text(json.dumps(dati)) print(f" {len(r)} giorni [{dati['start']} -> {dati['end']}] " f"drift {r.mean()*365:.1%} vol {r.std()*365**0.5:.1%}") print(f" bersaglio ${LS.TARGET:,.0f} · de-luck ×{VR.DELUCK} · " f"scritto {a.out} ({Path(a.out).stat().st_size/1024:.0f} KB)") if __name__ == "__main__": main()