LogoBlackBullAI
Know the history to empower the future.

Dynamic Time Warping (DTW) Algorithm: Why Is It Useful in Analyzing Stock Market Data Sets?

DTW Algorithm

An ancient Indian philosopher, Sage Vasishtha, described time as an illusion created by our mind. According to him, time exists only in our mind and has no physical existence. The causal effect of actions and reactions produces the illusion of time in our minds. Contemporary modern physicists are also reaching the same conclusion that time is an illusion.

The nature of time is so dynamic that its value changes with the change in frame of reference. We've seen in the famous movie Interstellar that one hour on a massive planet in deep space equals ten years on Earth. Suppose I go to that big planet, sing a song "Tan ta na tan, tan tan taaraaa… Chalti hai kya nau se baarah," and send those sound waves to Earth. Then, I come back to Earth and sing the same song again. If I try to compare the sound waves generated on Earth and on the big planet, I would find that those sound waves do not match. Though the wave pattern is the same, there is a huge difference in the sound tempo, since the speed of time is different on those two planets.

However, we can solve this problem using the Dynamic Time Warping (DTW) algorithm. In time series analysis, DTW is an algorithm for measuring similarity between two temporal sequences, which may vary in speed. Unlike simpler methods that compare points based on their position in the time sequence, DTW focuses on the shape of the data. This allows it to find the optimal alignment between two time series by minimizing the distance between them, even if they are out of phase or differ in length.

Now, let's see how this DTW algorithm is crucial in analyzing stock market data. We know that the stock market data is full of cyclical events; however, the time difference between these events may not always be the same. As the name suggests, this DTW algorithm wraps time and theoretically removes the illusion of time from the stock market event sequences. Hence, using DTW, we can compare any two-time series datasets without worrying about the speed of events (speed of time).

Understanding DTW mathematically is out of the scope of this article. However, to give you a glimpse of the beauty of mathematics, I am pasting the DTW formula below.

DTW Algorithm

Author - Sumit Khedkar,  Sumit Khedkar on Linkedin