Scientific Research

An Academic Publisher

Application of Wavelets to Detect Trend Reversals on Brazilian Stock Market

**Author(s)**Leave a comment

KEYWORDS

1. Introduction

Looking after maximizing the returns and improving the risk management of financial market investments, researchers and scientists develop, every year, new methods to predict the future behavior of the market variables. Among the different approaches to this question, the techniques to analyze the trends on the assets price are remarkably important, detecting the current trend or predicting its reversal [1] [2] .

In 1996, two independent workgroups proposed that the log-periodicity concept, used to predict critical phenomena, could be applied on the prediction of significant drops (crashes) of stock market through the study of the behavior of the S & P500 index (USA) during the October, 1987 bubble burst [3] [4] . This same concept was already successfully applied to predict high-pressure tanks rupture [5] [6] and detect earthquakes [7] [8] .

But fitting the log-periodic model to the asset prices time series posts a high complexity task, so the Continuous Wavelet Transform was used to generate the Wavelet Index, a real value between 0 and 1 that represents the immanency of a trend reversal, raising sell signals before the market crashes [9] [10] .

This research evaluates the Wavelet Index applicability on the Brazilian Stock Market, represented by the Bovespa Index (from BM & FBOVESPA Stock Exchange, located in Sao Paulo, Brazil) and 14 stocks of companies listed in BM & FBOVESPA as well, through the analysis of different kinds of wavelets and threshold values to generate the sell signals. The intensity of the drops that presents the best results using this method is also evaluated, as well as a comparison of the performance of the proposed method with the usual Technical Analysis tools.

2. The Log-Periodic Power Law

The origins of the log-periodic power-law come from the critical phenomena theory, developed in the decade of 1960. The application of the complex systems model to the financial market is based on the premise that the interactions among investors generate a cooperative behavior, accelerating the uptrend and creating a bubble. The rise in prices brings the market to an instable condition, where a small perturbation bursts the bubble (the critical point, the system collapse). In this model, the market’s internal conditions create the crashes and exogenous factors are only the triggers that bring the instability. So, the market itself progressively builds the bubble, in a self-organized process [3] .

Equation (1) mathematically represents this model, where I(t) represents the asset price (or value) on instant t and t_{c} is the instant where the crash is more probable. The parameter A is the asset price when t = t_{c}, β is the power law exponent, ω is the oscillation angular log-frequency, ϕ is the oscillation phase, B and C are constants used to fit the function:

$I\left(t\right)=A+B{\left({t}_{c}-t\right)}^{\beta}+C{\left({t}_{c}-t\right)}^{\beta}\mathrm{cos}\left(\omega \mathrm{ln}\left({t}_{c}-t\right)-\varphi \right)$ (1)

The log-periodic power law characteristically reduces the amplitude and the period of its oscillations as the critical moment (t_{c}) approaches, and the wavelets are intended to detect this increase in oscillation frequency [4] .

3. The Wavelet Transform

The Wavelet Transform is a particularly useful tool to analyze aperiodic and noise signals, characteristics that are common to financial market assets time series [11] . Using dilatation and translation operations on special waveforms, called wavelets, this transform can highlight specific signal formations on a time-frequency bi-dimensional plane, differently from the Fourier Transform.

A wavelet $\psi \left(t\right)$ must fulfill the following conditions [12] :

1) Must have finite energy (Equation (2), where E is the function energy, equal to the integral of its squared magnitude);

$E={{\displaystyle {\int}_{-\infty}^{\infty}\left|\psi \left(t\right)\right|}}^{2}\text{d}t<\infty $ (2)

2) Being
$\stackrel{^}{\psi}\left(f\right)$ the Fourier Transform of
$\psi \left(t\right)$ , according to Equation (3), it must respect the admissibility condition described on Equation (4). This implies that the wavelet has no components on frequency zero, meaning that its mean is equal to zero. C_{g} is the wavelet’s admissibility condition and changes to each wavelet type.

$\stackrel{^}{\psi}\left(f\right)={\displaystyle {\int}_{-\infty}^{\infty}\psi \left(t\right){\text{e}}^{i\left(2\pi f\right)t}\text{d}t}$ (3)

${C}_{g}={\displaystyle {\int}_{0}^{\infty}\frac{{\left|\stackrel{^}{\psi}\left(f\right)\right|}^{2}}{f}}\text{d}f<\infty $ (4)

The Continuous Wavelet Transform (CWT) $T\left(a,b\right)$ of signal x(t) is defined as the convolution of this signal with the wavelet for different values of a (the scale parameter, which represents the dilatation operation) and b (which represents the wavelet translation), as presented in Equation (5). Typically a weight-function of $1/\sqrt{a}$ is used to keep the same energy all scales of the wavelets.

$T\left(a,b\right)=\frac{1}{\sqrt{a}}{\displaystyle {\int}_{-\infty}^{}x\left(t\right)\psi \left(\frac{t-b}{a}\right)\text{d}t}$ (5)

In a more compact form:

${\psi}_{a,b}\left(t\right)=\frac{1}{\sqrt{a}}\psi \left(\frac{t-b}{a}\right)$ (6)

$T\left(a,b\right)={\displaystyle {\int}_{-\infty}^{\infty}x\left(t\right){\psi}_{a,b}\left(t\right)\text{d}t}$ (7)

The CWT results in a tri-dimensional graph, where the axis X holds the time (with length equal to the original signal), the different scales (frequency component) go in the axis Y and the calculated coefficient values ( $T\left(a,b\right)$ ) are in the axis Z. This graph is usually a contour curve, where the different colors represent the magnitude of $T\left(a,b\right)$ .

The total energy of a signal is the integral of its squared magnitude, the relative contribution of a scale a and a position b( $E\left(a,b\right)$ ) to the signal energy is given by Equation (8). The graph of $E\left(a,b\right)$ is known as scalogram and is used to highlight the location and scale of the signal’s dominant characteristics, in terms of energy [13] .

$E\left(a,b\right)={\left|T\left(a,b\right)\right|}^{2}$ (8)

4. Materials and Methods

This research considered the closing prices/values of Bovespa Index (IBOV) and other 14 stocks listed at BM & FBOVESPA Stock Exchange (from Sao Paulo, Brazil), between Jan/02/2008 and Jul/29/2016, (because the presentation of the dissertation was in November of 2016), discarding the periods when there were days that these assets were not negotiated and adjusting for dividends, splits and merges. Table 1 lists all assets considered, as well as the dates of the first and last days considered.

The first step was to analyze the assets’ time series to identify the uptrend movements that ended on drops equal to or larger than 5%, 10%, 15%, 20%, 25% and 30%, in order to evaluate the Wavelet Index performance in these different conditions. To isolate each uptrend movement, an algorithm identified its end (the drop that follows the uptrend) and then previous local minima defined its start. Figure 1 and Figure 2 shows the IBOV time series identifying the start and end of the movements that were follow by drops larger than 10% and 20% (respectively). The movements that were shorter than 30 days were discarded, as they were not long enough to provide satisfactory application of the CWT. The algorithm obtained 1529 movements, being 611 longer than 30 days.

The functions submitted to the Wavelet Transform must belong to the L²(R) space [14] , so it is necessary to remove the movement’s trend before analyzing them. A non-linear regression using least squares identified the trend of each movement, according to the Equation (9):

Table 1. Assets and periods considered.

Figure 1. IBOV with the movements followed by drops equal to or larger than 10% highlighted. The red marks are the movement start and the green marks, the movement end (Source: Author).

Figure 2. IBOV with the movements followed by drops equal to or larger than 20% highlighted. The red marks are the movement start and the green marks, the movement end (Source: Author).

${y}_{t}\left(t\right)=A+B{\left({t}_{c}-t\right)}^{\beta}$ (9)

The subtraction this trend (which is a power law) from the model proposed in Equation (1) highlights the movements’ log-periodic oscillations, with amplitude modulated according to the distance between t and t_{c}:

$I\left(t\right)-{y}_{t}\left(t\right)=C{\left({t}_{c}-t\right)}^{\beta}\mathrm{cos}\left(\omega \mathrm{ln}\left({t}_{c}-t\right)-\varphi \right)$ (10)

The Figure 3 shows an example of movement originally with its trend and then after the trend removal.

The movements, without its trends, went through a normalization process, so its values were between 0 and 1, and then submitted to the CWT, resulting in a

Figure 3. Movement with trend line in red (above). Same interval, with the trend removed (below).

bi-dimensional coefficients matrix. The squared value of this matrix is the movement’s scalogram, used in the subsequent analysis.

The proposed Wavelet Index calculation has four steps:

1) Calculate the difference between the larger coefficient and the smaller coefficient for each scalogram column. The larger this different, more significant is the correlation between the signal and the wavelet to a given scale (or to a given wavelet pseudo-frequency).

2) Obtain the scale of the larger coefficient, to each column that the difference calculated is larger than a given threshold (the “coefficients threshold”).

3) Calculate the Wavelet Index according to Equation (11), where WI is the Wavelet Index, N is the total quantity of scales used and n_{coef}_{max} is the scale where the larger coefficient happened. On the columns that did not reach the coefficients threshold, the Wavelet Index is equal to zero.

$WI=\frac{N-{n}_{coef\mathrm{max}}}{N}$ (11)

4) Compare the Wavelet Index with a new threshold (the “Wavelet Index Threshold”), considering a trend reversal imminent, and generating a sell signal, when the Wavelet Index is equal to or larger than this threshold.

The performance comparison between the Wavelet Index and the Technical Analysis tools considered that, given the same buy signals (the local minima from the identified movements); an investor would respect the sell signals generated for each indicator, separately. Then the investor would wait until the next buy signal, when he invests 100% of the available resources.

All algorithms used Python, except for the CWT calculations, which used the MATLAB©’s Wavelet Toolbox™, from The Mathworks, Inc.

5. Results and Discussion

In order to find the best combination of parameters to calculate the Wavelet Index, the described algorithm tested different combinations of wavelets, number of scales, coefficient thresholds and Wavelet Index thresholds:

・ Used wavelets: performed tests with the Haarwavelets (haar), Daubechies to N = 2 (db2) and N = 4 (db4), Meyer (meyr), Gaussian―1^{st} derivative (gaus1) e 4^{th} derivative (gaus4), Symmlet (sym5), Coiflet (coif3), Mexican Hat (mexh) and Morlet (morl);

・ Number of scales used in the CWT: 30 scales (minimum movements length) or maximum number of scales to each movement;

・ Coefficients threshold: value between 0.10 and 1.00, spaced of 0.01;

・ Wavelet Index Threshold: values between 0.10 and 1.00, spaced of 0.02.

The movements randomly constituted two groups, a search group (to evaluate the combination of parameters with best performance) and the test group (to test the best combination outside the initial group). Each combination has its performance evaluated at each movement, using two different criteria:

・ Early Sale Losses (ESL): usually, the Wavelet Index generates a sell signal before the time series reaches its peak value. Therefore, there is a loss due to the continuation of the uptrend after selling the asset. The algorithm calculates the ESL for each movement then sums all values and considers it as a percentage of the total uptrend.

・ False Negative (FN): happens when the combination does not result in a sell signal before the drop. The algorithm disregarded combinations that generate false negatives, as an FN may imply in severe losses to an investor.

The first test applied the described algorithm to all movements, separated according to the drop size. Therefore, the movements ended in drops equal to or larger than 5%, 10%, 15%, 20%, 25% and 30% were split randomly in search and test groups.

Table 2 brings the best combinations results in both groups, for each drop threshold.

The next test separated the movements by asset and applying the same procedure presented before. Table 3 brings the best combinations results by asset.

The next analysis separated the movements ending in drops equal to or larger than 5% and 10% from the movements ending in drops from 15% to 30%, looking for performance differences according to the drop size that follows the movements. The best combinations results for the first set are on Table 4, while the second set results are on Table 5.

Table 6 presents the frequency which every wavelet had the best performance on the tests. The Haar wavelet was the best in 25.5% tests (13 times), followed by Meyer wavelet with 23.5% (12 times). The Morlet and Symlet 5 wavelet were the best in only 1 case each (2%) and Daubechies 2 wavelet did not have the best performance in any test. Looking only at the test by asset for drops of 15% to 30%, the results are slightly different, as the Meyer wavelet was the best to 4 assets, followed by Haar and Gaussian1 wavelets (3 assets each).

Table 2. Results: all assets, separated by drop (Source: Author).

Table 3. Results: all movements, separated by asset (Source: Author).

Table 7 compares the results of the four tests performed, based on the average ESL and the quantity of FN to the search and test sets. Table 8 shows a similar analysis, but comparing the results by asset, on the three tests that separated the movements based on this criteria.

The tests that separated the movements by asset had better performance than the test that mixed movements from different assets. The performance also differs among assets with no obvious pattern, as there are significant differences even between assets from the same company (as PETR3/PETR4 and VALE3/VALE5). This is an evidence that every asset has different characteristics and, consequently, will present different performance when subject to the same Technical Analysis indicator [15] .

Table 4. Results: movements ending in drops of 5% and 10%, by asset (Source: Author).

Table 5. Results: movements ending in drops of 15% to 30%, by asset (Source: Author).

Table 6. Performance analyses: wavelets (Source: Author).

Table 7. Comparison of results: the four performed tests (Source: Author).

Table 8. Comparison of results: by asset (Source: Author).

In order to compare the performance of WI and Technical Analysis indicator, like MACD and RSI [16] [17] , the test considered time series from all assets, evaluating every drop threshold separately. The buy signals were the local minima (the start of the movements) from each drop threshold and the WI calculation used the best combination of parameters, according to Table 4 and Table 5. Table 9 brings the average performance for each indicator, together with the return of the assets through the studied period (based on a buy-and-hold strategy).

6. Conclusions

This research evaluated the applicability of the Wavelet Index to detect trend reversals in Brazilian stock market, testing different combinations of wavelets, number of scales and thresholds to generate sell signals and detect drops of different intensities.

The test results indicate that the proposed method to calculate the Wavelet Index detects successfully trend reversals followed by significant drops (over 10%) in the Brazilian stock market. When evaluating drops over 15% on the selected assets (Bovespa Index and 14 stocks from BM & FBOVESPA), the Wavelet Index presented average early sale losses of 45.0% in the search group and 43.9% in the test group, with no false negatives, using Meyer wavelet in 4 cases, Haar and Gaussian 1 wavelets in 3 cases each.

These results also point that the Wavelet Index had limited success when detecting trend reversals followed by minor drops (5% and 10%). The critical phenomena model using the log-periodic power law based the development of this Index, therefore this result indicates weak adherence of the minor drops to the proposed model.

It’s interesting to highlight that performance using the maximum number of scales to the Continuous Wavelet Transform was better than the performance using only 30 scales in 60.8% of the tests.

The Wavelet Index performance to detect trend reversals on the studied assets was superior to the tested Technical Analysis tools (MACD and RSI) to drop equal to or larger than 10%, 15%, 20%, 25% and 30%. An investment simulation based on the sell signals generated by Wavelet Index had average performance of

Table 9. Performance evaluation: average return by drop (Source: Author).

+693.2% (to drops over 20%), comparing with RSI’s +388.5% and MACD’s +344.6%, both to drops over 10%. All tested tools had better performance than the average return of the asset, considering a buy-and-hold strategy (+45.13%).

We are currently working on a new methodology to improve the accuracy of both the sale and purchase of the assets, using the combination of the Meyer wavelets in conjunction with the Haar wavelet.

We believe that with this proposal the success rate, based on the results obtained in Table 6, it is possible to reach 75% accuracy levels.

Funding

This work was partially supported by the Coordination for the Improvement of Higher Education Personnel―CAPES/Brazil.

Conflicts of Interest

The authors declare no conflicts of interest.

Cite this paper

*iBusiness*,

**9**, 61-73. doi: 10.4236/ib.2017.94005.

[1] |
Sornette, D. and Johansen, A. (1997) Large Financial Crashes. Physica A, 245, 411-422.
https://doi.org/10.1016/S0378-4371(97)00318-X |

[2] | Pring, M.J. (2014) Technical Analysis Explained. 5th Edition, McGraw-Hill, New York. |

[3] | Sornette, D. (2003) Why Stock Markets Crash. Princeton University, Princeton, NJ. |

[4] |
Caetano, M.A.L. and Yoneyama, T. (2007) Characterizing Abrupt Changes in the Stock Prices Using a Wavelet Decomposition Method. Physica A: Statistical Mechanics and Its Applications, 383, 519-526.
https://doi.org/10.1016/j.physa.2007.03.027 |

[5] |
Anifrani, J.-C., Le Floc’h, C., Sornette, D. and Souillard, B. (1995) Universal Log-Periodic Correction to Renormalization Group Scaling for Rupture Stress Prediction from Acoustic Emissions. Journal de Physique I, 5, 631-638.
https://doi.org/10.1051/jp1:1995156 |

[6] |
Johansen, A. and Sornette, D. (2000) Critical Ruptures. The European Physical Journal B-Condensed Matter and Complex Systems, 18, 163-181.
https://doi.org/10.1007/s100510070089 |

[7] |
Sornette, D., Johansen, A., Arneodo, A., Muzy, J.F. and Saleur, H. (1996) Complex Fractal Dimensions Describe the Hierarchical Structure of Diffusion-Limited-Aggregate Clusters. Physical Review Letters, 76, 251-254.
https://doi.org/10.1103/PhysRevLett.76.251 |

[8] |
Johansen, A., Sornette, D., Wakita, H., Tsunogai, U., Newman, W.I. and Saleur, H. (1996) Discrete Scaling in Earthquake Precursory Phenomena: Evidence in the Kobe Earthquake, Japan. Journal de Physique I, 6, 1391-1402.
https://doi.org/10.1051/jp1:1996143 |

[9] |
Caetano, M.A.L. and Yoneyama, T. (2009) A New Indicator of Imminent Occurrence of Drawdown in the Stock Market. Physica A: Statistical Mechanics and Its Applications, 388, 3563-3571. https://doi.org/10.1016/j.physa.2009.05.024 |

[10] |
Caetano, M.A.L. and Yoneyama, T. (2012) A Method for Detection of Abrupt Changes in the Financial Market Combining Wavelet Decomposition and Correlation Graphs. Physica A: Statistical Mechanics and Its Applications, 391, 4877-4882.
https://doi.org/10.1016/j.physa.2012.05.048 |

[11] |
Li, S. and Kuo, S. (2008) Knowledge Discovery in Financial Investment for Forecasting and Trading Strategy through Wavelet-Based SOM Networks. Expert Systems with Applications, 34, 935-951. https://doi.org/10.1016/j.eswa.2006.10.039 |

[12] |
Addison, P.S. (2002) The Illustrated Wavelet Transform Handbook. IOP, Bristol.
https://doi.org/10.1887/0750306920 |

[13] | de Oliveira, H.M. (2007) Análise de sinais para engenheiros. Brasport, Rio de Janeiro. |

[14] | Morettin, P.A. (1999) Ondas e ondaletas. Universidade de Sao Paulo, Sao Paulo. |

[15] | Matsuda, E. (2006) Comprar ou vender? 4th Edition, Saraiva, Sao Paulo. |

[16] | de B. Penteado, M.A. (2008) A funcao log-periódica e sua aplicacao na previsao da reversao de tendências por meio da análise gráfica do mercado acionário brasileiro. Tese (Doutorado emAdministracao), Universidade de Sao Paulo. http://www.teses.usp.br/teses/disponiveis/12/12139/tde-14082008-102631/pt-br.php |

[17] |
Vandewalle, N., Ausloos, M., Boveroux, P. and Minguet, A. (1999) Visualizing the Log-Periodic Pattern before Crashes. The European Physical Journal B - Condensed Matter and Complex Systems, 9, 355-359. https://doi.org/10.1007/s100510050775 |

Copyright © 2018 by authors and Scientific Research Publishing Inc.

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.