5. Group and Strategy Signal Blending

In one Operator, strategies with the same run_freq and run_timing belong to the same Group; within each Group, a blender expression merges multiple strategy signals into one.

5.1. How Groups Are Formed

  • When adding strategies with run_freq and run_timing, they join an existing group if those match; otherwise a new group is created.

  • In backtest/live trading, scheduling is per Group: strategies in a Group run at the same time, then the blender merges their outputs.

5.2. Inspect Operator Groups

  • groups: Configuration and member strategies of each Group.

  • group_timing_table: run_freq and run_timing per group for verifying run schedules.

5.3. Blender Expressions

A blender merges signals from strategies in the same group (s0, s1, s2, … in add order). Common forms:

Expression

Meaning

s0

Use only the first strategy’s signal.

0.5*s0+0.5*s1

Equal-weight blend of two strategy signals.

s0*s1

Element-wise product (e.g., multiply timing positions).

(s0+s1)/2

Equivalent to 0.5*s0+0.5*s1.

Relation to signal_type: For PT, s0/s1 are usually positions in [0,1]; for PS, follow each strategy’s convention. Supported ops are scalars combined with s0/s1/… via +, −, ×, ÷.

5.4. Merging Multiple Groups

When an Operator has multiple Groups, group_merge_type controls how final signals are merged:

  • None: Framework default (usually the last or a designated group).

  • And: Logical AND across groups (e.g., all timing signals must be 1).

  • Or: Logical OR across groups.

5.5. Example

Typical equal-weight blend of two timing strategies:

op = qt.Operator(signal_type='PT', run_freq='d')
op.add_strategy('dma', run_freq='d', run_timing='open')
op.add_strategy('macd', run_freq='d', run_timing='open')
# 在 Group 的 blender 中设置为 0.5*s0+0.5*s1(具体 API 以当前版本为准)

After configuration, this Group computes dma and macd signals separately at each run step, then outputs the blended position via the blender.