Share This Article:

Application of Wavelets to Detect Trend Reversals on Brazilian Stock Market

Full-Text HTML XML Download Download as PDF (Size:975KB) PP. 61-73
DOI: 10.4236/ib.2017.94005    301 Downloads   594 Views  

ABSTRACT

This study develops a method to detect trend reversals followed by significant drops in Brazilian Stock Market using wavelets. Applying the concept of the log-periodic power-law, whose oscillations present reduction in amplitude and period as the critical moment approaches (where there is a higher probability of market drop), it used the Continuous Wavelet Transform to detect the increasing oscillation frequency in the stock price, time series and generate sell signals. An algorithm was developed to test different kinds of wavelets and parameters to calculate the Wavelet Index, evaluating whose combination of parameters brings the best results and comparing these results with the existing Technical Analysis tools. The results show that the proposed method to calculate the Wavelet Index detects successfully the significant drops (over 10%) in the Brazilian Stock Market. Considering drops over 15%, there were losses due to early sales of 45% (average) in the search set and 43.9% in the test set, without false negatives, using mainly the Meyer wavelet. Its performance was also better than existing Technical Analysis tools, like MACD and RSI.

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 tc is the instant where the crash is more probable. The parameter A is the asset price when t = tc, β 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 ( t ) = A + B ( t c t ) β + C ( t c t ) β cos ( ω ln ( t c t ) ϕ ) (1)

The log-periodic power law characteristically reduces the amplitude and the period of its oscillations as the critical moment (tc) 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 ψ ( t ) 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 = | ψ ( t ) | 2 d t < (2)

2) Being ψ ^ ( f ) the Fourier Transform of ψ ( t ) , 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. Cg is the wavelet’s admissibility condition and changes to each wavelet type.

ψ ^ ( f ) = ψ ( t ) e i ( 2 π f ) t d t (3)

C g = 0 | ψ ^ ( f ) | 2 f d f < (4)

The Continuous Wavelet Transform (CWT) T ( a , b ) 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 / a is used to keep the same energy all scales of the wavelets.

T ( a , b ) = 1 a x ( t ) ψ ( t b a ) d t (5)

In a more compact form:

ψ a , b ( t ) = 1 a ψ ( t b a ) (6)

T ( a , b ) = x ( t ) ψ a , b ( t ) 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 ( a , b ) ) are in the axis Z. This graph is usually a contour curve, where the different colors represent the magnitude of T ( a , b ) .

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 ( a , b ) ) to the signal energy is given by Equation (8). The graph of E ( a , b ) 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 ( a , b ) = | T ( a , b ) | 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 ( t ) = A + B ( t c t ) β (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 tc:

I ( t ) y t ( t ) = C ( t c t ) β cos ( ω ln ( t c t ) ϕ ) (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 ncoefmax 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.

W I = N n c o e f 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―1st derivative (gaus1) e 4th 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

Penof, D. and Belardi, A. (2017) Application of Wavelets to Detect Trend Reversals on Brazilian Stock Market. iBusiness, 9, 61-73. doi: 10.4236/ib.2017.94005.

References

[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

  
comments powered by Disqus

Copyright © 2018 by authors and Scientific Research Publishing Inc.

Creative Commons License

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