LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#12
Rolling z-score
easyQuantacceptance —~15 min
Implement rolling_z(values, window) — the z-score of the LAST value relative to the trailing window values (inclusive of the last): (last - mean) / stdev using the sample standard deviation of exactly those window values.
A z-score of −2 means today is two standard deviations below its recent self — the raw material of every mean-reversion bot in the workbench. Return the score rounded to 4 decimal places.
example 1
input
values=[100.0, 101.0, 99.0, 102.0, 98.0, 97.0], window=6
output
-1.3363
example 2
input
values=[100.0, 101.0, 99.0, 102.0, 98.0, 97.0], window=3
output
-0.7559
constraints
- 2 ≤ window ≤ len(values) ≤ 10_000
- the window values are not all equal
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to rolling_z()
values=[100.0, 101.0, 99.0, 102.0, 98.0, 97.0], window=6
expected
-1.3363
the judge calls rolling_z() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice