feat: strategy builder

This commit is contained in:
OpenSquared
2026-07-30 13:51:15 +02:00
parent 81165581d7
commit d85c0348d8
3 changed files with 58 additions and 16 deletions

View File

@@ -139,9 +139,10 @@ def chain(
n_expiries: int = Query(3),
dte_min: Optional[int] = Query(None),
dte_max: Optional[int] = Query(None),
as_of: Optional[str] = Query(None, description="Reconstruct the chain as it stood at/before this date instead of now — e.g. to build legs against the same chain a past Replay window will walk, rather than today's."),
):
try:
return get_chain_slice(symbol, horizon_days, n_expiries, dte_min=dte_min, dte_max=dte_max)
return get_chain_slice(symbol, horizon_days, n_expiries, dte_min=dte_min, dte_max=dte_max, as_of=as_of)
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))
@@ -152,15 +153,18 @@ def presets(
horizon_days: int = Query(8),
dte_min: Optional[int] = Query(None),
dte_max: Optional[int] = Query(None),
as_of: Optional[str] = Query(None),
):
"""The full strategy catalog (services.backtest_strategies.STRATEGIES) built from the
REAL current chain instead of Backtest's synthetic grid — so a preset click here seeds
the leg editor with actually-quoted strikes/expiries, ready to price or replay as-is.
n_expiries=5 (vs. Strategy Builder's own default of 3) so calendar/diagonal presets,
which need two distinct expiries, reliably have a second one to draw from."""
REAL chain instead of Backtest's synthetic grid — so a preset click here seeds the leg
editor with actually-quoted strikes/expiries, ready to price or replay as-is.
n_expiries=20 (vs. Strategy Builder's own default of 3) so calendar/diagonal presets,
which need two distinct expiries, reliably have a second one to draw from, and so a
wide dte_min/dte_max window (e.g. hunting for a ~30d expiry) isn't silently narrowed
back down to whatever's nearest horizon_days."""
from services.backtest_strategies import STRATEGIES, build_legs
try:
chain_slice = get_chain_slice(symbol, horizon_days, 5, dte_min=dte_min, dte_max=dte_max)
chain_slice = get_chain_slice(symbol, horizon_days, 20, dte_min=dte_min, dte_max=dte_max, as_of=as_of)
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))