Systemicalpha

Average

systemic:core-avgStatisticsfunction1 cr

Inputs

NameTypeDescription
DatafloatarrayThe numerical series for which to compute the cumulative (running) average.

Outputs

NameTypeDescription
AveragefloatarrayThe running (cumulative) average series, where each position contains the mean of all input values from the start up to that position.

The Cumulative Average module computes the running mean of a series—at each position, it returns the average of all values from the start up to that point.

xˉn=1n∑i=1nxi\bar{x}_n = \frac{1}{n} \sum_{i=1}^{n} x_i

How It Works

flowchart TD
    subgraph Input["Input Series"]
        D["x1, x2, x3, ... xn"]
    end
    
    subgraph Process["Cumulative Calculation"]
        S1["Position 1: x1"]
        S2["Position 2: sum / 2"]
        S3["Position 3: sum / 3"]
        SN["Position n: sum / n"]
    end
    
    subgraph Output["Running Average"]
        R["avg1, avg2, avg3, ... avgn"]
    end
    
    D --> S1 --> S2 --> S3 --> SN --> R

Step-by-Step Example

PositionInput ValueCumulative SumRunning Average
1101010.0
2203015.0
3154515.0
4257017.5
53010020.0

The Stabilization Effect

As more data accumulates, each new value has less impact on the average.

After N ValuesNew Value WeightEffect
250%High sensitivity
1010%Moderate sensitivity
1001%Low sensitivity
10000.1%Nearly stable

Cumulative Average vs Moving Averages

AspectAVGSMAEMA
WindowAll dataFixed rollingWeighted decay
MemoryFull historyLimitedFading
SensitivityDecreasesConstantConstant
Best forBaselinesTrendsResponsive

The Philosophy of Averages

The arithmetic mean is perhaps humanity's oldest statistical tool—a beautifully simple idea that transforms a collection of observations into a single representative value. In finance, this simplicity belies profound implications.

"The arithmetic mean is a point of balance—the fulcrum where all deviations cancel out."

The cumulative average has a unique property: it remembers everything. Unlike rolling windows that forget old data, the cumulative average carries the weight of history. This makes it both a strength and a limitation:

  • Strength: Provides a stable, long-term reference point
  • Limitation: Slow to react to regime changes

Creative Application 1: The "Gravitational Pull" Trading Concept

Markets, like celestial bodies, often appear to have a gravitational center. The cumulative average can serve as this "gravitational mean"—a price level that exerts a psychological pull on market participants.

flowchart TD
    subgraph MarketPhysics["Market Gravity Concept"]
        PRICE["Current Price"]
        AVG["Cumulative Average<br/>(Gravitational Center)"]
        ABOVE["Price > Average<br/>Extension above equilibrium"]
        BELOW["Price < Average<br/>Compression below equilibrium"]
    end
    
    PRICE --> |"Distance from center"| AVG
    AVG --> ABOVE
    AVG --> BELOW
    ABOVE --> |"Pull back toward mean"| AVG
    BELOW --> |"Pull back toward mean"| AVG
    
    style AVG fill:#3498db,stroke:#fff,color:#fff

Research Insight: Studies on mean reversion suggest that extreme deviations from long-term averages tend to correct over time. The cumulative average, by definition, is the fairest baseline—it treats every historical price equally. This concept underpins strategies like pairs trading and statistical arbitrage.


Creative Application 2: Dollar-Cost Averaging Tracker

Dollar-cost averaging (DCA) is one of the most researched investment strategies, and the cumulative average is its natural companion. By tracking your average cost basis in real-time, you gain insight into whether you're currently buying at a premium or discount.

flowchart LR
    subgraph DCA["DCA Performance System"]
        BUY["Monthly Purchase"]
        PRICE["Current Price"]
        AVG["Cumulative Avg<br/>(Your Cost Basis)"]
        COMPARE{"Price vs Avg?"}
        PREMIUM["Buying at Premium ⚠️"]
        DISCOUNT["Buying at Discount ✓"]
    end
    
    BUY --> PRICE
    BUY --> AVG
    AVG --> COMPARE
    PRICE --> COMPARE
    COMPARE -->|"Price > Avg"| PREMIUM
    COMPARE -->|"Price < Avg"| DISCOUNT
MonthPriceYour Avg CostStatus
Jan$50$50.00—
Feb$45$47.50Buying at discount
Mar$60$51.67Buying at premium
Apr$40$48.75Buying at discount
May$55$50.00At breakeven

Key Insight: When current price is below your cumulative average, your next purchase improves your overall position more efficiently. This psychological framework helps investors stay disciplined during drawdowns—exactly when emotional selling is most tempting.


Practical Applications

1. Lifetime Performance Baseline

Track the lifetime average return of a strategy or portfolio. The stabilization effect means this baseline becomes increasingly reliable over time.

2. Fair Value Reference

Use the cumulative average of earnings, revenues, or other fundamentals as a "fair value" anchor.

3. Regime Detection

Compare current values to the cumulative average. Persistent deviations may signal regime changes:

  • Sustained above average: Expansion regime
  • Sustained below average: Contraction regime

Missing Data

Gaps in the input (a closed market, a missing data point) are gaps in the output — never zero. A missing slot emits None at that position; the running average simply skips it and resumes from the next observed value, so the average is always computed over bars that actually happened.

Edge Cases

ScenarioBehavior
Empty inputReturns empty output
Single valueReturns that value
Missing value (gap)Output at that position is None; the running average resumes from the next observed value, unaffected by the gap
All values missingEvery output position is None — no average exists yet
Live modeReturns the running average over the full served history as a single value; None when the current tick is missing or nothing has been observed yet

Further Reading

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5