Simple Moving Average (SMA)

sma(data, n)

Calculate the simple moving average of a list of data points for the most recent n periods.

syse.sma(data, n)

Calculate the simple moving average of a list of data points for the most recent n periods.

Parameters:
  • data (list) – A list of data points.

  • n (int) – The number of most recent observations to be used.

Returns:

The simple moving average.

Return type:

float

Examples:

Suppose you are the owner of a retail store, and you want to analyze the sales performance of your store for the last 10 days. You have a list of the daily sales figures for the past 10 days. You can use the above Python function to calculate the simple moving average of the sales figures over the past 10 days to get an idea of the store’s overall sales trend. This information can be useful in determining whether you need to adjust your inventory or marketing strategies to improve sales.