Extracting Features/Patterns in a price data using Wavelet Transform(PART-1)

Abhishek Chikara
Jan 29 · 5 min read

Not a Blog Just Writing Notes for myself :)

Why Not use FFT or Fourier Transform to extract patterns or components in stock price data instead of using Wavelet transform directly?

Fourier Transform will work very well when the frequency spectrum is stationary. That is, the frequencies present in the signal are not time-dependent; if a signal contains a frequency of x Hz this frequency should be present equally anywhere in the signal.
The more non-stationary/dynamic a signal is, the worse the results will be.

Our Stock Data is dynamic in nature. A much better approach for analyzing dynamic signals is to use the Wavelet Transform instead of the Fourier Transform.

What’s the Difference between Fourier Transform and Wavelet Transform?

So wavelet transform also transform the signal into its frequency domain, just like Fourie Transform The Difference is Fourier Transform has a very high resolution in the frequency domain and zero resolution in the time domain

while the output of wavelet transform has a high resolution in frequency as well as the time domain

In layman’s terms: A Fourier transform (FT) will tell you what frequencies are present in your signal. A wavelet transform (WT) will tell you what frequencies are present and where (or at what scale). If you had a signal that was changing in time, the FT wouldn’t tell you when (time) this has occurred. You can also think of replacing the time variable with a space variable, with a similar analogy.

So Using Fourier transform we get to know which frequencies are present in the signal but not at which time that frequency oscillates so How the scientist overcome this problem?

Short-Time Fourier Transform. In this approach, the original signal is split into several parts of equal length (which may or may not have an overlap) by using a sliding window before applying the Fourier Transform. The idea is quite simple: if we split our signal into 10 parts, and the Fourier Transform detects a specific frequency in the second part, then we know for sure that this frequency has occurred between 2/10 th and 3/10 th of our original signal.

The main problem with this approach is that you run into the theoretical limits of the Fourier Transform known as the uncertainty principle. The smaller we make the size of the window the more we will know about where a frequency has occurred in the signal, but less about the frequency value itself. The larger we make the size of the window the more we will know about the frequency value and less about the time.

The Wavelet Transform has:

for small frequency values a high resolution in the frequency domain, low resolution in the time- domain,
for large frequency values a low resolution in the frequency domain, high resolution in the time domain.

How does the Wavelet Transform work?

The Fourier Transform uses a series of sine-waves with different frequencies to analyze a signal. That is, a signal is represented through a linear combination of sine-waves.
The Wavelet Transform uses a series of functions called wavelets, each with a different scale. The word wavelet means a small wave, and this is exactly what a wavelet is.

So a sine wave is from -inf to +inf while a wavelet exist for a particular duration which has a zero mean

There are many types of Wavelets to choose from

So Wavelet has two main concept

1. Scaling: Scaling is the process of stretching and shrinking the signal in time. It is represented by φ(t/s) where φ(t) is signal while s is the scaling factor and corresponds to how much a signal is scaled in time and scale is inversely proportional to the frequency

  • So a signal with a large scale/window(stretch wavelet) and analyze ‘large’ features(which corresponds to lower freq) and then we look at the signal with smaller scales(shrunken wavelet) in order to analyze smaller features(which corresponds to higher freq).
  • A stretched wavelet helps with capturing slowly varying changes in the signal while a shrunken wavelet helps in capturing abrupt changes

2. Shifting: Shifting simply means advancing or delaying the onset of the wavelet along the length of the signal. A shifted wavelet is usually presented by φ(t-k). We need to shift the wavelet in order the find the feature we are looking for in the signal

Since the Wavelet is localized in time, we can multiply our signal with the wavelet at different locations in time. We start with the beginning of our signal and slowly move the wavelet towards the end of the signal. This procedure is also known as a convolution. After we have done this for the original (mother) wavelet, we can scale it such that it becomes larger and repeat the process.

How Wavelets can be helpful for extracting features from our price data?

  1. Denoising a series

2. determining the principal component of movement in the series

  • Denoising is accomplished by recomposing the series by summing up the components from the decomposition, less the last few highest frequency components. This denoised (or filtered) series, if chosen well, often gives a view of the core price process. Assuming continuation in the same direction can be used to extrapolate for a short period forward.

So let’s fetch MSFT price data and smooth the data using wavelet transform as a filter bank:

The above function also return out Ordered list of coefficients arrays where n denotes the level of decomposition. The first element (cA_n) of the result is approximation coefficients array and the following elements (cD_n - cD_1) are details coefficients arrays.

In the next post, we will use other forms of Wavelet Transform to generate features for our price data

The Startup

Get smarter at building your thing. Join The Startup’s +792K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Abhishek Chikara

Written by

Finance 🤜🤛 Machine Learning Linkedin:https://www.linkedin.com/in/abhishek-chikara-96b68597/

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store