feat: strategy builder
This commit is contained in:
@@ -282,6 +282,47 @@ def price(req: PriceRequest):
|
||||
result["spot"] = chain_slice["spot"]
|
||||
result["scenario_spot"] = surface_scenario.spot
|
||||
result["proxy"] = chain_slice["proxy"]
|
||||
|
||||
# Debug trace for two open questions (nominal/entry_cost not matching the UI's own bid/
|
||||
# ask math, and "-∞" risk on structures that look bounded by hand): log EXACTLY what was
|
||||
# received and computed, so both can be checked from System Logs (source=strategy_price_debug,
|
||||
# or filter level=WARNING to jump straight to the unbounded cases) instead of digging
|
||||
# through the browser's Network tab. Remove once both are confirmed resolved.
|
||||
from services.database import log_system_event
|
||||
bounded_risk = result.get("bounded_risk")
|
||||
log_system_event(
|
||||
level="INFO" if bounded_risk else "WARNING",
|
||||
source="strategy_price_debug",
|
||||
message=(
|
||||
f"/price {req.scenario.symbol}: {len(legs)} jambe(s), nominal={req.scenario.contract_size}, "
|
||||
f"entry_cost={result.get('entry_cost')} (mid={result.get('entry_cost_mid')}), "
|
||||
f"broker_spread_cost={result.get('broker_spread_cost')}, "
|
||||
f"max_gain={result.get('max_gain')}, max_loss={result.get('max_loss')}, bounded_risk={bounded_risk}"
|
||||
),
|
||||
ticker=req.scenario.symbol,
|
||||
details={
|
||||
"legs_received": legs,
|
||||
"scenario_received": {
|
||||
"contract_size": req.scenario.contract_size,
|
||||
"horizon_days": req.scenario.horizon_days,
|
||||
"spot_shock_pct": req.scenario.spot_shock_pct,
|
||||
"iv_level_shift": req.scenario.iv_level_shift,
|
||||
"skew_tilt": req.scenario.skew_tilt,
|
||||
"term_slope_shift": req.scenario.term_slope_shift,
|
||||
"has_spot_path": bool(req.scenario.spot_path),
|
||||
"has_iv_path": bool(req.scenario.iv_path),
|
||||
"has_skew_path": bool(req.scenario.skew_path),
|
||||
"has_term_path": bool(req.scenario.term_path),
|
||||
},
|
||||
"priced": {
|
||||
"entry_cost": result.get("entry_cost"), "entry_cost_mid": result.get("entry_cost_mid"),
|
||||
"broker_spread_cost": result.get("broker_spread_cost"),
|
||||
"max_gain": result.get("max_gain"), "max_loss": result.get("max_loss"),
|
||||
"bounded_risk": bounded_risk,
|
||||
},
|
||||
"risk_debug": result.get("risk_debug"),
|
||||
},
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user