Systemicalpha

Lag

systemic:core-lagMathfunction1 cr

Inputs

NameTypeDescription
PeriodsintegerChoose a nonnegative whole number of earlier **usable numeric readings**. **1** selects the previous such reading at each current numeric position; **5** selects the fifth earlier one. This counts readings rather than calendar days or hours, so gaps can make the elapsed time longer than expected.
SeriesfloatarrayConnect the numeric values you want to look back through: prices, returns, indicator readings, or another module's output. **Shifted** keeps this series' numeric unit and aligns with its positions.

Outputs

NameTypeDescription
ShiftedfloatarrayThe earlier numeric value selected by **Periods**, in the same unit and at the same positions as **Series**. Compare it with the current input to examine change, or use it as one side of another calculation.

A price rises today—but compared with which earlier price? Yesterday's? The last available reading before a data gap? Lag brings an earlier numeric observation alongside the current one, so you can compare them in the rest of your system.

Choose Periods, a nonnegative whole number of earlier usable readings. Lag follows the observations in the connected series, not elapsed clock time, and never uses a reading from the future. With Periods = 0, it keeps the current numeric value. In a complete series, this is the familiar lag by observations; gaps change what counts as the previous observation here.

Lag⁡k(X)t=xj−k,j=number of usable numeric readings through position t.\operatorname{Lag}_{k}(X)_t=x_{j-k}, \qquad j=\text{number of usable numeric readings through position }t.

Here (k) is Periods and (x_j) is the (j)th usable numeric reading. The formula applies when the current position has such a reading and at least (k) earlier ones exist. Otherwise the output is null.

Walk through a gap

Set Periods = 1 for the small arithmetic series below. These are illustrative numbers, not market prices.

PositionSeriesShiftedWhat happened
110nullNo earlier usable reading.
2nullnullNo observation at this position.
3NaNnullAn observation exists, but has no usable number.
4010Zero is the next usable reading; its predecessor is 10.
5200The preceding usable reading is zero.
6NaNnullThis position supplies no numeric reading.
7nullnullThis position has no stored observation.
83020The preceding usable reading is 20.

A null gap and NaN are different source events: null means no stored observation at that position; NaN is a stored observation without a usable numeric value. Neither counts toward the numeric lookback, and both produce null at their own output positions. Zero counts. That is why position 5 receives zero, not 10.

With Periods = 2, position 5 would receive 10: the second earlier usable reading. With Periods = 0, each usable numeric reading stays at its own position; null and NaN positions still produce null. A larger setting leaves more initial positions null while enough readings accumulate.

If you think in days or hours, inspect the input frequency first. On a complete daily trading series, five usable observations may correspond to five trading sessions. Across a missing reading they may span longer. If a slower connected series has been aligned to a faster timeline by repeating its latest available value, each repeated numeric value counts as a reading here.

Questions you can build

How much did the latest reading change?

Connect a price or indicator to Lag → Series with Periods = 1. Put the original series in Subtract → First Value and Shifted in Subtract → Second Value. The result is an absolute change in the same unit: dollars for a dollar price, percentage points for a percentage reading. For a relative change, divide that difference by Shifted only when Shifted is nonzero. A null comparison tells you that the required numeric reading is unavailable.

Try this: Plot an indicator next to its one-period shifted value. When they part ways, inspect the original data. Did the indicator really move, or did a gap make the comparison span more time than expected?

Does a weekly comparison mean a calendar week?

On a daily series, Periods = 5 compares with the fifth earlier usable reading. This can approximate a trading-week comparison when the series is complete, but the setting does not promise five calendar days. Holidays, absent readings, and earlier alignment all affect the elapsed time between the two values.

Try this: Compare a five-period Lag on a complete daily series and on one with missing observations. Check the dates behind the shifted values before interpreting a five-period change.

Did one series move first?

Shift a return series with Lag and compare it with a second return series using Correlation Coefficient: connect Shifted to its First Dataset and the second return series to Second Dataset. Then compare Periods = 0, 1, 2 with the same correlation window and repeat the experiment on a different historical interval. This is a lagged-correlation question, not evidence of causation or proof that a signal arrives soon enough to trade.

Try this: Examine one- and two-period shifts separately. If a relationship appears at only one setting or only one sample, what does that suggest about its stability?

Reading Shifted

Lag keeps the numeric unit of Series and the same positions as the input. A missing current reading or too little earlier numeric history produces null at that position. In live execution, only the newest position's result is returned, even if it is null. Lag can use only the history supplied to it; an earlier reading outside that history is unavailable.

© 2026 WanoLabs. All rights reservedAlpha build v0.1.5