- **Similar:** [StdDev](../stddev/StdDev.md), [MeanDev](../meandev/MeanDev.md) | **Trading note:** Rolling variance; squared deviation from mean. Foundation of portfolio risk calculations.
Variance measures how far a set of numbers is spread out from their average value. In finance, it is a key measure of volatility and risk.
## Historical Context
Variance is a fundamental concept in statistics, formalized by Ronald Fisher in 1918. In finance, it gained prominence with Modern Portfolio Theory (Markowitz, 1952), where it serves as the standard measure of risk.
## Architecture & Physics
The Variance indicator uses a sliding window (RingBuffer) to maintain the last `N` data points. It calculates the variance using an O(1) running sum of squares algorithm, ensuring constant time complexity regardless of the period length.
| **Allocations** | 0 | Zero-allocation in hot path. |
| **Complexity** | O(1) | Constant time update. |
| **Accuracy** | 9 | High accuracy, though running sums can accumulate floating point errors over very long periods (mitigated by periodic resync if needed, though not strictly implemented here as window is finite). |