Expand description
§Book: trading a full month or a full year, the way a person would
sim.rs grades strategies one trade at a time. That answers “is this
trade a good bet?”, but not “what would my account have looked like if I
had run this for all of 2022?”. This file answers the second question.
§What “trade a full period” means here
- Start flat: cash only,
capitaldollars, at the close of the last trading day before the period. - Every close, decide: SD is read from bars up to and including that close, and nothing later. The strategy says what it wants to hold.
- Fill at the next open (stocks) or at that close (options, the option simulator’s rule, since option prices come from the close). Every fill pays costs.
- Mark to market every close: the equity curve is cash plus what every open position is worth that day.
- End flat: everything still open is closed at the period’s last close, at marked value minus closing costs.
Nothing in the period can see the period’s future: SD’s models for
year Y are refitted on bars whose outcomes were known before Y began
(see sd_year).
§Two kinds of strategy
Allocator: stock strategies. Each close they return target weights (negative = short); the book trades the difference.- Option strategies from
strategy/mod.rs: each symbol’s trades come fromsuper::sim::run_window, and the book sizes each one at a fixed fraction of equity (“risk 2% of the account per trade”).
Structs§
- Closed
- One finished position, for win ratio and expectancy.
- DayView
- What an allocator may look at on one close.
- Equal
Hold - Equal weight in every symbol that trades on day one, held.
- Event
- An event a live runner would announce.
- Fire
Momentum - Trade fresh squeeze fires in the direction of momentum.
- HoldOne
- Buy one symbol on day one, hold to the end.
- Lane
- One symbol, lined up on the shared calendar.
- Metrics
- The standard scorecard.
- Move
Tilt - Rank by SD’s expected move and hold the top (or bottom) names, weekly.
- Run
- The result of trading one strategy over one period.
- SdSide
- Hold every name SD puts above 0.5, equal weight, rebalanced weekly.
- Stretch
Reversion - Few-day mean reversion: own the names stretched furthest below their 21-bar average (on the side SD calls up), re-picked every 5 days.
- Swing
Fire - Few-day swing: buy fresh fires (first half of their expected life) with a clear upward lean; sell as soon as the fire is no longer fresh.
Constants§
- PALETTE
- A colour per series that reads on light and dark pages.
- RISK_
FREE - Annual risk-free rate subtracted in Sharpe and Sortino.
- STOCK_
COST - Stock costs: half-spread + slippage per side, as a fraction of notional.
Traits§
- Allocator
- A stock strategy: target weights each close.
Functions§
- allocators
- Every stock strategy the year runs include, in report order.
- metrics
- run_
allocator - Trade an allocator over calendar days
start..=end(start= the close before the period, where the first decision is made). - run_
options - Size option trades into an account: each trade may lose at most
risk_fracof equity at entry, at mostmax_openat once (later ones are skipped). - svg_
bars - Grouped bars: one group per bucket label, one bar per series (values 0..1).
- svg_
equity - Line chart of equity curves, each starting at 100.
- svg_
heatmap - Heat map: one row per strategy, one column per period, cell = return.