Systemicalpha

Standard Deviation

systemic:core-stdevStatisticsfunction1 cr

Inputs

NameTypeDescription
DatafloatarrayThe numerical series over which the cumulative standard deviation is computed.

Outputs

NameTypeDescription
StDevfloatarrayA 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.

σn=1n∑i=1n(xi−xˉn)2\sigma_n = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(x_i - \bar{x}_n)^2}

Where:

  • xix_i is the ii-th data point
  • xˉn\bar{x}_n is the cumulative mean of the first nn points
  • σn\sigma_n is the standard deviation at position nn

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
ApproachBehaviorBest For
RollingFixed memory, forgets old dataShort-term volatility signals
CumulativeNever forgets, stabilizes over timeHistorical 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:

AssetDaily 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 BehaviorWhat It Means
High valuesWide price swings; the asset is unpredictable
Low valuesTight clustering around the mean; stable behavior
Rising over timeRecent data is more volatile than earlier data
Falling / stabilizingThe 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.

ConditionInterpretation
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.

Position Size=Risk Budgetσ×Entry Price\text{Position Size} = \frac{\text{Risk Budget}}{\sigma \times \text{Entry Price}}

For a 10,000portfoliorisking210,000 portfolio risking 2% per trade (200), with an asset priced at $100 and σ = 3%:

Shares=2000.03×100=66.67≈66 shares\text{Shares} = \frac{200}{0.03 \times 100} = 66.67 \approx 66 \text{ shares}

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:

CombinationPurpose
STDEV + Moving AverageBuild custom Bollinger Bands
STDEV + PercentileRank current volatility vs. history
STDEV ÷ Mean (via DIV)Coefficient of Variation—normalized volatility
Price − Mean (via SUB), then ÷ STDEVZ-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 null for 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

LimitationImplication
Lagging indicatorBased purely on historical data; cannot predict future volatility
Assumes stationarityIf the asset's behavior fundamentally changes, old data may be misleading
Sensitive to outliersExtreme values (especially early in the series) have outsized impact
Not directionalA 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:

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.


Further Reading

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