Average
systemic:core-avgStatisticsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Data | floatarray | The numerical series for which to compute the cumulative (running) average. |
Outputs
| Name | Type | Description |
|---|---|---|
| Average | floatarray | The 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.
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
| Position | Input Value | Cumulative Sum | Running Average |
|---|---|---|---|
| 1 | 10 | 10 | 10.0 |
| 2 | 20 | 30 | 15.0 |
| 3 | 15 | 45 | 15.0 |
| 4 | 25 | 70 | 17.5 |
| 5 | 30 | 100 | 20.0 |
The Stabilization Effect
As more data accumulates, each new value has less impact on the average.
| After N Values | New Value Weight | Effect |
|---|---|---|
| 2 | 50% | High sensitivity |
| 10 | 10% | Moderate sensitivity |
| 100 | 1% | Low sensitivity |
| 1000 | 0.1% | Nearly stable |
Cumulative Average vs Moving Averages
| Aspect | AVG | SMA | EMA |
|---|---|---|---|
| Window | All data | Fixed rolling | Weighted decay |
| Memory | Full history | Limited | Fading |
| Sensitivity | Decreases | Constant | Constant |
| Best for | Baselines | Trends | Responsive |
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
| Month | Price | Your Avg Cost | Status |
|---|---|---|---|
| Jan | $50 | $50.00 | — |
| Feb | $45 | $47.50 | Buying at discount |
| Mar | $60 | $51.67 | Buying at premium |
| Apr | $40 | $48.75 | Buying at discount |
| May | $55 | $50.00 | At 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
| Scenario | Behavior |
|---|---|
| Empty input | Returns empty output |
| Single value | Returns 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 missing | Every output position is None — no average exists yet |
| Live mode | Returns 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 |