Strategy¶
A strategy decides what to do with signals. RulesStrategy composes entry,
exit, and risk rules; StrategyModel is the base contract for custom
strategies, and Observation is the input passed to each decision.
Rules strategy¶
signalflow.RulesStrategy
dataclass
¶
Bases: Strategy
Turn validated signals into open/close intents via fixed rules.
Rules¶
signalflow.Entry
dataclass
¶
Entry(size_pct: float = 0.1, min_p_success: float = 0.0, max_positions: int = 1000, max_positions_per_pair: int | None = None)
Position entry policy.
When a validator is present (the signal frame carries a p_success column)
and min_p_success is positive, a null p_success counts as not validated
and the entry is skipped. Without a validator column, entries open unchanged.
max_positions caps concurrent open positions global across pairs.
max_positions_per_pair (when set) caps them per pair; None disables it.
signalflow.Exit
dataclass
¶
Take-profit / stop-loss exit policy.
signalflow.Risk
dataclass
¶
Risk(max_drawdown: float = 1.0, max_positions: int = 1000, max_notional_per_pair: float = 1.0, kill_switch_path: str | None = None)
Clip intents against drawdown, position, and notional limits.
max_positions caps concurrent open positions global across pairs.
clip ¶
clip(intents: list[Intent], portfolio: PortfolioSnapshot, peak_equity: float, raise_on_trip: bool = False) -> list[Intent]
Clip intents; with raise_on_trip a tripped kill switch halts loudly instead of dropping.
Source code in src/signalflow/strategy/risk.py
Strategy contract¶
signalflow.StrategyModel ¶
Bases: Protocol
signalflow.Observation
dataclass
¶
Observation(ts: object, signals: DataFrame, portfolio: PortfolioSnapshot, mandate: dict = dict(), schema_version: int = OBSERVATION_SCHEMA_VERSION)
Validated signals + portfolio + market state + constraints at one ts.
from_dict
classmethod
¶
Rebuild an Observation, rejecting a schema version it was not trained on.
Source code in src/signalflow/strategy/observation.py
to_dict ¶
Serialize to a JSON-able dict tagged with the schema version.
Source code in src/signalflow/strategy/observation.py
to_prompt_context ¶
JSON-able structured context for an LLM strategy (no raw candles).
Source code in src/signalflow/strategy/observation.py
to_vector ¶
Stable fixed-length numeric summary for RL policies.