DataLane

17. Moving average

hardProNot started~10 minPythonImplement moving_average()

Asked in screens shaped like: Bloomberg, QuantCo

Return the simple moving average of x with window w (valid / trailing windows only), each value rounded to 4 decimals.

Examples

  • Example 1

    Input: { "x": [1, 2, 3, 4, 5], "w": 3 }
    Output: [2, 3, 4]

Constraints

  • 1 <= w <= len(x)

Python editor

Loading Python engine…

Ctrl/Cmd + Enter submits

Run your code to see stdout.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close