### Developers Club geek daily blog

2 years, 9 months ago

The group of the Brazilian scientists published the research devoted to creation of the tool for a prediction of behavior of the assets bargaining in stock market. In work the detailed description of a method and method of calculations for similar forecasts is submitted. We present to yours the most interesting moments of this document.

#### What is the adaptive filter

The adaptive filter is the tool capable to self-training for achievement of the set level of compliance of the output data to the real situation. Adaptivity is understood as an opportunity to react to changes of input data in real time for achievement of higher performance. In practice, adaptive algorithms are implemented by two classical methods — method of a gradient and the least squares (LMS and RLS). The similar filter can be used for a wide range of tasks — filterings, spectrum analysis or search of signals, etc.

In figure 1 the universal scheme of use of the adaptive filter in a predictive framework where k is number of iteration, x (k) — an incoming signal, y(k) — the output of the adaptive filter which is the forecast of the desirable answer of d(k), and e(k) — the error signal defined as a difference between the desirable answer and an output of the filter, that is e(k) = d(k) — y(k) is submitted.

The recursive adaptive algorithm of the least squares (RLS, recursive Least-Squares) allows to try to obtain the high performance and speed of convergence when using in variables in time environments.

Fig. 1. The general block map of the adaptive filter for a prediction of signals

One more important parameter is a so-called window of supervision, that is the time period of the analysis which usually has rectangular or exponential compliance. The parameter controlling compliance and duration of a window of supervision is called zabyvaniye coefficients `λ` (it is applied to memory of algorithm), `0 << λ < 1` and object function looks so:

This function is convex in multidimensional space `w(k)`, that is ξd(k) has only one global minimum and any local minimum. Thus, we can reach this point, having set a gradient ξd(k) equal to zero that will lead to such formula:

#### Use of the adaptive filter in a framework of predictions of stock prices

Objective of this research — to understand, the option with use of adaptive filtering as the tool for a prediction of stock prices at the real exchanges is how viable. The adaptive LMS filter was successfully used to a traffic prediction in the wireless networks [Liang (2002)]. In the current case adaptive filtering was used for receipt of an assessment of a possible value of the stock of shares of the company of Petrobras bargaining at the Brazilian exchange Bovespa in São Paulo (PETR3 ticker).

For creation of the module of a prediction of the movement of the price of PETR3 the adaptive digital FIR filter with 100 real coefficients was used. As algorithm of adaptation RLS with coefficient of a zabyvaniye 0,98 was used. Also the window of predictability of 16 days in size was used. Simulation was made on the MATLAB platform, as input data trade information during the period with 01/03/2000 to 09/23/2009 was used. Values of day stock prices correspond to the moment of closing of auction. In figure 2 convergence of coefficients of the adaptive filter which is used during creation of predictions of the movement of the price of PETR3 is shown.

Fig. 2. Convergence of coefficients of the adaptive filter started for generation of predictions of stock prices of the Petrobras company (PETR3 in the Brazilian stock market).

Evolution of coefficients of filtering clearly shows existence of convergence during the period which is approximately matching prediction time. On abscissa axis the number of the trading days participating in simulation is celebrated. The real assessment of the stocks PETR3 in the Brazilian stock market during the specified period is shown by the red line in figure 3. In the same place black noted values of the prices predicted by the filter.

Fig. 3. PETR3 stock price in the Brazilian stock market in the period of the analysis for filtering. Red the real market trend, black — the assessment generated by the adaptive filter is shown.

It is obvious that there is a compliance of the predicted prices and subjects, how are you were in the market actually. For confirmation of this fact modeling of specific trading day — specifically 2,450 day since the beginning of supervision 1/3/2000 years was carried out. In figure 4 the zoom of the prediction made the adaptive filter is shown:

Fig. 4. A prediction of stock prices in specific day

#### Performance of the adaptive filter for a prediction of the prices of the selected asset

Let's consider strategy of investments in shares of PETR3 with use of the predictions generated by the filter from the moment of 2473 (it is shown in fig. 5). Filtering is performed by means of RLS algorithm with 100 coefficients and coefficient of a zabyvaniye λ = 0,98. The estimated trend of the movement of stock prices of PETR3 on the basis of filtering for a 16-day window is displayed by a dotted line in figure 5.

Fig. 5. Behavior of an asset of PETR3 during the period with 08/18/2009 to 09/22/2009. A dotted line — a prediction of the adaptive filter, red — a real stock price in the market.

The curve of a prediction speaks about need of purchase of an asset in trading day 09/02/2009 and sales of shares at the time of 17/09/2009 — thus sale has to fall on the moment of growth preceding reduction of prices. The diagram of the actual prices says that if such strategy was implemented, then purchase of shares would take place at the price 37,86, and sale on 41,05 that would give profit in the amount of 8,43% of the volume of investment. In spite of the fact that this example is only a special case, it illustrates possible efficiency of the predictions based on adaptive filtering. Further tests for other trading days were carried out, and results generally were same.

#### Creation of the adaptive filter and accuracy of predictions

Despite positive results of tests, the offered method leaves some questions. One of them sounds so — for what type of assets it works better? What number of coefficients of FIR should be used for improvement of quality of operation of the module of a prediction? Whether Vliit value of coefficient of a zabyvaniye on result?

For an assessment of quality of the predictions made by means of adaptive filtering correlation is used - it is a similarity measure for the analysis of quality of coincidence between the predicted signal and real quotations at the exchange within the set prediction window.

The analysis of accuracy is performed by means of studying of values of correlation as functions of number of coefficients of the filter and the prediction window size. In figure 5 it is shown 3D - the diagram of correlation between 08/18/2009 and 09/22/2009:

Fig. 6. Correlation 3D - the diagram between the predicted signals and real stock quotations.

Diagram 6 was converted into the three-dimensional planimetric diagram provided in figure 7. On it the zone of the increased correlation between the generated predicted signal and real stock prices in the market is better visible.

For studying influence of number of coefficients of the filter for adaptive predictions the side profile of space from figure 6 (it is represented in fig. 8), in which the correlation peaks visible to the observer who is in the right part of space are noted was created. It is obvious that section between 30 and 100 coefficients represents high correlation. Respectively, use 30 and smaller number of koefftsiyent is not enough for receipt of an exact prediction.

Fig. 8. The correlation profile considering number of coefficients.

The first section of high correlation is not especially useful as it can be reached only at very small window of a prediction. The best option in this specific scenario is the choice of number of coefficients between 60 and 100.

Then for prediction window impact assessment on quality of the received forecasts, the front profile of three-dimensional space from figure 6 (fig. 9) was created. On it the behavior of the maximum correlation taking into account the prediction window sizes is shown. It is obvious that the choice of very short window leads to high correlation (validly, stock prices of the trading days going one after another show high correlation). However it practically gives nothing to us in respect of creation of strategy of investment in stock market.

Fig. 9. A correlation profile taking into account the prediction window size (from 1 to 30 trading days of the Brazilian stock market).

Unexpected result — experiments showed that the choice of a window of a prediction about 10 days in size is extremely inefficient. On the contrary, predictions at a window in about 15 working days show much the best results. Just as it was supposed, too long windows of a prediction lead to decrease in a korrelyuyation.

Thus, the most optimum window of a prediction in this specific case are 15-20 days.

Summary information on the number of the used coefficients, length of a window of a prediction is provided in table 1, dates of purchase and sale of shares it agrees the strategy offered by the filter, the price of transactions, and also the general profit of transactions.

Apparently, use of the adaptive filter allowed to achieve receipt of profit, on average, in the amount of 7% of the volume of investment.