Mean Absolute Deviation vs Standard Deviation
Master the key differences between MAD and SD for better statistical analysis and smarter trading decisions.
Volatility Measurement
Understand data dispersion
Outlier Sensitivity
Choose the right metric
Trading Applications
Practical implementation
The Formulas
Mean Absolute Deviation
Standard Deviation
Understanding MAD vs Standard Deviation in Trading
When analyzing trading performance and market volatility, two fundamental statistical measures emerge: Mean Absolute Deviation (MAD) and Standard Deviation (SD). While both quantify data dispersion, they handle outliers differently and serve distinct purposes in trading analysis. Understanding when to use each metric can dramatically improve your risk assessment and strategy evaluation.
What Are MAD and Standard Deviation?
Both metrics measure how spread out data points are from the mean, but they calculate this dispersion using different mathematical approaches that produce notably different results, especially with volatile or outlier-prone data.
Mean Absolute Deviation (MAD)
xᵢ = Each data point
μ = Mean of dataset
n = Number of observations
Standard Deviation (SD)
xᵢ = Each data point
μ = Mean of dataset
n = Number of observations
5 Key Differences Between MAD and SD
1. Outlier Sensitivity
The most critical difference lies in how each metric handles extreme values. Standard Deviation squares deviations, which amplifies the impact of outliers dramatically. MAD uses absolute values, treating all deviations proportionally.
Trading Example: Consider daily returns of 1%, 2%, 1.5%, 2%, and 15% (flash spike). The SD will be heavily influenced by the 15% outlier, potentially misrepresenting typical volatility. MAD provides a more stable measure of everyday price movement.
2. Mathematical Properties
Standard Deviation is differentiable and works seamlessly with statistical theory (normal distributions, confidence intervals). MAD is simpler mathematically but less amenable to advanced statistical inference. SD is the foundation for metrics like Sharpe Ratio and Bollinger Bands.
3. Computational Complexity
MAD is computationally simpler, requiring only absolute value operations. SD involves squaring and square root calculations, which can impact performance in high-frequency trading systems processing millions of calculations.
Performance Note: In backtesting systems analyzing thousands of trades, MAD calculations can be 15-20% faster than SD calculations, though modern computers make this difference negligible for most applications.
4. Interpretation and Scale
MAD is in the same units as your data and represents the average deviation. SD is also in the same units but typically larger than MAD due to the squaring effect. For normal distributions, SD ≈ 1.25 × MAD, providing a useful conversion benchmark.
5. Industry Adoption
Standard Deviation dominates finance due to its role in portfolio theory, options pricing (Black-Scholes), and risk management (VaR). MAD is gaining traction in robust statistics and machine learning applications where outlier resistance matters more than mathematical elegance.
Implementing MAD and SD in MQL5
Here's practical code to calculate both metrics and compare their behavior with real trading data:
// Calculate Mean Absolute Deviation
double CalculateMAD(double data[], int period)
{
if(period <= 0) return 0.0;
// Calculate mean
double sum = 0.0;
for(int i = 0; i < period; i++)
{
sum += data[i];
}
double mean = sum / period;
// Calculate sum of absolute deviations
double absDeviationSum = 0.0;
for(int i = 0; i < period; i++)
{
absDeviationSum += MathAbs(data[i] - mean);
}
return absDeviationSum / period;
}
// Calculate Standard Deviation
double CalculateSD(double data[], int period)
{
if(period <= 0) return 0.0;
// Calculate mean
double sum = 0.0;
for(int i = 0; i < period; i++)
{
sum += data[i];
}
double mean = sum / period;
// Calculate sum of squared deviations
double squaredDeviationSum = 0.0;
for(int i = 0; i < period; i++)
{
squaredDeviationSum += MathPow(data[i] - mean, 2);
}
return MathSqrt(squaredDeviationSum / period);
}
// Compare both metrics with example data
void OnStart()
{
// Example 1: Normal trading day returns (%)
double normalReturns[10] = {0.5, -0.3, 0.7, -0.4, 0.6, -0.2, 0.4, -0.5, 0.3, -0.1};
double mad1 = CalculateMAD(normalReturns, 10);
double sd1 = CalculateSD(normalReturns, 10);
Print("=== Normal Trading Day ===");
Print("MAD: ", DoubleToString(mad1, 4), "%");
Print("SD: ", DoubleToString(sd1, 4), "%");
Print("SD/MAD Ratio: ", DoubleToString(sd1/mad1, 2));
// Example 2: Day with flash crash outlier
double outlierReturns[10] = {0.5, -0.3, 0.7, -0.4, 0.6, -8.5, 0.4, -0.5, 0.3, -0.1};
double mad2 = CalculateMAD(outlierReturns, 10);
double sd2 = CalculateSD(outlierReturns, 10);
Print("\n=== Day With Flash Crash ===");
Print("MAD: ", DoubleToString(mad2, 4), "%");
Print("SD: ", DoubleToString(sd2, 4), "%");
Print("SD/MAD Ratio: ", DoubleToString(sd2/mad2, 2));
// Show impact of outlier
Print("\n=== Outlier Impact Analysis ===");
Print("MAD increased by: ", DoubleToString((mad2/mad1 - 1)*100, 1), "%");
Print("SD increased by: ", DoubleToString((sd2/sd1 - 1)*100, 1), "%");
// Recommendation based on data characteristics
double skewness = (sd2/mad2) / 1.25; // 1.25 is theoretical ratio for normal distribution
Print("\n=== Recommendation ===");
if(skewness > 1.2)
Print("Data has significant outliers - consider using MAD for robust analysis");
else if(skewness < 0.8)
Print("Data is more uniform than normal - SD may underestimate risk");
else
Print("Data is approximately normal - both metrics are suitable");
}
When to Use Each Metric
| Scenario | Use MAD | Use SD |
|---|---|---|
| Flash crashes / spikes | ✓ Recommended | Overstates risk |
| Sharpe Ratio calculation | Non-standard | ✓ Required |
| High-frequency data | ✓ More stable | Can be noisy |
| Normal market conditions | Both suitable | |
| Portfolio optimization | Limited theory | ✓ Industry standard |
| Quick volatility check | ✓ Faster compute | More precise |
Practical Trading Applications
Position Sizing with MAD
Use MAD for position sizing during volatile periods with frequent outliers. It provides a more stable risk estimate that won't cause you to dramatically reduce position sizes after single extreme events.
risk_per_trade = account_equity * 0.02;
volatility = CalculateMAD(recent_returns, 20);
position_size = risk_per_trade / volatility;
Stop Loss Placement with SD
Use Standard Deviation for stop loss placement in trending markets. The sensitivity to outliers helps you set stops that account for worst-case scenarios and avoid premature exits.
volatility = CalculateSD(price_changes, 14);
stop_distance = 2.0 * volatility; // 2 SD rule
stop_loss = entry_price - stop_distance;
EA Performance Monitoring
Calculate both metrics monthly to detect market regime changes. A widening gap between SD and MAD signals increasing outlier frequency, potentially indicating market stress or strategy degradation.
Real-World Example: Comparing Metrics
Let's analyze how MAD and SD behave differently with actual trading scenarios:
Scenario Analysis
Case 1: Steady Trend (Low Volatility)
Daily returns: 0.3%, 0.4%, 0.2%, 0.5%, 0.3%, 0.4%, 0.2%
MAD: 0.11%
Represents typical deviation
SD: 0.13%
Similar to MAD (SD/MAD ≈ 1.18)
Both metrics agree - use either for analysis
Case 2: News Spike Day
Daily returns: 0.3%, 0.4%, -5.2%, 0.5%, 0.3%, 0.4%, 0.2%
MAD: 0.89%
Moderate increase (8x)
SD: 2.07%
Large increase (16x)
SD heavily penalizes outlier - MAD better represents "normal" volatility
Case 3: High Volatility Market
Daily returns: 1.2%, -1.8%, 2.1%, -1.5%, 1.7%, -2.0%, 1.4%
MAD: 1.54%
Higher base volatility
SD: 1.73%
Still proportional (SD/MAD ≈ 1.12)
Both capture volatility well - consistent ratio suggests normal distribution
Advanced Implementation: Hybrid Approach
For robust trading systems, combine both metrics to get comprehensive risk assessment:
// Hybrid volatility assessment for EA risk management
struct VolatilityMetrics
{
double mad;
double sd;
double ratio; // SD/MAD ratio
string regime; // Market regime classification
double adjustedVol; // Risk-adjusted volatility metric
};
VolatilityMetrics AssessVolatility(double returns[], int period)
{
VolatilityMetrics metrics;
// Calculate both metrics
metrics.mad = CalculateMAD(returns, period);
metrics.sd = CalculateSD(returns, period);
// Calculate ratio (normal distribution ≈ 1.25)
if(metrics.mad > 0)
metrics.ratio = metrics.sd / metrics.mad;
else
metrics.ratio = 0;
// Classify market regime based on ratio
if(metrics.ratio > 1.5)
{
metrics.regime = "High Outlier Activity";
metrics.adjustedVol = metrics.mad * 1.3; // Use MAD with buffer
}
else if(metrics.ratio > 1.25)
{
metrics.regime = "Normal Distribution";
metrics.adjustedVol = metrics.sd; // Use SD (standard approach)
}
else if(metrics.ratio > 1.0)
{
metrics.regime = "Low Volatility/Uniform";
metrics.adjustedVol = metrics.sd * 1.1; // Slightly increase SD estimate
}
else
{
metrics.regime = "Anomalous";
metrics.adjustedVol = MathMax(metrics.mad, metrics.sd);
}
return metrics;
}
// Apply hybrid approach to position sizing
double CalculatePositionSize(double accountEquity, double riskPercent)
{
// Get recent returns
double returns[50];
int period = 50;
// Populate returns array (simplified - in real code, fetch from history)
for(int i = 0; i < period; i++)
{
// Your code to get actual return data
returns[i] = 0.0; // Placeholder
}
// Assess volatility using hybrid approach
VolatilityMetrics vol = AssessVolatility(returns, period);
// Calculate risk-adjusted position size
double riskAmount = accountEquity * (riskPercent / 100.0);
double positionSize = riskAmount / vol.adjustedVol;
// Log decision
Print("=== Volatility Assessment ===");
Print("MAD: ", DoubleToString(vol.mad, 4), "%");
Print("SD: ", DoubleToString(vol.sd, 4), "%");
Print("Ratio: ", DoubleToString(vol.ratio, 2));
Print("Regime: ", vol.regime);
Print("Adjusted Volatility: ", DoubleToString(vol.adjustedVol, 4), "%");
Print("Position Size: ", positionSize, " lots");
return positionSize;
}
Common Mistakes to Avoid
❌ Using SD blindly with outlier-prone data
Standard Deviation can overstate risk during flash crashes, leading to overly conservative position sizing and missed opportunities.
❌ Ignoring the SD/MAD ratio
The ratio between these metrics tells you about data distribution. Ignoring it means missing early warning signs of regime changes.
❌ Using MAD for standard financial metrics
Sharpe Ratio, Value at Risk, and other industry-standard metrics require Standard Deviation. Don't substitute MAD unless you're creating custom metrics.
❌ Insufficient sample size
Both metrics need adequate data (minimum 30-50 observations) to be meaningful. Too few data points produce unreliable volatility estimates.
Key Takeaways
-
MAD is more robust to outliers, making it ideal for volatile markets with flash events
-
Standard Deviation is required for industry-standard metrics like Sharpe Ratio and VaR
-
The SD/MAD ratio (normally ~1.25) indicates data distribution and outlier presence
-
Hybrid approaches combining both metrics provide the most robust risk assessment
-
Monitor both metrics over time to detect market regime changes and strategy degradation
"The best traders don't rely on a single metric. Understanding when to use MAD versus SD separates sophisticated risk managers from the rest."
Quick Reference Guide
Choose MAD When:
- • Data contains frequent outliers
- • You need robust volatility estimates
- • Flash crashes distort your analysis
- • Working with high-frequency data
- • Position sizing in volatile markets
Choose SD When:
- • Calculating Sharpe Ratio or Sortino Ratio
- • Portfolio optimization and theory
- • Data follows normal distribution
- • Industry-standard reporting required
- • Worst-case scenario planning
Remember: SD/MAD Ratio Interpretation
Ratio < 1.0
Anomalous - investigate data
Ratio ≈ 1.25
Normal distribution - ideal
Ratio > 1.5
Heavy outliers - use MAD