Mastering Moving Average

Unveiling the secrets to smarter financial analysis

A.I Hub
4 min readJul 21, 2024
Image owned by tech champion

In this article, we will walk you through the fantastic journey of learning features based on moving averages. In the intricate world of financial analysis, few tools wield as much power and insight as the moving average. Serving as a beacon amidst market fluctuations, moving averages provide a dynamic lens through which trends and patterns come into sharp focus. Whether charting the course of stocks, currencies or commodities, understanding the nuanced features of moving averages unveils a pathway to informed decision making and strategic advantage in today’s complex investment landscape.

Table of Content

  • Features based on moving averages

Features Based On Moving Averages

Image owned by investopedia

We calculate several moving averages, as I listed below:

  • Moving average means for the 700, 1.5K, 3K and 6K windows and
    excluding NaNs.
  • Exponentially weighted moving average with spans of 300, 3K, and 6K.
  • Average standard deviation moving average over 700 and 400 windows.
  • Moving averages means for 700 size window plus or minus 2 times
    average standard deviation moving average over the same size window.

The moving averages help us to discern patterns, reduce noise and provide a
clear picture of the underlying trends in the data.

We also calculate the IQR, the 001% and 999% quantiles. The IQR

meaning interquartile range is calculated by subtracting the 25%

percentile from the 75% percentile using numpy functions. The interquartile
range is the region where 50% of the data is found. The 001% and 999%
quantiles are also calculated with the numpy function for quantiles. The IQR

and the various other quantiles we have included are useful because they
provide important information about the central tendency and the spread of
the signal.

For windows of 10, 100 and 1,000 we calculate the moving average and
moving standard deviation. With these values, we then calculate the min,
max, mean, standard deviation, average absolute and relative change, 01%,

05%, 95% and 99% quantiles and absolute max roll. We include these
features because they reveal information about the local characteristics of the
signal within the specified window. Subsequently, for the features derived
from the moving average standard deviation calculated for windows of 10,
100 and 1,000.

For the features derived from the moving average mean, calculated for
windows of 10, 100 and 1,000.

For each 150K row segment generated from the training data, we are
calculating these features. Then, the time to failure is selected as the value
from the last row in the current segment.

Next, we are scaling all features using a StandardScaler. This is not

mandatory if we are using a model based on decision trees such as random
forest or XGBoost. We include this step for a case where we would like to
use other models, for example, one based on neural networks, where
normalizing the features would be a necessary step.

We repeat the same process for test data segments.

After we analyzed the data, we generated a set of engineered features. We
intend to use these features to build a baseline model. Then, based on the
model evaluation, we can further select what features to keep and

eventually, to create new features.

Conclusion

Finally, we will landing out from the concept of moving averages based on features, the strategic use of moving averages unveils a powerful toolkit for traders and analysts alike, offering not just insights into market trends but a nuanced understanding of momentum shifts and potential entry or exit points. By harnessing the versatility of various moving average types, from simple to exponential, adaptive and beyond, practitioners can tailor their approach to suit different market conditions and time frames. Whether employed as standalone indicators or in conjunction with other technical tools, moving averages remain indispensable in the arsenal of every astute investor seeking to navigate the complexities of financial markets with precision and foresight.

--

--

A.I Hub
A.I Hub

Written by A.I Hub

We writes about Data Science | Software Development | Machine Learning | Artificial Intelligence | Ethical Hacking and much more. Unleash your potential with us

No responses yet