feat: instrument model

This commit is contained in:
OpenSquared
2026-07-03 11:00:23 +02:00
parent 5381b3fb92
commit 8f51e0de7b
3 changed files with 80 additions and 18 deletions

View File

@@ -1015,12 +1015,14 @@ def get_model_state(conn, instrument: str, at_date: Optional[str] = None) -> Opt
def simulate_timeline(
conn, instrument: str, period: str = "1y",
virtual_events: Optional[list] = None,
start_date: Optional[str] = None,
) -> list[dict]:
"""
Simulate all node values day by day over the period.
Returns [{date, nodes: {id: value}, net_pips}].
Uses lifecycle (rise/plateau/decay) for event contributions.
Manual overrides are static (applied uniformly across the period).
start_date overrides the period-based date_from when provided.
"""
inst_upper = instrument.upper()
row = conn.execute(
@@ -1033,9 +1035,15 @@ def simulate_timeline(
output_id = graph_def["output_node"]
period_days = {"5d":7,"1mo":35,"3mo":95,"6mo":190,"1y":370,"2y":740}
lookback = period_days.get(period, 370)
today = datetime.utcnow().date()
date_from = today - timedelta(days=lookback)
lookback = period_days.get(period, 370)
today = datetime.utcnow().date()
if start_date:
try:
date_from = date_type.fromisoformat(start_date[:10])
except ValueError:
date_from = today - timedelta(days=lookback)
else:
date_from = today - timedelta(days=lookback)
# Load overrides (static)
overrides = {r["node_id"]: dict(r) for r in conn.execute(
@@ -1107,6 +1115,10 @@ def simulate_timeline(
for ev in events:
if ev["ev_date"] > cur:
continue
if ev["ev_date"] < date_from:
# Events avant la fenêtre ne portent pas de lifecycle dans la simu
# (leur impact est absorbé dans l'auto-anchor du prix de départ)
continue
days = (cur - ev["ev_date"]).days
df = _lifecycle(days, ev["rise"], ev["plateau"], ev["absorption"], ev["dtype"])
if df < 0.01: