- **Similar:** [StdDev](../stddev/StdDev.md), [IQR](../iqr/Iqr.md) | **Trading note:** Mean deviation (average absolute deviation); more robust than StdDev. Used in CCI calculation.
Mean Deviation (also known as Mean Absolute Deviation or Average Absolute Deviation) measures the average of the absolute deviations from the mean. Unlike Standard Deviation, it does not square the deviations, making it more robust to outliers and more intuitive to interpret.
## Historical Context
Mean Deviation was one of the earliest measures of dispersion, predating Standard Deviation. Karl Pearson famously argued for the superiority of Standard Deviation in the early 20th century due to its mathematical tractability, but Mean Deviation has seen renewed interest in robust statistics and financial applications. It is a core component of the Commodity Channel Index (CCI), introduced by Donald Lambert in 1980.
## Architecture & Physics
`MeanDev` uses a sliding window (RingBuffer) to maintain the last `N` data points. For each update, it calculates the arithmetic mean and then averages the absolute deviations from that mean across the window.
### Key Design Principles
* **O(N) per update**: Since the mean changes with each new data point, the absolute deviations must be recalculated across the window.
* **Circular Buffer**: Uses a ring buffer of size `Period` for efficient sliding window management.
* **Robustness**: Less sensitive to outliers than variance-based measures because deviations are not squared.
O(N) per update — no O(1) formulation for mean absolute deviation (unlike variance). The abs() required for each deviation prevents the running-sum trick.
| Metric | Score | Notes |
| :--- | :--- | :--- |
| **Throughput** | Moderate | O(N) per update for deviation calculation. |
| **Allocations** | 0 | Zero-allocation hot path with ring buffer. |
| **Complexity** | O(N) | Must iterate window for absolute deviations. |
| **Accuracy** | High | Straightforward calculation with no numerical pitfalls. |