A simple moving average gives the oldest value in its window exactly as much say as the newest. For most series that's wrong — recent readings are more informative. A weighted moving average fixes it by letting you choose the weights.
Task: write wma(series, weights) returning one value per window position, each rounded to 4 decimal places.
len(weights). Slide it along the series one step at a time, so the output has len(series) - len(weights) + 1 entries.weights[0] pairs with the oldest value in the window and the last weight with the newest. So [1, 2] weights the newer value twice as heavily.[1, 2] and [0.333, 0.667] behave identically.That normalisation is what keeps the output on the same scale as the input. Skip it and [1, 2] would inflate every value threefold — a drift that looks like a signal.
The useful sanity check: all-equal weights must reproduce the simple moving average exactly, and a window over constant values must return that constant whatever the weights are.