Files
QuanTAlib/lib/errors/rae/Rae.md
T
Miha Kralj 35a6702b06 fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
2026-03-10 18:38:23 -07:00

5.3 KiB

RAE: Relative Absolute Error

Property Value
Category Error Metric
Inputs Actual, Predicted (dual series)
Parameters period
Outputs Single series (Rae)
Output range \geq 0
Warmup period bars

TL;DR

  • Relative Absolute Error (RAE) measures the total absolute error of predictions relative to the total absolute error of a simple baseline predictor ...
  • Parameterized by period.
  • Output range: \geq 0.
  • Requires period bars of warmup before first valid output (IsHot = true).
  • Validated against TA-Lib, Skender, and Tulip reference implementations where available.

"How much better than just guessing the mean? RAE gives you the ratio."

Relative Absolute Error (RAE) measures the total absolute error of predictions relative to the total absolute error of a simple baseline predictor that always predicts the mean of actual values. This provides a normalized performance metric.

Architecture & Physics

RAE computes a ratio of summed absolute errors. The numerator is the sum of absolute errors between actual and predicted values. The denominator is the sum of absolute errors between actual values and their mean (the naive mean-predictor baseline).

Interpretation Guide

RAE Value Interpretation
RAE < 1 Predictions are better than mean predictor
RAE = 1 Predictions equal mean predictor performance
RAE > 1 Predictions are worse than mean predictor
RAE = 0 Perfect predictions

The baseline captures how variable the data is. For highly variable data, a larger absolute error is expected from any predictor.

Mathematical Foundation

1. Absolute Error

e_t = |y_t - \hat{y}_t|

2. Baseline Error (vs Mean)

b_t = |y_t - \bar{y}|

where \bar{y} is the rolling mean of actual values.

3. Relative Absolute Error

\text{RAE} = \frac{\sum_{t=1}^{n} |y_t - \hat{y}_t|}{\sum_{t=1}^{n} |y_t - \bar{y}|}

Performance Profile

Operation Count (Streaming Mode)

O(1) per bar. Single-pass scalar transformation of (actual, forecast) pair; no lookback window required.

Operation Count Cost (cycles) Subtotal
Error computation (subtract, abs/square/log) 1-3 ~3-8 cy ~5-15 cy
Running accumulator update (EMA or sum) 1 ~4 cy ~4 cy
Total 2-4 ~9-19 cycles

Streaming update requires only the current actual/forecast pair and running state. ~10-15 cycles/bar typical.

Batch Mode (SIMD Analysis)

Operation Vectorizable? Notes
Element-wise error computation Yes Independent per bar; fully vectorizable with Vector<double>
Reduction (sum/mean) Yes Parallel reduction; AVX2 gives 4x speedup
Log/exp components Partial Transcendental ops; polynomial approx for SIMD

Batch SIMD: 4x-8x speedup for large windows. ~3-5 cy/bar amortized in vectorized batch mode.

Metric Score Notes
Throughput ~40 ns/bar Three running sums maintained
Allocations 0 Zero-allocation implementation
Complexity O(1) Constant time per update
Accuracy 9/10 Clear baseline comparison
Timeliness 7/10 Rolling window introduces lag
Robustness 9/10 Handles edge cases well

Common Pitfalls

Flat Series Problem

When all actual values in the window are identical, the mean equals every value, making the baseline error zero. The implementation returns 1.0 in this case (equivalent to mean predictor performance).

Rolling Mean Updates

The baseline error is calculated against the rolling mean, which updates each tick. This means historical baseline errors aren't static: they would change if recalculated with the new mean. The implementation stores instantaneous baseline errors for O(1) performance.

Different from R²

RAE and R² (coefficient of determination) are related but distinct: <<<<<<< HEAD

d493bfd42f

  • RAE uses absolute errors (L1 norm)
  • R² uses squared errors (L2 norm)
  • Both use mean-predictor as baseline

Usage

// Create RAE calculator with period 14
var rae = new Rae(14);

// Stream values
var result = rae.Update(actual, predicted);
Console.WriteLine($"RAE: {result.Value:F4}");
// RAE < 1 = better than mean, RAE > 1 = worse than mean

// Batch calculation
var raeSeries = Rae.Calculate(actualSeries, predictedSeries, 14);

// Zero-allocation span version
Rae.Batch(actualSpan, predictedSpan, outputSpan, 14);
Metric Error Type Baseline Range Units
RAE Absolute Mean predictor [0, ∞) Ratio
RSE Squared Mean predictor [0, ∞) Ratio
Squared Mean predictor (-∞, 1] Coefficient
MASE Absolute Naive forecast [0, ∞) Ratio

RAE is preferable when:

  • You want robustness to outliers (absolute vs squared errors)
  • You need a ratio interpretation (< 1 is good, > 1 is bad)
  • The mean predictor is a relevant baseline for your domain