Skip to main content

Module book

Module book 

Source
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

  1. Start flat: cash only, capital dollars, at the close of the last trading day before the period.
  2. 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.
  3. 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.
  4. Mark to market every close: the equity curve is cash plus what every open position is worth that day.
  5. 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 from super::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.
EqualHold
Equal weight in every symbol that trades on day one, held.
Event
An event a live runner would announce.
FireMomentum
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.
MoveTilt
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.
StretchReversion
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.
SwingFire
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_frac of equity at entry, at most max_open at 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.