LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#20
Linear-regression channel
mediumQuantacceptance —~20 min
Implement linreg_channel(values, k) — a linear-regression channel over the whole series: fit y = a + b·t for t = 0..n-1 by ordinary least squares, take the population standard deviation of the RESIDUALS y - (a + b·t), and return the channel at the last bar: [slope, fitted_last - k·std, fitted_last + k·std].
It is the channel the workbench's regression bot draws and the /pro chart lets you drag. Return the three values rounded to 4 decimal places.
example 1
input
values=[100.0, 102.0, 98.0, 98.0, 102.0, 100.0], k=2.0
output
[0, 96.734, 103.266]
example 2
input
values=[100.0, 101.0, 103.0, 102.0, 105.0, 106.0], k=2.0
output
[1.1714, 104.391, 107.1328]
constraints
- 3 ≤ len(values) ≤ 5_000
- 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 linreg_channel()
values=[100.0, 102.0, 98.0, 98.0, 102.0, 100.0], k=2.0
expected
[0, 96.734, 103.266]
the judge calls linreg_channel() 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