financial.simple_moving_average =============================== .. py:module:: financial.simple_moving_average .. autoapi-nested-parse:: The Simple Moving Average (SMA) is a statistical calculation used to analyze data points by creating a constantly updated average price over a specific time period. In finance, SMA is often used in time series analysis to smooth out price data and identify trends. Reference: https://en.wikipedia.org/wiki/Moving_average Attributes ---------- .. autoapisummary:: financial.simple_moving_average.data Functions --------- .. autoapisummary:: financial.simple_moving_average.simple_moving_average Module Contents --------------- .. py:function:: simple_moving_average(data: collections.abc.Sequence[float], window_size: int) -> list[float | None] Calculate the simple moving average (SMA) for some given time series data. :param data: A list of numerical data points. :param window_size: An integer representing the size of the SMA window. :return: A list of SMA values with the same length as the input data. Examples: >>> sma = simple_moving_average([10, 12, 15, 13, 14, 16, 18, 17, 19, 21], 3) >>> [round(value, 2) if value is not None else None for value in sma] [None, None, 12.33, 13.33, 14.0, 14.33, 16.0, 17.0, 18.0, 19.0] >>> simple_moving_average([10, 12, 15], 5) [None, None, None] >>> simple_moving_average([10, 12, 15, 13, 14, 16, 18, 17, 19, 21], 0) Traceback (most recent call last): ... ValueError: Window size must be a positive integer .. py:data:: data :value: [10, 12, 15, 13, 14, 16, 18, 17, 19, 21]