feat: strategy builder

This commit is contained in:
OpenSquared
2026-07-30 11:30:59 +02:00
parent 15528e0c98
commit 1c4d8013c4
4 changed files with 240 additions and 3 deletions

View File

@@ -179,6 +179,30 @@ def suggested_profile(scenario: ScenarioIn):
return infer_natural_greek_profile(scenario.spot_shock_pct, scenario.iv_level_shift, scenario.horizon_days)
class ReplayRequest(BaseModel):
symbol: str
legs: List[LegIn]
start_date: str
end_date: str
contract_size: float = DEFAULT_CONTRACT_SIZE
@router.post("/replay")
def replay(req: ReplayRequest):
"""Day-by-day mark-to-market of these exact legs against REAL accumulated Saxo
history between two dates — not a scenario, a replay of what actually happened.
See services.strategy_replay for why it's a distinct thing from /price's scenario
pricing (which prices a hypothetical spot/IV shock, not real historical quotes)."""
from services.strategy_replay import replay_position
try:
return replay_position(
req.symbol, [leg.dict() for leg in req.legs], req.start_date, req.end_date,
contract_size=req.contract_size,
)
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))
@router.post("/optimize")
def optimize(req: OptimizeRequest):
if req.constraints.max_legs > 4: