feat: strategy builder
This commit is contained in:
@@ -224,6 +224,7 @@ def price_combo(
|
||||
"max_gain": bounded["max_gain"],
|
||||
"max_loss": bounded["max_loss"],
|
||||
"bounded_risk": bounded["bounded"],
|
||||
"risk_debug": bounded.get("risk_debug"),
|
||||
"greeks_now": greeks_at(legs, spot_now, 0, surface_now, r),
|
||||
"greeks_scenario": greeks_at(legs, spot_scenario, horizon_days, surface_scenario, r),
|
||||
"net_delta_now": delta_now,
|
||||
@@ -281,6 +282,16 @@ def check_bounded_risk(
|
||||
loss_bounded = (lo_edge >= lo_in - tol) and (hi_edge >= hi_in - tol)
|
||||
gain_bounded = (lo_edge <= lo_in + tol) and (hi_edge <= hi_in + tol)
|
||||
|
||||
# Diagnostic snapshot of exactly why loss/gain were classified (un)bounded — surfaced
|
||||
# up through price_combo/payoff_curves so the /price router can log it (system_logs)
|
||||
# instead of this being a black box every time "-∞" shows up in the UI.
|
||||
risk_debug = {
|
||||
"eval_days": eval_days, "spot": spot, "entry_ref": round(entry_ref, 2), "tol": round(tol, 4),
|
||||
"lo_tail_price": round(float(tail_grid[0]), 6), "lo_edge_pnl": round(lo_edge, 2), "lo_inner_pnl": round(lo_in, 2),
|
||||
"hi_tail_price": round(float(tail_grid[-1]), 6), "hi_edge_pnl": round(hi_edge, 2), "hi_inner_pnl": round(hi_in, 2),
|
||||
"loss_bounded": loss_bounded, "gain_bounded": gain_bounded,
|
||||
}
|
||||
|
||||
# Dense linear sweep across the legs' own strikes — needed even in the fast path (see
|
||||
# docstring above), only the final 1-D refinement is reserved for precise=True.
|
||||
strikes = [l["strike"] for l in legs]
|
||||
@@ -294,6 +305,7 @@ def check_bounded_risk(
|
||||
"bounded": loss_bounded,
|
||||
"max_loss": round(min(combined_values), 2) if loss_bounded else None,
|
||||
"max_gain": round(max(combined_values), 2) if gain_bounded else None,
|
||||
"risk_debug": risk_debug,
|
||||
}
|
||||
|
||||
# Any FIXED grid — however dense — is a different finite sampling of the same
|
||||
@@ -330,6 +342,7 @@ def check_bounded_risk(
|
||||
"bounded": loss_bounded,
|
||||
"max_loss": round(refine(False), 2) if loss_bounded else None,
|
||||
"max_gain": round(refine(True), 2) if gain_bounded else None,
|
||||
"risk_debug": risk_debug,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user