Calculate robust pairwise scale using Qn and Sn, distinguish raw from normal-calibrated estimates, and handle median conventions, ties and breakdown limits.
Qn and Sn scale estimators
Qn and Sn are robust estimators of scale built from pairwise absolute differences between observations. They measure spread without first estimating a centre. In quant work, they can provide a baseline scale for return or residual diagnostics when a few extreme observations would dominate the standard deviation. That resistance does not establish that a market jump is an error: a genuine loss still belongs in the risk analysis.
Both were introduced by Rousseeuw and Croux as alternatives to the median absolute deviation, or MAD. The distinction is structural. MAD measures distances from the sample median; Qn and Sn compare observations with one another. A high breakdown point describes resistance to contamination, rather than accuracy for every financial distribution.
Qn selects one ordered pairwise distance
For n≥2 finite real observations, collect the (2n) distances ∣xi−xj∣ with i<j, retaining repeated distances. Sort them and define
h=⌊2n⌋+1,k=(2h),Qraw={∣xi−xj∣:i<j}(k).
The subscript (k) means the kth smallest distance, using one-based ranks. This rank approaches the lower quartile of the pairwise distances as the sample grows. It is not an instruction to call an arbitrary interpolated 25th-percentile routine, particularly in a small sample. The robustbase Qn documentation states this rank explicitly.
Consider the fictional observations
x=(0,1,2,3,100).
Here h=3 and k=3. The ten sorted distances are
1,1,1,2,2,3,97,98,99,100.
The third smallest is 1, so Qraw=1. The four distances involving 100 lie at the upper end and do not determine the selected rank.
Sn takes a median of within-observation medians
For odd n, first take the median distance from each observation to all n observations, including itself. Then take the median of those n answers:
Sraw=mediani{medianj∣xi−xj∣}.
For the same five observations:
Observation
Sorted distances, including self
Inner median
0
0, 1, 2, 3, 100
2
1
0, 1, 1, 2, 99
1
2
0, 1, 1, 2, 98
1
3
0, 1, 2, 3, 97
2
100
0, 97, 98, 99, 100
98
The median of 2,1,1,2,98 is 2, giving Sraw=2.
For even n, the convention matters. The usual Rousseeuw–Croux definition, also used in the robustbase implementation, is outer low median of inner high medians. For m ordered values, the low median has rank ⌊(m+1)/2⌋ and the high median has rank ⌊m/2⌋+1. Keep the self-distances when using this definition. Averaging the two middle values at both stages defines a different statistic. With five observations, all these median conventions agree.
For fictional data 0, 1, 2, 3, 100, Qn selects the third of ten distances, giving raw Q equal to 1. Sn uses row medians 2, 1, 1, 2, 98 and gives raw S equal to 2. Neither result includes calibration.
Two selections from the same pairwise distances. Moving the last observation from 100 to 1,000 leaves both raw answers unchanged; the sample range rises from 100 to 1,000.
Raw spread and calibrated scale are different outputs
Normal-model calibration writes the estimators as
Qn=dnaQQraw,Sn=cnaSSraw,
where aQ,aS are asymptotic consistency constants and dn,cn are optional finite-sample bias corrections. Consistency here targets the standard deviation σ of an i.i.d. normal model, not variance σ2, as the statsmodels Qn documentation explicitly specifies.
The corrected Qn constant is
aQ=2Φ−1(5/8)1≈2.219144466,
with Φ the standard normal CDF. The historical value 2.2219 contains a small error; robustbase documents the correction and uses the rounded constant 2.21914. For Sn, aS≈1.1926. Before finite-sample correction, these give about 2.21914 and 2.3852 for our example. They are not the raw values 1 and 2, and neither pair should be presented as a library's default corrected output. See the checked Qn and Sn documentation for their defaults.
Finite-sample corrections depend on sample size and the chosen implementation. Normal calibration does not make the estimator equal to standard deviation for an arbitrary skewed or heavy-tailed distribution. Akinshin's finite-sample study distinguishes these calibration factors from their large-sample limits.
What the robust number leaves out
For our original sample, the unscaled MAD is 1, the range is 100, the sample variance is 1,941.7, and the sample standard deviation is about 44.0647, using divisor n−1. The agreement between raw Qn and raw MAD is a coincidence of this sample. Variance has squared units; the other measures retain the observations' units. A range uses only the endpoints, while these robust scales select central features of the distances.
Both Qn and Sn are translation invariant and scale equivariant: adding a constant leaves them unchanged; multiplying the observations by b multiplies the estimate by ∣b∣. If observations are returns in percentage points, the resulting scale is also in percentage points.
Their familiar 50% breakdown description is a large-sample replacement-contamination statement, with finite-sample qualifications and an initially nondegenerate sample. Breakdown of a scale includes both explosion to infinity and collapse to zero. It is not a guarantee of small bias below 50% contamination. With just five observations, two replacements can create a triple tie and collapse both estimates to zero. Indeed, the separate toy sample (0,0,0,1,2) already gives Qraw=Sraw=0. A zero denominator can therefore arise from rounding or repeated prices even when not every observation is equal.
For return diagnostics, report the convention and inspect the observations behind it. Robust scale can stabilise a reference level while extreme losses remain economically important. It does not by itself estimate tail-loss probabilities, resolve serial dependence, or justify a square-root-of-time annualisation.
For the ordinary sample median, variance and standard-deviation baseline used in this comparison, see Basic Statistics and Regression, available with a free signed-in account.
Practice: the even-sample convention
For (0,1,10,11), compute raw Sn using inner high medians, including self-distances, and the outer low median. Would averaging both middle values at each stage give the same answer?
Answer. The inner high medians are 10,9,9,10. Their outer low median is 9. Averaging both middle distances within each row instead gives 5.5,5,5,5.5; averaging the middle two of those gives 5.25. That second calculation is a different statistic, not a finite-sample correction to Sn.