Okay, it’s not as glamorous as a luxury yacht filled with supermodels, but it can help you:
- Decompose any signal and reduce the noise
- Identifying Cycles, Trends, and Forecasts Time Series
- Extract features for Machine Learning Models
- Manage Risks
- Detecting Trading Opportunities via Frequency Clusters
- And much more ...
Basically, if you’re building a trading bot, this is one of the tools you’ll want in your arsenal. In this article, I’ll cover the basics, but stay tuned for a follow-up where we’ll explore its full potential—and the common pitfalls to avoid.
For those who aren’t math enthusiasts, don’t worry! I’ll make everything as intuitive as possible, so you can apply it like a true signal-processing wizard in your own projects.
The world is beautiful, isn’t it? (Oh, and if something isn’t clear, ask me! I may not have the answer, but at least it’ll boost my SEO. Thanks!😁)
What is Fourier Analysis?
Analysis, that branch of mathematics dealing with functions, took a revolutionary turn thanks to a certain Joseph Fourier (yes, a French guy—cocorico! 🐓). He studied the famous series that now bear his name. His idea? To decompose periodic functions into a sum of cosines and sines. A brilliant approach that, among other things, helped solve the heat equation and allowed us to deeply explore a multitude of periodic signals—like those fancy brain wave tracings on an EEG.
But what does this have to do with stock prices, you ask? Absolutely nothing. That little historical detour was just for my own amusement!
That being said, even though stock prices and financial "signals" are not periodic (at least not on a large scale), Fourier’s second major discovery is actually useful to us here. Indeed, as early as 1810, he demonstrated that any function, whether periodic or not, could be decomposed into a sum of trigonometric functions—yes, those same cosines and sines! More precisely, we state:
For any function integrable over ℝ:
- Let be such that the integral of its absolute value is finite, meaning:
- For the math geeks, this is closely related to absolute convergence.
- For everyone else, it just means that the area under the curve, counted in absolute value (as if we flattened everything to be positive), is finite.
- And for the rest of the world… let’s just say it applies to any "normal" function.
Now, such a function can be transformed as follows:
This is what we call the Fourier transform. And we can retrieve using the inverse transform:
Alright, let’s take it slow! No need to panic.
The formula we really care about here is the inverse Fourier transform. Why? Because it reveals something amazing: if we take a well-behaved function , we can express it as a sum of complex exponential functions.
And these complex exponentials, thanks to Euler’s formula, can be rewritten as:
Which, after some calculations, gives us:
In simpler terms, is a sum (okay, a continuous sum, but still a sum) of sine and cosine signals. In other words, we’ve just managed to break down a non-periodic function into a superposition of periodic signals. Pretty cool, right? Here is a comparison to help you break it down :
Magnificent? Absolutely. But buckle up, because this is just the warm-up before the real fireworks begin.
But how can we make sense of it?
The key to interpretation lies precisely in this decomposition. To fully grasp its usefulness in finance, let's explore the intuition behind this transform.
Imagine a function that depends on , a distance, where is an aperiodic function describing heat distribution along a metal bar. Let’s assume that is measured in Kelvin and in meters. To the American units club: the rest of us are waiting for you to invent 'light-years per ounce' as the next standard !
Now, let’s apply the Fourier transform to decompose this signal into a sum of periodic signals. And when we talk about periodic signals, we’re not just talking about periods (yes, I know…pretty logic right) but also about frequencies, which are simply the inverse of the period. This means we are decomposing our temperature function into different frequency components. But what does that really mean?
Let’s take a closer look. In the exponential term , the exponent must be dimensionless. This implies that , the frequency, must have units of (inverse meters). This means it is a spatial frequency —compared to a time frequency that represents the inverse of time itself!😍
Next, the integral tells us that the temperature in Kelvin can be expressed as a sum of terms . Since the exponential function is dimensionless and has units of , it follows that must have units of Kelvin × meters so that the entire expression remains in Kelvin. In other words, represents the amplitude of the contribution of the spatial frequency to the temperature.
A crucial point: this decomposition is unique for each spatial frequency. It is logically impossible to have two waves with the same frequency of .
Let’s Crunch Some Numbers to Make It Clearer
Now, suppose that for our metal bar, we obtain for the frequencies and . This means that these two spatial frequencies contribute equally to the heat distribution in our bar. However, this equality in amplitude does not mean that the temperature variation is the same:
- For , the temperature variation is over 1 meter, meaning a difference of 5 Kelvin per meter.
- For , the temperature variation is also , but over only 50 cm (1/2 meter), meaning the temperature changes occur much more rapidly.
Quick Suprise Test:
What if we found an amplitude of for a frequency ?
Answer: we would have temperature oscillations of lower amplitude than before, but occurring much more frequently, as they would take place over a much smaller distance—20 cm (1/5 meter). This means that even though the magnitude of the variation is smaller, it happens far more often in space.👍
The key idea here is that we have transformed a global problem of temperature in Kelvin into a local analysis based on spatial frequencies. In other words, we have taken a physical phenomenon (heat propagation along a bar) and decomposed it into independent waves, each representing different scales of heat propagation. This process establishes a powerful connection between the physical world (measured temperatures in Kelvin) and the frequency domain (spatial frequencies , measured in ).
And the most beautiful part? We can also do the reverse! We can start from a time-dependent function (such as a wave that varies over time) and analyze it in terms of its frequencies. It’s like crossing a bridge between two worlds, and that bridge is truly astonishing!🤩
Are you starting to see the beauty of this formula?
Here’s what it allows us to do for any function:
- Change the frame of reference, adopting an entirely new perspective.
- Decompose a global problem in a simple, unique, and local way.
- Identify periodic structures (and therefore order) within what initially appears to be aperiodic chaos!
Honestly, I’m absolutely fascinated by this formula! And the cherry on top? Its potential goes even further—its applications, especially in finance, are absolutely mind-blowing. The way we can leverage this mathematical gem to understand and analyze complex financial phenomena is nothing short of revolutionary.
5 Practical and Ready-to-Use Ideas for Fourier Analysis
The first important thing to know is that, in practice, you’ll never strictly use the Fourier Transform as such, but rather the Fast Fourier Transform (FFT) since it’s the fastest algorithm to compute the transform. It’s also one of my favorite algorithms, so let me know if you'd like me to write a detailed article on it!
Anyway, here are 5 concrete ideas for using FFT, from the most obvious to the least obvious:
- Decomposition and Noise Reduction
- Cycle and Trend Identification and Forecasting
- Feature Extraction for Other Models
- Risk Measurement Using Fourier Analysis
- Identifying Trading Signals from Frequency "Clusters"
I'll give a bit more detail on each of these so you’re not left hanging, but keep in mind that each of these ideas could lead to one or more full articles!
1. Decomposition and Noise Reduction
The idea here is to analyze an aperiodic function in order to identify its main cycles using the power spectral density. Then, using a filter, we filter out the spectrum, keeping only the most significant components. We assume that the filtered components are noise and not important for analyzing the data. The result is a cleaner dataset, with less noise and more useful information. If done "correctly", the goal is to improve the quality of our data by reducing errors caused by random fluctuations.
2. Cycle and Trend Identification and Forecasting
FFT can be used to detect repetitive cycles in the prices of a financial asset. This helps identify significant cycles, and thus useful trends. The idea is then to assume that these cycles are stable and repeat over the short/medium term, meaning they can be extrapolated to predict the future. If you'd like to learn more, I recommend reading the article "Making Simple Predictions with Fourier Analysis," where you'll find the complete method explained with code.
3. Feature Extraction for Other Models
Fourier transforms can be used to extract important features from time series in trading, such as the amplitudes and phases of different frequencies. These features can then be used as inputs for machine learning models. Additionally, it's possible to decompose a signal into its components and extract the most relevant components to feed into a machine learning model, which will determine which component is important at a given moment (using a meta-model approach). Yep... features engineering can be cool too !
4. Risk Measurement Using Fourier Analysis
The article "A New Measure of Risk Using Fourier Analysis" (2024) by M. Grabinski and G. Klinkova proposes an innovative method for measuring risk in the stock market using Fourier analysis. Their approach focuses on the price fluctuations of stocks and compares the frequency of these variations to a company’s fundamental value. By identifying rapid price movements that might signal excessive speculation, they introduce a revised "irrationality ratio". This new measure, more precise and robust than previous methods (Schädler 2018), allows for a better grasp of the risks associated with speculative fluctuations while preserving the market's fundamental dynamics. If this piques your interest, I suggest checking out the dedicated article (although it may not be available yet, it’s a priority on my list).
5. Identifying Trading Signals from Frequency Clusters
Analyzing price series by identifying frequency clusters allows for the detection of areas where significant market movements are about to occur. By grouping the dominant frequencies in prices, we can observe periods of high volatility or consolidation, which often precede trend reversals or accelerations. Applying dynamic clustering techniques like DBSCAN or K-means can help anticipate these periods of intense activity and adjust our entry and exit strategies accordingly. For example, a sudden clustering of fast frequencies could signal an imminent reversal, providing an opportunity to enter a position before the price movement unfolds. This approach enhances trend anticipation by refining trading signals based on the spectral variations in prices.
Wrapping Up Part 1 on Fourier Analysis
Concluding articles like this is pretty tough... The only thing I can really say is: did you get it? Getting feedback while I’m staring at my screen is going to be tricky...😅
We’ve broken down the intuition behind Fourier theory in detail and explored 5 possible applications for trading. I’m currently working on articles for applications 1, 2, and 4. I’m sure they’ll be useful for your projects (and for understanding Fourier better too!).
Before I post those, though, the next article will dive into 5 more advanced applications. To be honest, the last few applications are pretty complex for me (and not super intuitive), but they’ll definitely be useful for some of you. I’ll also provide all the sources in case you want to dig deeper.
Consider this the movie intermission—go grab some popcorn because the film’s about to restart with more gunfight scenes, and the plot is about to get wild! 🍿
Don’t hesitate to comment, share, and most importantly, code!
I wish you an excellent day and lots of success in your trading projects!
La Bise et à très vite! ✌️
References
- Grabinski, Michael and Galiya Klinkova. “A new measure of risk using Fourier analysis.” (2024).
Comments