Skip to content

Strategy Studio

Savvas Leousis edited this page Sep 26, 2026 · 2 revisions

Strategy Studio

Build a strategy from rules, with no code. Test it, register it, then switch it on or off. The backend is served by the REST API under /api/studio, and the Studio page of the Web Console is its visual builder.

stateDiagram-v2
  [*] --> draft: create
  draft --> draft: edit, validate, backtest, lab run
  draft --> shadow: register
  shadow --> active: enable (go-live gate)
  active --> shadow: disable
Loading

A rule spec

A draft holds a JSON spec run by RuleStrategy (catalog id rule_based). Example, from the built-in "SMA trend following" template:

{
  "version": 1,
  "name": "SMA trend following",
  "interval": "1d",
  "universe": {"asset_classes": ["equity"]},
  "indicators": [
    {"id": "sma20", "kind": "sma", "period": 20},
    {"id": "sma50", "kind": "sma", "period": 50},
    {"id": "roc20", "kind": "roc", "period": 20}
  ],
  "entry": {"type": "compare", "left": {"type": "indicator", "id": "sma20"},
            "op": ">", "right": {"type": "indicator", "id": "sma50"}},
  "exit":  {"type": "compare", "left": {"type": "indicator", "id": "sma20"},
            "op": "crosses_below", "right": {"type": "indicator", "id": "sma50"}},
  "rank": {"by": "roc20", "order": "desc"},
  "sizing": {"max_positions": 5, "allocation": 1.0},
  "risk": {"stop_loss_pct": null, "take_profit_pct": null}
}
  • Indicators: close, volume, sma, ema, rsi, roc (or trailing_return), zscore, atr, donchian_high, donchian_low.
  • Operators: <, <=, >, >=, crosses_above, crosses_below.
  • Logic: combine conditions with all, any, not.
  • Sizing: equal weight across up to max_positions.
  • Risk: optional stop loss and take profit, in percent.
  • Templates: RSI mean reversion, SMA trend following, Donchian breakout (GET /api/studio/templates).

The flow

Step Route
Create a draft POST /api/studio/drafts with name and spec
Validate (spec check + smoke run) POST /api/studio/drafts/{id}/validate
Backtest (background job) POST /api/studio/drafts/{id}/backtests
Lab run with survival tests (job) POST /api/studio/drafts/{id}/lab-runs
Register (lands in shadow) POST /api/studio/drafts/{id}/register
Enable (active) / disable (shadow) POST /api/studio/drafts/{id}/enable or /disable

Enable uses the same go-live gate as a promotion: it is refused unless the go-live check passes, or you send override with a reason of at least 20 characters. The JSON schema of a spec is at GET /api/studio/schema.

Writes need the API token. See API and MCP.

Code strategies (off by default)

A draft can also hold Python source (kind: "code"), saved under data/user_strategies/.

It is off unless you set [api] allow_code_strategies = true. Why:

  • The code runs inside the server with its full rights (files, network, secrets in env).
  • There is no sandbox and no timeout.
  • Only turn it on for one trusted user on a trusted machine.

When on, a module must define exactly one BaseStrategy subclass and pass a smoke run on sample data before it can be backtested or registered.

Clone this wiki locally