Best basket stop loss and target; margin through the day
Status (2026-11-09): built, not deployed.
The two "Best" buttons (Basket page)
Next to Basket SL (Rs) and Basket target (Rs) there is a Best button. It starts a job on the shared queue (POST /api/tbs/basket-limits, app/api/basket_limits.py) that runs the basket once without limits, then tries many values on the basket's own minute-by-minute profit curves (tbs/basket_limits.py):
- A limit only decides at which minute a day is squared off, so every (stop loss, target) pair can be tested without simulating again: the day's result is the curve value at the first minute that lost
slor gainedtarget(stop loss first on a tie, asbasket.apply_limitsdoes), less the round-trip charges of the legs still open there. Overnight days and days without minute bars keep their own result. - Stop-loss values come from the days' worst losses (quantiles plus a ladder from 8% of the largest to 105%), targets from their best gains, in round numbers. The other limit typed on the page is held while one is searched.
- The best value is the highest Calmar (net / max drawdown) among those that make money (if none does, the least bad is shown and flagged). Each row also shows the first 70% and the last 30% of the days on their own and whether both beat the current limits: a value that is better in only one half is weak evidence.
- The numbers are an estimate; run the basket with the chosen value to confirm (the dialog says so). Use fills the field.
Margin through the day (TBS results)
The Summary tab of every TBS result (run, basket, saved report) now has Margin through the day (tbs/marginprofile.py, summary.margin_profile from runview.filtered_view): the margin the legs open at each 15 minute point need (the Quick rate on sold minus bought notional), the busiest day and the average day, with the peak and its time, the average and the utilisation (average margin over the session / peak: 100% = the same margin all day). A strategy that has squared off frees its margin. When the run has an exact SPAN margin the chart is scaled to it so it matches the Margin card.