本文へ移動

仕組み

ADR-0004: T0 strategies are lowered to a neutral signal graph and executed by the host's strategy engine

これらのページは英語です。仕様は一つの言語で保つことで、一つのことだけを語ります。

Status: accepted (2026-10-09)

Context#

TTT already has a versioned strategy IR (strategy-graph, schema 1), a validator, a canonical identity hash, and one engine (StrategyHost) that runs a strategy identically in backtest, replay, demo and live, with lookahead prevention built into strategy_core::Features. The brief forbids a duplicate strategy engine without demonstrated need, and also requires the language core not to depend on TTT internals.

Decision#

  • strategy declarations in .tz compile to T0 signal graphs, a section of the T0 IR defined by T0 (t0-ir::strategy): nodes for constants, parameters, arithmetic, comparison, logic, transitions (cross above/below, rising, falling, previous, bars since), exposure tests and host feature nodes (operation ids taken from the host manifest, e.g. features.sma), plus ordered rules with one order action each.
  • T0 does not interpret signal graphs. A strategy value is data the program hands to a host operation (backtest.run); the TTT bridge translates it to strategy_graph::StrategyDefinition, runs TTT's validation (validate, check_dataset) and executes it with TTT's engine. Anything the host cannot represent is refused with a structured error, never approximated.
  • The meaning of transition nodes is specified in the language spec as evaluation-step semantics matching the host engine's contract (ttt.strategy-ir@1); an equivalence test in t0-host runs the same strategy written in .tz and built directly as a TTT graph and requires identical journals.

Alternatives#

  • Compile .tz straight to strategy_graph types -- makes t0-compiler depend on the terminal.
  • A T0 strategy interpreter -- a second engine with its own fill timing and lookahead rules; exactly what the brief and TTT's own design forbid.
  • Arbitrary T0 functions as strategies (called per event) -- powerful, but needs a lookahead-safe event API in the language and a per-event host callback; out of scope until a host contract for it exists. Recorded as a Phase 8 candidate.

Consequences#

  • Strategy expressiveness in v0 equals the host's node vocabulary.
  • A second host could execute the same graphs by implementing the same feature operations.