LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#16
Bollinger bands
easyQuantacceptance —~10 min
Implement bollinger(values, window, k) — the Bollinger bands at the last bar: the simple moving average of the trailing window values, and k population standard deviations either side of it.
The bands are the most-drawn overlay on the /pro chart and the envelope the workbench's Bollinger bot trades. Return [lower, middle, upper] rounded to 4 decimal places.
example 1
input
values=[100.0, 102.0, 101.0, 103.0, 104.0, 102.5], window=5, k=2.0
output
[100.5, 102.5, 104.5]
example 2
input
values=[100.0, 102.0, 101.0, 103.0, 104.0, 102.5], window=5, k=1.5
output
[101, 102.5, 104]
constraints
- 2 ≤ window ≤ len(values)
- 0.5 ≤ k ≤ 4
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 bollinger()
values=[100.0, 102.0, 101.0, 103.0, 104.0, 102.5], window=5, k=2.0
expected
[100.5, 102.5, 104.5]
the judge calls bollinger() 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