Your question is Moving Average for Time Series. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Castleton Commodities International uses rolling statistics to monitor market time series. Given a sequence of numeric observations and a window size, return the moving average at every position.
For position i, average the values from max(0, i - window + 1) through i. Initial positions use the values available so far, so the output has the same length as the input. Return an empty list when the input series is empty.
Implement moving_average(values, window).
values, a list of integers or floating-point numbers, and window, a positive integer.values.def moving_average(values, window):