create_rule
Adds systematic trading rules to a portfolio for day-by-day evaluation on FLOW forward paths. Supports signal rules for trend-following and binary rules for risk overrides.
Instructions
Add a systematic trading rule to a portfolio. Rules are evaluated day-by-day on FLOW forward paths during forward_test_rules — not backtested on history.
TWO RULE TYPES: • Signal rules (action.type='signal_weight') — continuous indicator → proportional position. For CTAs and trend-followers. • Binary rules (all other action types) — trigger fires → discrete weight change. For risk overlays, hard stops, regime gates.
Use signal rules (priority 0) for the core strategy; binary rules (priority 1+) for risk overrides.
── SIGNAL RULE ── trigger: {indicator, asset, params} ← no operator/threshold action: {type:'signal_weight', asset, normalizer, max_weight, min_weight} normalizer = typical signal magnitude; clip(signal/normalizer, -1, 1) → position weight = scaledmax_weight if scaled≥0 else scaled|min_weight|
trigger={indicator:'macd_line', asset:'CL=F', params:{fast:12, slow:60}} action={type:'signal_weight', asset:'CL=F', normalizer:2.0, max_weight:0.6, min_weight:-0.3}
trigger={indicator:'z_score', asset:'ZN=F', params:{window:60}} action={type:'signal_weight', asset:'ZN=F', normalizer:2.0, max_weight:0.5, min_weight:-0.5}
── BINARY RULE ── trigger: {indicator, asset, params, operator, threshold} OR {combinator:'all'|'any', conditions:[...]} indicators: raw | moving_average | ema | rsi | bollinger_upper | bollinger_lower | bollinger_width | macd_line | macd_signal | rolling_std | rolling_volatility | rate_of_change | z_score asset: portfolio assets OR conditioning factors ('^VIX', 'DX-Y.NYB', 'T10Y2Y', 'ZN=F', ...) operator: '>' | '<' | '>=' | '<=' | '==' | 'crosses_above' | 'crosses_below' action: exit | set_weight (exact value, negative=short) | scale_weight (multiplier) | reverse
trigger={indicator:'rsi', asset:'CL=F', params:{period:14}, operator:'>', threshold:70} action={type:'exit', asset:'CL=F'}
trigger={combinator:'all', conditions:[ {indicator:'raw', asset:'^VIX', params:{}, operator:'>', threshold:30}, {indicator:'rsi', asset:'CL=F', params:{period:14}, operator:'>', threshold:65}]} action={type:'scale_weight', asset:'CL=F', value:0.5}
IMPORTANT: Trigger assets can be portfolio assets OR conditioning factors (VIX, DXY, etc.). For forward_test_rules, the FLOW model must include ALL referenced features — missing features cause rules to silently fail. For evaluate_rules (live data), any feature in training_data works with no model dependency.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Short descriptive name for the rule | |
| action | Yes | Signal: {type:'signal_weight', asset, normalizer, max_weight, min_weight} OR binary: {type:'exit'|'set_weight'|'scale_weight'|'reverse', asset, value?} | |
| trigger | Yes | For BINARY rules: single condition {indicator,asset,params,operator,threshold} or multi-condition {combinator:'all'|'any', conditions:[...]}. For SIGNAL rules: just {indicator,asset,params} — no operator or threshold needed. | |
| priority | No | Evaluation order when multiple rules fire (lower = first, default 0) | |
| is_active | No | Whether the rule is active (default false) | |
| description | No | Optional longer description | |
| portfolio_id | Yes | Portfolio UUID |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |