Citadel's quantitative research workflows often process ordered market observations and summarize them over fixed windows. Given a list of numeric observations, return the moving average for every contiguous window of a specified size.
Use a sliding-window approach so each new average updates the previous sum instead of recomputing all values in the window.
Implement moving_average(nums, window_size).
nums is a non-empty list of integers or floating-point numbers.window_size is an integer between 1 and len(nums), inclusive.window_size.len(nums) - window_size + 1.def moving_average(nums, window_size):