Systemicalpha

Subtract

systemic:core-subMathfunction1 cr

Inputs

NameTypeDescription
First ValuefloatarrayThe value to subtract **from** — the left-hand side of the subtraction.
Second ValuefloatarrayThe value to subtract — the right-hand side of the subtraction.

Outputs

NameTypeDescription
DifferencefloatarrayThe element-wise difference of the two input series (First − Second).

Differencei=Ai−Bi\text{Difference}_i = A_i - B_i

Computes element-wise subtraction of two numeric series. Fundamental for spreads, price changes, and deviations.

First (A)Second (B)Difference
1008020
80100-20
50500

Missing Data

If either input is missing (null) at a position — a data gap or a closed-market day — the difference at that position is null. The module never invents a value for missing data: a gap in your inputs stays a gap in the output.

FirstSecondDifference
100nullnull
null80null
nullnullnull

Separate from missing data, a result can be mathematically undefined: subtracting +∞ from +∞ (or −∞ from −∞) has no answer, so that position is also null even though both inputs exist. Any other infinite result passes through unchanged.

In live execution the module returns exactly one datapoint — the newest position — which is null when it cannot be determined.


Input Alignment

Systemic automatically aligns inputs before subtraction:

ScenarioWhat Happens
Different lengthsShorter series padded by repeating last value
Different frequenciesLower-frequency upsampled to match higher
One constantConstant expanded to match series length

Example: BTC (1h) − ETH (15m) → BTC upsampled to 15m intervals first.


Order Matters

Subtraction is not commutative: A − B ≠ B − A

InputsResultInterpretation
Price − SMA+20Price is 20 above average
SMA − Price-20Average is 20 below price

Choose input order based on your desired sign interpretation.


Practical Example: Price Deviation from Moving Average

Subtracting a 20-period SMA from price creates a deviation indicator:

Use CaseInterpretation
Price − SMA > 0Price above average (potentially overbought)
Price − SMA < 0Price below average (potentially oversold)
Price − SMA → 0Reverting to mean

This deviation, when plotted over time, reveals momentum shifts and potential reversal zones. Many mean-reversion strategies use this as a foundation, triggering entries when deviation exceeds historical thresholds.


  • ADD — Element-wise addition
  • DIV — Normalize difference (e.g., percentage deviation)
  • ABS — Absolute deviation (unsigned distance)
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5