## What does a Moving Average mean?

Moving average is a statistical technique used to analyze time-series data by calculating the average of a set of consecutive data points over a specific period of time. The moving average is calculated by adding up the values of the data points within the period and then dividing the sum by the number of data points.

Moving averages are commonly used in finance, economics, and other fields to smooth out fluctuations in data and identify trends over time. For example, a 10-day moving average of a stock's price would be calculated by averaging the prices of the stock over the past 10 days.

There are different types of moving averages, such as simple moving average (SMA), weighted moving average (WMA), and exponential moving average (EMA), which differ in the weights assigned to each data point in the calculation.

## Simple Moving Average(SMA)

Simple moving average is a basic technique used to smooth out time-series data by calculating the average of a set of consecutive data points over a specified time period. The calculation of SMA is simple: you just add up the values of the data points in the period and then divide the sum by the number of data points.

For example, let's say you have the following data points representing the closing prices of a stock for the last 7 days:

Day 1: 50

Day 2: 52

Day 3: 48

Day 4: 49

Day 5: 51

Day 6: 50

Day 7: 53

To calculate a 3-day SMA, you would add up the closing prices of the last 3 days and divide the sum by 3. So, the SMA for Day 4 would be:

SMA = (48 + 52 + 50) / 3 = 50

To calculate the SMA for the next day, Day 5, you would add up the closing prices of the last 3 days again, but shift the window one day forward. So, the SMA for Day 5 would be:

SMA = (52 + 50 + 49) / 3 = 50.33

And you would continue this process for the rest of the data points.

SMA is a useful tool for identifying trends and smoothing out fluctuations in time-series data. However, it has some limitations, such as being sensitive to outliers and not adapting well to sudden changes in the data.

## Weighted Moving Average

Weighted moving average is a statistical technique used to analyze time-series data by assigning different weights to different data points within a specified time period. The weights are usually higher for more recent data points and lower for older data points. The calculation of WMA is more complex than that of SMA, as it involves multiplying each data point by its respective weight before summing and dividing.

For example, let's say you have the following data points representing the closing prices of a stock for the last 5 days:

Day 1: 50

Day 2: 52

Day 3: 48

Day 4: 49

Day 5: 51

To calculate a 5-day WMA, you would assign weights to each data point in the period, with the most recent data point assigned the highest weight and the oldest data point assigned the lowest weight. A common method for assigning weights is to use a linear weighting scheme, where the weights decrease linearly from the most recent data point to the oldest data point.

For example, for a 5-day WMA, the weights would be:

Day 1: 5/15

Day 2: 4/15

Day 3: 3/15

Day 4: 2/15

Day 5: 1/15

To calculate the 5-day WMA for Day 5, you would multiply each data point by its respective weight, sum the products, and then divide by the sum of the weights. So, the WMA for Day 5 would be:

WMA = (50 x 5/15) + (52 x 4/15) + (48 x 3/15) + (49 x 2/15) + (51 x 1/15) / (5/15 + 4/15 + 3/15 + 2/15 + 1/15) = 50.267

And you would continue this process for the rest of the data points.

WMA is a useful tool for smoothing out fluctuations in time-series data and giving more weight to recent data points. However, it also has some limitations, such as being more complex to calculate than SMA and being sensitive to the choice of weights.

## Exponential Moving Average

Exponential moving average is a statistical technique used to analyze time-series data by assigning exponentially decreasing weights to each data point within a specified time period. The weights are highest for the most recent data point and decrease exponentially for older data points. The calculation of EMA involves using a smoothing factor that determines the rate at which the weights decrease.

For example, let's say you have the same data points representing the closing prices of a stock for the last 5 days as in the previous example:

Day 1: 50

Day 2: 52

Day 3: 48

Day 4: 49

Day 5: 51

To calculate a 5-day EMA, you would first calculate the simple moving average (SMA) for the first data point, and then use a smoothing factor to calculate the EMA for the rest of the data points. The smoothing factor is usually a value between 0 and 1, with a higher value giving more weight to recent data points.

For example, let's use a smoothing factor of 0.33. The 5-day SMA for the first data point is simply 50. To calculate the EMA for Day 2, you would use the formula:

EMA = (Price - EMA previous day) x Smoothing factor + EMA previous day

So, the EMA for Day 2 would be:

EMA = (52 - 50) x 0.33 + 50 = 50.66

To calculate the EMA for Day 3, you would use the formula again with the new EMA value for Day 2:

EMA = (48 - 50.66) x 0.33 + 50.66 = 49.33

And you would continue this process for the rest of the data points.

EMA is a useful tool for smoothing out fluctuations in time-series data and giving more weight to recent data points. However, it is also more complex to calculate than SMA and WMA, and its sensitivity to recent data points can make it more volatile and less suitable for certain types of analysis.

## Which Moving Average is Best?

There is no single moving average that is better to use than the others in all situations. Each type of moving average has its own strengths and weaknesses, and the choice of which one to use depends on the specific context and goals of the analysis.

For example, simple moving average (SMA) is easy to calculate and is useful for identifying general trends, but it can be sensitive to outliers and may not give as much weight to recent data points. Weighted moving average (WMA) and exponential moving average (EMA) give more weight to recent data points and can be better for short-term analysis, but they are more complex to calculate and may be more volatile.

Ultimately, the best approach is to use a combination of moving averages and other analysis techniques to gain a more complete understanding of the time-series data being analyzed.

## Comments