MCPcopy
hub / github.com/microsoft/qlib / robust_zscore

Function robust_zscore

qlib/utils/data.py:15–31  ·  view source on GitHub ↗

Robust ZScore Normalization Use robust statistics for Z-Score normalization: mean(x) = median(x) std(x) = MAD(x) * 1.4826 Reference: https://en.wikipedia.org/wiki/Median_absolute_deviation.

(x: pd.Series, zscore=False)

Source from the content-addressed store, hash-verified

13
14
15def robust_zscore(x: pd.Series, zscore=False):
16 """Robust ZScore Normalization
17
18 Use robust statistics for Z-Score normalization:
19 mean(x) = median(x)
20 std(x) = MAD(x) * 1.4826
21
22 Reference:
23 https://en.wikipedia.org/wiki/Median_absolute_deviation.
24 """
25 x = x - x.median()
26 mad = x.abs().median()
27 x = np.clip(x / mad / 1.4826, -3, 3)
28 if zscore:
29 x -= x.mean()
30 x /= x.std()
31 return x
32
33
34def zscore(x: Union[pd.Series, pd.DataFrame]):

Callers

nothing calls this directly

Calls 3

clipMethod · 0.80
absMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected