feat: option lab
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
import traceback as tb_mod
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, List, Dict, Any
|
||||
@@ -179,6 +179,21 @@ def position_payoff(pos_id: str):
|
||||
return compute_payoff(pos)
|
||||
|
||||
|
||||
@router.get("/positions/{pos_id}/retrospective-optimal")
|
||||
def position_retrospective_optimal(pos_id: str, as_of: str = Query(None)):
|
||||
""""What would have been optimal, in hindsight?" — reprices the position's real legs
|
||||
and runs the Strategy Builder optimizer against the REAL historical Saxo chain and the
|
||||
REALIZED spot/IV move since entry (not a guessed scenario) — see
|
||||
services.strategy_comparison.compute_retrospective_comparison. Expensive (runs the full
|
||||
template-search optimizer), so this is on-demand from the Portfolio position detail, not
|
||||
auto-computed for every open position."""
|
||||
from services.strategy_comparison import compute_retrospective_comparison
|
||||
pos = next((p for p in get_positions("open") + get_positions("closed") if p["id"] == pos_id), None)
|
||||
if not pos:
|
||||
raise HTTPException(status_code=404, detail=f"Position '{pos_id}' introuvable")
|
||||
return compute_retrospective_comparison(pos, as_of=as_of)
|
||||
|
||||
|
||||
@router.get("/scenario-exposure")
|
||||
def scenario_exposure():
|
||||
"""Reprices every open position under a handful of named macro scenarios (Risk-Off,
|
||||
|
||||
Reference in New Issue
Block a user