FOURIER ANALYSIS FOR STOCK PRICE FORECASTING: ASSUMPTION AND EVIDENCE

The research addressed the relevant question whether the Fourier analysis really provides practical value for investors forecasting stock market price. To answer this question, the significant cycles were discovered using the Fourier analysis inside the price series of US stocks; then, the simulation of an agent buying and selling on minima and maxima of these cycles was made. The results were then compared to those of an agent operating chaotically. Moreover, the existing significant cycles were found using more precise methods, suggested in the research, and based on the results of an agent buying and selling on all possible periods and phases. It has been analysed whether these really existing cycles were in accordance with the significant cycles resulting from the Fourier analysis. It has been concluded that the Fourier analysis basically failed. Suchlike failures are expected on similar data series. In addition, momentum and level trading backtests have been used in a similar way. It has been found that the level trading does provide a certain practical value in comparison to the momentum trading method. The research also simplifies the complicated theoretical background for practitioners.


Introduction
The Fourier analysis methods are nowadays frequently implemented into an algorithmic trading as a Technical Analysis tool for a directional forecasting of a market price development. The question is whether this tool really provides certain benefit for the investors? This question is still under the discussion among both financial market practitioners and academicians.
The main contribution of this study is to answer reliably the question above, which means we have to do a precise examination based on the robust backtesting on price time series and quantify a possible benefit. US Stocks were used for the backtesting as this market provides a significantly large data set, and it is reasonable to expect similar results of the Fourier analysis in the case of other liquid investment instruments or on the similar data series in finance.
Moreover, other technical tools, i.e. momentum and level trading methods have also been utilised on US Stocks in order to quantify the success rate of these algorithmic trading methods, and to conclude whether these methods are able to provide certain practical value for algorithmic trading.
The aim of this research is also to simplify the complicated theoretical background of this portfolio management topic for practitioners.

Literature overview
The Fourier analysis is the study of the processes where general periodical functions may be represented by a sum of simple trigonometric functions, e.g. sinus. The Fourier analysis is predominantly based on studies of Jean Baptiste Joseph Fourier. It utilises the fact that any finite and time-ordered time series can be approximated by a decomposition of the data into a set of sine waves. Each of these sine waves has a specific cycle length, amplitude, and phase relationship with the other sine waves. In Fig. 1a, there are two cycles (dots and line) with different period/frequency; in Fig. 1b, there are two pure sine cycles with the same period/frequency but with a different phase angle, the phase difference equal to φ.
Based on a simple comparison of their amplitudes, it is possible to find significant cycles with dominating amplitudes and their periods. The Fourier analysis has many scientific applications, mainly in mathematics (partial differential equations, theory of numbers, combinatorics, probability theory, statistics, numerical analysis), in engineering and physics (signal processing, imaging, acoustics, optics) but also in finance (option pricing : Scott 1997;Ramponi 2012;Zhang, Wang 2013). The complete Fourier analysis concept is called spectral analysis. Fast Fourier Transform (FFT) is an abbreviated calculation of DFT (Discrete Fourier Transform) that can be computed in a fraction of time in comparison to the complete analysis. FFT reduces the amount of computer time enormously, and this analysis is used in this research as well. According to Walker (1996: 53): "The FFT is one of the greatest contributions to the numerical analysis made in this century".
The Fourier analysis is often used in Technical Analysis or in other prediction tools, e.g. Meta Stock program which focuses on FFT. This indicator shows the predominant period's length and also the relative amplitude of each. Knowledge about dominant periods should allow us making a profit based on periodical buys at local minima and sells on local maxima (Fig. 1) of the cycle. Very early studies connected to existing economic cycles of certain frequency were mentioned in articles by Frisch (1933) or Schumpeter (1939). There is quite a wide spectrum of research in the area of the Fourier analysis in finance (Brock, Sayers 1988;Chen 1988Chen , 1996Ramsey et al. 1990;DeCoster, Mitchell 1991;Benhabib 1992;Zarnowitz 1992;Day, Chen 1993;Granger, Terasvirta 1993;King, Rebelo 1993;Prigogine 1993;Qian, Chen 1994. None of these, however, solve the question of its practical value. The basic research in signal processing in this area, which is connected to our subject, was made by Gabor (1946). The basic mathematical background of the Fourier analysis is described in detail by Walker (1996).
Momentum and level trading methods were also described by Stádník (2014) as the result of expected feedback actions. According to this theory, the "Trend Stabilizer" feedback prolongs the trends on average, and the "Price Inertia Feedback" forces the price towards the price level, which is given for example by the important economic news. Further momentum studies are provided by Pesaran and Timmermann (1995), Chan et al. (1996), Divis and Teply (2005), Chang et al. (2010), Stankevičienė and Gembickaja (2012), Janda and Svárovská (2013), Janda et al. (2014), Barak et al. (2015). Momentum and level trading methods are currently used in high frequency (HTF) algorithmic methods.

Methodology of the research
To answer the question: "Does the Fourier analysis work in finance for stock price forecasting?", daily closing prices of 2332 US stocks, up to 5 years back, have been used. The list of tested stocks is provided in the appendix (Table 9). Two methods -FFT and Complex Period Test were used to identify predominant cycles and to assess the benefit of the Fourier analysis. Both are described in the following text.
Both methods have been implemented in Matlab environment (the core source code is the part of the Appendix).

FFT
To avoid poor functionality of the Fourier analyses, the transformed function must meet the following criteria: (1) Stationary function, meaning that the function repeats with the same periodicity to infinity; (2) The sample of the function, over which the Fourier transform is calculated, must be large enough to be representative. The sample must capture at least one period of all the components that make up the function.
Important is that Fourier transforms can be applied to any function, including nonstationary and non-smooth time series but its benefit on such function should be carefully tested and assessed before regular use. This is exactly the case in finance -the environment of partly random processes. We can suspect poor functionality, but it needs to be checked first.
The FFT method has been used in order to find significant cycles, and it has been applied to market price time series. The resulting significant cycles are called "best FFT cycles" in the following text. To practically quantify the benefit of this method, an agent opening and closing long positions on the best FFT cycles, minima and maxima are simulated. The WIN ratio results are compared with the results of an agent opening and closing long positions chaotically on the same period but a random phase. Such a problematic is closely connected to the percentage advantage (Stádník 2013), which must be generally higher than 50% to provide a profit on average while making repeated speculations. There are certain presumptions to guarantee the profit: an endless number of repetitions and also no capital restrictions. Such presumptions are not realistic in practice, but it is believed there is no better way how to assess the functionality of the method.
The WIN ratio is calculated according to the formula (1): where, N success is a number of speculations with a financially positive result (the result is in plus), and N all is the number of all the speculations.
Before the FFT analysis is applied, it is necessary to eliminate trends (to make "detrending") from the original time series to maximally fulfil the requirements of the series stationarity. In practice, it is usually solved by "detrending" the data by using either a linear regression or a moving average method. In our research, this procedure has been based on lowering of the price value about certain moving average (minimizing the magnitude of the price chart). For the FFT implementation, the Matlab function Y = fft(x) has been used. This function returns the discrete Fourier transform (DFT) of the vector x, computed with a fast Fourier transform (FFT) algorithm (formula 2), N is the next power of 2 from the original signal length of x: From a complex point of view, spectrograms have also been made. A spectrogram in our research is a visual representation of the spectrum of frequencies in a price time series as spectrums vary in time. Matlab implemented function S = spectrogram(x, window, noverlap, nfft, fs) is used. The function returns S, the short time Fourier transform of the input signal vector x, window is a Hamming window of length nfft, noverlap is the number of samples that each segment overlaps, nfft is the FFT length and it is the maximum of 256 or the next power of 2 greater than the length of each segment of x, fs is the sampling frequency, which defaults to normalised frequency. In the research, spectrogram (x, 128, 120, 128, 1) has been used.

Complex Period Test
The second approach how to find significant cycles is Complex Period Test. This method was suggested in this research in order to find dominant periods and its phases for each stock utilizing an agent opening long positions successively in all possible phases of an assumed cycle and closing positions after a half period of the cycle. The time distance between the expected minima and maxima is one-half of the period (Fig. 1a). Periods 2, 4, 6, 8, …, 160 days were checked in this way. It has been decided to check the maximum period of 160 days as there was no financial sense to make repeated investments based on the percentage advantage during longer periods. Odd periods have not been used in order to avoid the problem of the price at a half period as our data set contains only closing prices and a significant impact of this method on the final result is not expected. The correctness of this test is indisputably based on its own simple and logical principle.
The principle of all phase angles checking within one period is shown in the Fig. 2. By the way of example, if a period of 4 days and the phase 0 are expected to exist, a long position is opened on the beginning day, which is denoted as a "0" phase ( Fig. 2), and the position is closed after half a period, i.e. after 2 days in our example. In this manner, it is continued until the end of the time series.
After the phase 0 checking, the phase 1 is tested by opening position on the day following the 0 phase day. In this way, all possible 4 phases (0-3) are tested. The best WIN ratio phase in the Figure 2 is the phase 2, where we bought at the local minimum and sold after half a period at the local maximum ("buy" and "sell" is highlighted by the  Figure 2; "B" in the figure means "buy", "S" in the figure means "sell"). Then, for each period, the best WIN ratio of the phases is found, and these WIN ratios are compared together in order to select the most significant periods and their phases. The cycles providing the best WIN ratio results are denoted as the "best Complex Period Test cycles".
One argument against such a method is given next. If an agent consequently buys and sells with a positive win ratio, there can be a simply upward trend present, or maybe a positive result has been obtained solely due to a purely chaotic process. In that case, it basically does not say much about the cyclical development. To eliminate this problem, the comparison of the results of an agent buying and selling (opening long positions) chaotically is used (see the previous chapter). If a chaotic agent is profitable on average (on all the stocks), then there is an upward trend, which can be quantified by this average win ratio (in the case of no trend this win ratio should be close to 50%). If the average result (on all the stocks) of the agent operating on a certain cycle and phase is significantly better than the result of the chaotic agent, it must be concluded that this result came from the existing cycle.
The second common argument against this method is that very close amplitudes with different phases and frequencies could influence each other or even minimise the resulting cycle. It has to be stated that in this way, minimised cycles (even if they are created from significant cyclical processes) are without a practical value, and it is also not possible to discover them using FFT, so it does not influence our research results.

Assessment of FFT
Finally, the best FFT cycles were compared to the best Complex Period Test cycles and a discussion on the FFT method was made. Six best FFT cycles were chosen, and their WIN ratio results were taken from Complex Period Test to compare to the results of best Complex Period Test cycles.

Momentum and level trading tests
In the second part of the research, the question about the practical value of momentum and level trading methods was solved. Analogically to the previous part, the comparison was made between WIN ratio results of agents using the momentum or level trading methods and an agent operating chaotically. In the case of momentum tests, the long position was opened in case of persisting upward trend and the short position -in the case of the persisting downward trend. After a certain time (which is defined during the tests), the position was closed. The persisting upward trend means that there is a certain number of successively increasing steps (analogically in the case of the decreasing trend).
In the case of level trading tests, the long position was opened when a price fell below a certain level represented by a moving average. Analogically, the short position was opened when the price increased above this level. Level trading was also supported by the features of a typical financial distribution (Stádník 2014).
A chaotically operating agent opened randomly long or short positions at the same moment as the agent using momentum or level techniques.
Momentum and level trading tests have also been implemented in the Matlab environment (the core source code is the part of the Appendix).

Findings of the research on the Fourier analysis
The first crucial finding of this research is based on a simple spectrum or spectrogram of the price development. In most cases, a realistic spectrum is not so optimistic for significant cycles as in Kaufman (2013) in Figure 3.
A typical spectrum and spectrogram of 1-day data series are provided in Figure 4 (The Boeing Company) or Figure 5 (International Business Machines Corporation -IBM). Visually, the significant peaks cannot be recognised in the spectrum, but certain areas of higher significances can be recognised in the lower frequencies. The best FFT cycles (modus for all the stocks) are given in Table 1; the related histogram is in Fig. 6 a, b. The best periods of Complex Period Test (modus for all the stocks) are provided in Table 2; and the histogram is given in Figure 7.  Resulting win ratios of an agent trading on six best FFT cycles are presented in Table 3. The average result of an agent chaotically opening and closing long positions with the frequencies of best FFT cycles but on random phases is provided in Table 4. Resulting win ratio of an agent trading on the best cycle according to Complex Period Test is shown in Table 5. The result of congruence of best FFT periods and best periods resulting from Periods Complex Test are provided in Table 6.

Findings of the research on momentum and level trading methods
There are the WIN ratio results for momentum trading provided in Table 7 when the speculative position was closed in one day after it had been opened (T+1). The results are with respect to the number of successive up/down steps.  Table 8 presents the WIN ratio results for level trading when the speculative position was closed in one day after it had been opened (T+1).  The standard deviation of the ratios is involved in Tables 7 and 8. With a higher number of successive up/down steps (Table 7), the higher value of the deviation is measured. The reason is that the number of observations decreases. It is believed the data, which are obtained, provide a valuable indication. A more detailed statistical analysis is recommended for a possible further research.

Scientific discussion, limitations and possible further research
Because of a possibly poor functionality of FFT, it is difficult to decide whether the magnitudes in the spectrum are FFT leakage artefacts or actual function components. Useful is a comparison of measured spectrograms and white noise spectrograms shown in Figure 8. Certain differences have been identified, which indicate a possible benefit for the use of FFT. But based on the spectrum and the spectrograms alone, it is hard to say how significant the practical advantage may be. So, the question is whether this finding has a certain practical value.
The only way to answer this question is to use the simulation of an agent operating on the best FFT periods.
Based on the test of congruence between significant cycles resulting from Complex Period Test and FFT methods, it can be stated that FFT basically fails to find the best cycles. This statement is supported by the result of an agent operating on the best FFT cycles where the WIN ratio is 55% and the WIN ratio of an agent operating on Complex Period Test best cycles is 59%. 2332 US stocks, which represent almost all of the US market of shares, have been used to avoid survivorship bias (Elton et al. 1996;Linnainmaa 2013).
Then, the question is why FFT basically fails?
The first reason is that the data series does not meet the criteria of stationarity (chapter 2.1.) which implies a possible poor functionality of FFT in general. Such problem could also be connected to a time series with noise. Saying that there is a noise inside the time series is very vague and does not contain any information at all. In the case of a technical approach, high or low-frequency noises are usually expected and a filter may be used to separate noise from a signal. In the case of a "financial" signal, the situation is different and basically, it cannot be recognised if there is a certain noise. By the way of example: in Figure 9 a, there is an example of a periodic artificial signal, which is hidden in the signal in Figure 9 b. It is not possible to recognise the signal in the spectrum using FFT methods as it can be seen in Figure 10 a, b. This topic is an especially interesting for further research.
Based on the spectrograms, it can be stated that spectrum characteristics change in time.
Thus, a possible way to improve speculative results is to test the agent operating on changing frequencies which are given by spectrograms.
Research on high-frequency data basically leads to the same results. For example, the high-frequency spectrograms for Bund Futures look very similarly (Fig. 11 a, b).
In the case of momentum trading, it is concluded that this technique basically fails on the daily basis contrary to the level trading method. The level trading results are in accordance with the characteristics of typical financial daily distribution (Stádník 2014).
The momentum trading method would provide certain practical value in the case of using reverse speculations in comparison with our test. This means to open long positions instead of short ones during the test.

Conclusions
It was examined whether the Fourier analysis really does provide a certain advantage for investors forecasting the future development of a stock market price. The main finding is that this method basically fails to find the existing predominant cycles. Based on an attempt to detect significant periods in the US stock market data, using FFT -one of the methods of the Fourier analysis -it has been found that this method is unacceptable. Moreover, it is reasonable to expect similar failures in the case of other liquid investment instruments or similar financial data series. The Fourier analysis is still used nowadays for forecasting in finance and its benefit is under the discussion among both financial market practitioners and academicians.
According to the spectrum and spectrogram analysis, it can be preliminarily stated that there are certain significant periods in the market price development in comparison with the case when the development is purely chaotic. The test of congruence between the significant periods resulting from FFT and Complex Period Test gives only 3%.
Complex Period Test was suggested in the research and it is the unquestionable method for finding the most significant periods. Algorithmic trading methods based on the Fourier analysis in our test provide only approximately 1% higher WIN ratio over a chaotically working agent. The question is whether this percentage advantage is able to cover transaction costs and whether it has certain practical value. Based on Complex Period Test, it can be stated that if FFT detects the best really existing periods, the WIN ratio should be 5% over the chaotically working agent. It is reasonable to expect similar failures of FFT in the case of other liquid investment instruments or similar data series in finance. Why does FFT method fail? One possible explanation is non-stationarity of the data series, which could also be connected to the presence of too much "financial" noise in the development. This problematic represents one of the limitations of the research and it is recommended as a possible way of further studies in the area.
Another limitation is that the research does not take into consideration a spectrum variability during the time, so a possible way how to possibly improve speculative results is to test and assess the agent operating on frequencies based on the spectrograms.
Moreover, momentum and level trading methods have been tested in order to find out whether these methods are able to provide certain practical results for market price forecasting. These methods are also frequently used for algorithmic trading on the US stock market.
It was found that the level trading method provides certain practical value. As the results are approximately only 1% above the results of a chaotically operated agent, the final practical value again depends on the transaction costs. Results of level trading back tests are in accordance with the previous research (Stádník 2012). In the previous research, the level trading method was tested based on previous day closing price to be the level.
The current research is based on moving average at the level.
Momentum trading tests fail to provide certain practical value on the daily basis. It would provide certain practical value in the case of using the reverse action (long positions instead of the short ones) but this way basically leads to the level trading method. The results of the research are with respect to the number of successive up/down steps.