Standard Deviation
systemic:core-stdevStatisticsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Data | floatarray | The numerical series over which the cumulative standard deviation is computed. |
Outputs
| Name | Type | Description |
|---|---|---|
| StDev | floatarray | A time series of cumulative (expanding) standard deviation values, where each position reflects the volatility of all data from the start up to that point. |
The Standard Deviation module computes the cumulative dispersion of data points from their evolving mean. Unlike a rolling window calculation, this module produces an expanding standard deviation—each output value reflects the variability of all data points from the beginning of the series up to that point.
Where:
- is the -th data point
- is the cumulative mean of the first points
- is the standard deviation at position
Why Cumulative (Expanding) Standard Deviation?
Most traders are familiar with rolling standard deviation—a fixed-length window that slides forward. This module takes a different approach: at each point, it measures how spread out all prior data has been.
flowchart LR
subgraph Rolling["Rolling StDev (Window = 3)"]
R1["Point 5: uses points 3-5"]
R2["Point 6: uses points 4-6"]
R3["Point 7: uses points 5-7"]
end
subgraph Expanding["Cumulative StDev (This Module)"]
E1["Point 5: uses points 1-5"]
E2["Point 6: uses points 1-6"]
E3["Point 7: uses points 1-7"]
end
| Approach | Behavior | Best For |
|---|---|---|
| Rolling | Fixed memory, forgets old data | Short-term volatility signals |
| Cumulative | Never forgets, stabilizes over time | Historical context, regime detection |
The cumulative approach answers: "How volatile has this asset been since I started observing it?"
How It Works
flowchart TD
subgraph Input["Input Data"]
P["Series of Values (prices, returns, indicators)"]
end
subgraph Process["At Each Point n"]
M["Calculate cumulative mean of points 1...n"]
D["Compute squared deviations from mean"]
V["Average the squared deviations"]
S["Take square root → σ_n"]
end
subgraph Output["Output Series"]
SD["σ_1, σ_2, σ_3, ... σ_n"]
end
P --> M --> D --> V --> S --> SD
Key property: Early values in the output fluctuate more; as more data accumulates, the cumulative standard deviation stabilizes toward the true long-term volatility.
Real-World Volatility Comparison
Different assets exhibit dramatically different volatility profiles. Using daily return data from June–December 2024:
| Asset | Daily StDev (σ) | Annualized Volatility |
|---|---|---|
| SPY (S&P 500 ETF) | 0.85% | ~13.4% |
| GLD (Gold ETF) | 1.02% | ~16.1% |
| NVDA (Nvidia) | 3.32% | ~52.7% |
| BTC (Bitcoin) | 3.73% | ~59.3% |
Annualized volatility = Daily σ × √252 (trading days per year)
This illustrates why position sizing and risk management cannot be one-size-fits-all: holding the same dollar amount in BTC exposes you to roughly 4× the volatility of SPY.
Interpreting the Output
| STDEV Behavior | What It Means |
|---|---|
| High values | Wide price swings; the asset is unpredictable |
| Low values | Tight clustering around the mean; stable behavior |
| Rising over time | Recent data is more volatile than earlier data |
| Falling / stabilizing | The asset is settling into a consistent range |
The Stabilization Effect
Because this is cumulative, a single volatile day early in your series has a large impact. As your series grows, that same day's influence diminishes—the law of large numbers at work.
xychart-beta
title "Cumulative StDev Stabilization (Conceptual)"
x-axis "Data Points" [10, 50, 100, 200, 500]
y-axis "σ Sensitivity to New Point" 0 --> 15
line "Impact of One Outlier (%)" [10, 4, 2.5, 1.5, 0.8]
Trading Applications
1. Volatility Regime Detection
The cumulative standard deviation provides a baseline for "normal" volatility. When short-term volatility (from another module) significantly exceeds this baseline, you may be entering a new regime.
| Condition | Interpretation |
|---|---|
| Short-term σ >> Cumulative σ | Market stress or breakout |
| Short-term σ ≈ Cumulative σ | Normal conditions |
| Short-term σ << Cumulative σ | Unusual calm; potential squeeze |
2. Risk-Adjusted Position Sizing
A foundational principle: size positions inversely to volatility.
For a 200), with an asset priced at $100 and σ = 3%:
Higher volatility → fewer shares. This keeps your dollar risk consistent across assets.
3. Historical Volatility Benchmarking
Comparing cumulative volatility across different periods helps identify structural changes:
- "Is this asset more volatile in 2024 than it was in 2020-2023?"
- "Has volatility permanently shifted after a major event?"
Combining with Other Modules
Standard deviation is rarely used alone. Consider these combinations:
| Combination | Purpose |
|---|---|
| STDEV + Moving Average | Build custom Bollinger Bands |
| STDEV + Percentile | Rank current volatility vs. history |
| STDEV ÷ Mean (via DIV) | Coefficient of Variation—normalized volatility |
| Price − Mean (via SUB), then ÷ STDEV | Z-Score—see how many σ from the mean |
Live Mode Behavior
When running in live mode (real-time single-point execution), this module returns a single value: the standard deviation of the entire observed history at that moment. This is equivalent to the final value of the cumulative series — null when the newest bar is missing or fewer than 2 observations have been seen yet.
Missing Data
A closed-market bar, a data gap, or an upstream null is never treated as zero — a fabricated zero here would read as "zero risk" and cause a division-by-zero downstream (e.g. risk_budget / σ position sizing). Instead:
- The output at a missing bar's position is
null, not a carried-forward value - Missing bars are skipped, not zero-filled: the cumulative mean/variance calculation resumes cleanly at the next observed bar
- The output is
nullfor the first observed bar too — a single observation has no defined spread — and only becomes a real number once at least 2 observed bars exist
Limitations to Consider
| Limitation | Implication |
|---|---|
| Lagging indicator | Based purely on historical data; cannot predict future volatility |
| Assumes stationarity | If the asset's behavior fundamentally changes, old data may be misleading |
| Sensitive to outliers | Extreme values (especially early in the series) have outsized impact |
| Not directional | A 5% gain and 5% loss contribute equally to volatility |
The Bigger Picture: Volatility in Markets
Standard deviation is the cornerstone of modern finance. It underpins:
- Modern Portfolio Theory — Risk-return optimization
- Value at Risk (VaR) — Quantifying potential loss
- Sharpe Ratio — Returns per unit of risk
- Options Pricing — Implied vs. realized volatility
Understanding and measuring volatility isn't just about avoiding risk—it's about pricing risk correctly and finding opportunities where the market has mispriced it.