feat: instrument model
This commit is contained in:
@@ -1077,6 +1077,28 @@ def simulate_timeline(
|
||||
structural_pips = round(float(vals_struct.get(output_id, 0.0)), 1)
|
||||
fundamental_level_base = round(price_intercept + structural_pips * pip_to_price, 6)
|
||||
|
||||
# Auto-anchor : caler le niveau fondamental sur le prix réel au début de la fenêtre.
|
||||
# start_offset = prix_réel_début - niveau_fondamental_machine
|
||||
# → synthetic_price(t) = prix_réel_début + event_pips(t) * pip_to_price
|
||||
start_offset = 0.0
|
||||
try:
|
||||
ph_row = conn.execute(
|
||||
"""SELECT close FROM price_history_cache
|
||||
WHERE instrument=? AND date>=? ORDER BY date ASC LIMIT 1""",
|
||||
(inst_upper, str(date_from))
|
||||
).fetchone()
|
||||
if ph_row is None:
|
||||
# Weekends/jours fériés : on remonte jusqu'à 7 jours avant
|
||||
ph_row = conn.execute(
|
||||
"""SELECT close FROM price_history_cache
|
||||
WHERE instrument=? AND date>=? ORDER BY date ASC LIMIT 1""",
|
||||
(inst_upper, str(date_from - timedelta(days=7)))
|
||||
).fetchone()
|
||||
if ph_row:
|
||||
start_offset = round(float(ph_row["close"]) - fundamental_level_base, 6)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
timeline = []
|
||||
cur = date_from
|
||||
while cur <= today:
|
||||
@@ -1111,8 +1133,8 @@ def simulate_timeline(
|
||||
"net_pips": net,
|
||||
"structural_pips": structural_pips,
|
||||
"event_pips": round(net - structural_pips, 1),
|
||||
"fundamental_level": fundamental_level_base,
|
||||
"synthetic_price": round(price_intercept + net * pip_to_price, 6),
|
||||
"fundamental_level": round(fundamental_level_base + start_offset, 6),
|
||||
"synthetic_price": round(price_intercept + start_offset + net * pip_to_price, 6),
|
||||
"regime": regime_label,
|
||||
"nodes": {k: round(float(v), 1) for k, v in vals.items()},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user