All problems
Bollinger Band Position
Problem
Compute where the last price sits inside a Bollinger band built from the last k prices: position = (last - lower) / (upper - lower), with bands mean ± num_std * population standard deviation.
Return 0.5 when the standard deviation is zero, and None if k is not positive or exceeds the series length.
Hint
A value of 1.0 means the price sits exactly on the upper band.
Test cases
case 1
in: [[1,2,3,4,5],5,2]
expected: 0.8535533905932738
case 2
in: [[5,5,5],3,2]
expected: 0.5
case 3
in: [[1,2,3],0,2]
expected: null
case 4
in: [[1,2,3],5,2]
expected: null
Starter codePython
def bollinger_position(prices, k, num_std):
# Your code here
pass4 test cases · run your code against them in the editor