In the First part I made an overview of currency market in Ukraine. In this part I will make a small overview of econometrics theory. Let’s start.

From the mid 20th century till nowadays engineers have been trying to use and design different forecasting methods. Nowadays this direction is a part of “Machine Learning” that includes a lot of science parts. Also Machine Learning is available on software suits and can be used in some programming languages: Python, C, R.

Well, I am a .NET developer and I am interested in Machine Learning libraries for .NET. Not so long ago Microsoft published own framework ML.Net. It gives you the ability to add machine learning to .NET applications, in either online or offline scenarios. With this capability, you can make automatic predictions using the data available to your application. Machine learning applications make use of patterns in the data to make predictions rather than needing to be explicitly programmed[6].

I got interested in time series forecasting in order to use it for financial markets. Since singular spectrum analysis is the most popular method among all ML.NET methods, I decided to use it for time series. Also I have heard from the university professor who consulted me in this topic that there are two approaches for analysis and prediction of time series — fundamental analysis and technical analysis. For successful forecasting we should use both of this methods. Also Fractal analysis becomes popular. It is based on ideas of technical analysis. I think it would be a good way to describe what is technical analysis, the “mother” of fractal analysis.

This method of forecasting is based on history prices.

The first mention of technical analysis was by Joseph de la Vega in the 17th century, for trading in Dutch markets.

In the 1920s, Richard Chabaker published several books on technical analysis, which developed the work of Charles Dow and Peter Hamilton in their books “Stock Market Theory” and “Technical Market Analysis”. Finally, in 1948, Robert Edwards and John Magee published the legendary book, Technical Analysis of Stock Trends.

At the end of the 19th century, Charles Dow developed what was later called the “Dow Theory” and which became the basis for modern technical analysis. The Dow theory still works, as on the first day. Ralph Nelson Elliot, William Gunn, Richard Wyckoff — all these guys at the beginning of the 20th century created what is still used. Over the past decades, many new technical tools and theories have appeared, because computer technology has made an incredible leap forward.

Fractal analysis can be a quality solution to many problems in the field of forecasting stock prices and market valuation. Its practical application is often ignored by traders and investors. However, research data is currently available, indicating that fractal time series analysis helps to effectively evaluate the presence and stability of a trend in the market.

Effective market models worked successfully right up to the collapse of the American market in 1987 (The Dow Jones index fell 29.2% in one day).

Analysts assured that this is a rare event, according to the Gauss curve, the next time something like this could come in a few million years. But then crises of 1992, 1995 followed, 1998, 2008. This contradicted all the theoretical postulates of the probabilistic approach. It has become clearly — you need a completely different look at the essence of the financial market. The answer was given by the American mathematician, founder of the theory of fractals Benoit Mandelbrot. He discovered a phenomenon that is called “thick tails.”

Mandelbrot suggested that the dynamics of stock markets is not random, but obeys some power law.

One of Significant values in analysis fractal time series is Hurst Exponent.

The Hurst exponent was proposed by H. E. Hurst for use in fractal analysis. It has recently become popular in the finance data largely due to Peters’ work. The Hurst exponent provides a measure for long-term memory and fractality of a time series. Since it is robust with few assumptions about underlying system, it has broad applicability for time series analysis. The values of the Hurst exponent range between 0 and 1. Based on the Hurst exponent value H, a time series can be classified into three categories.

H=0.5 indicates a random series.

0<H<0.5 indicates an anti-persistent series.

0.5<H<1 indicates a persistent series.

An anti-persistent series has a characteristic of “mean reverting”, which means an up value is more likely followed by a down value, and vice versa. The strength of “mean reverting” increases as H approaches 0.0. A persistent series is trend reinforcing, which means the direction (up or down compared to the last value) of the next value is more likely the same as current value. The strength of trend increases as H approaches 1.0. Most economic and financial time series are persistent with H>0.5.

In time series forecasting, the first question we want to answer is whether the time series under study is predictable. If the time series is random, all methods are expected to fail. We want to identify and study those time series having at least some degree of predictability. We know that a time series with a large Hurst exponent has strong trend, thus it’s natural to believe that such time series are more predictable than those having a Hurst exponent close to 0.5. Applying R/S Analysis to Stock Markets also an initiative of Benoit Mandelbrot. According to his studies, daily rates bank loans have a Hurst rate 0.7, while wheat prices and bond quotes are random, that is, they have H = 0.5. Simultaneously with Mandelbrot, similar studies were conducted by Edgar Peters. He discovered high Hurst values ​​for blue chips (IBM, Apple) and close to 0.5 values for the second tier. In his work “Fractal financial market analysis »Peters conducted R / S analysis of the dynamics of currency pairs and revealed a high value of the indicator H [1].

Note time series, it is desirable that the number of values was high enough (e.g. Edgar Peters when researching the stock market took about 5,000 values) [1]. We transform the data source using the logarithmic relations, and we obtain time series with level values of length n:

There are several formulas to calculate Hurst exponent. Classic algorithm is: The Hurst exponent can be calculated by rescaled range analysis (R/S analysis). For a time series, X = X1, X2, … Xn, R/S analysis method is as follows:

  1. Calculate mean value m.

2. Calculate mean adjusted series Y

3. Calculate cumulative deviate series Z

4. Calculate range series R

5. Calculate standard deviation series S

Here u is the mean value from X1 to Xt.

Calculate rescaled range series (R/S)

To estimate the Hurst exponent, should plot (R/S) versus t in log-log axes. The slope of the regression line approximates the Hurst exponent.

Also the is another Hurts formula

where H is the Hurst exponent; S is the standard deviation of a set of observations x; R is the range of the accumulated deviation Zu; N is the number of observation periods; is a given constant, a positive number.

In the work “Chaos and order in the capital markets” [2] Peters offers another option for verifying the consistency of calculating the Hurst value. If we received a high value of this indicator, then check if long-term memory exists in fact, you can, randomize position the source data.

Indeed, if the effect of long-term memory takes place, then the data order is also important for stirring the Hurst indicator is significantly will decrease. If the indicator remains unchanged, we can talk about the failure of the sample.

Methods

For rate prediction I Use two (for this moment) different algorithms. Singular spectrum analysis and Holt-Winters exponential smoothing.

SSA

Singular spectrum analysis (SSA) is non-parametric time series method which decomposes, reconstructs and forecasts time series. It incorporates tools from time series analysis, multivariate statistics, dynamical systems and signal processing [3]. The basic SSA method primarily involves two stages: decomposition and reconstruction and both stages contain two separate steps. The decomposition stage consists two steps: embedding and singular value decomposition (SVD); the reconstruction stage: grouping and diagonal averaging. These two stages make up the basic SSA algorithm [4] you can read basic article about SSA. Well, I don’t want make prediction on a paper, we just use already implemented this method from ML.Net by Microsoft. This method has an important parameter that we should mention and it’s Window size. The Window size is the only parameter in the decomposition stage. Selection of the proper window length depends on the problem in hand and on preliminary information about the time series . Knowing that the time series may have a periodic component with an integer period, to get a better separability of this components it is recommended to choose the window length proportional to that period. Theoretical results show that Window size should be large enough but not greater than 𝑁 /2

Holt-Winters

Holt–Winters models were formerly introduced in the 1960s and have been very commonly used in forecasting techniques and signal processing. The Holt–Winters model (also known as triple exponential smoothing) introduced by Winters [5] consists of three smoothing equations and a forecasting equation as shown in equations below:

Level: St=α(XtIt−s)+(1−α)(St−1+Tt−1)

Trend: Tt=γ(St−St−1)+(1−γ)Tt−1

Seasonality: It=δ(XtSt)+(1−δ)It−1

Forecasting: X^t(k)=(St+k Tt)It−s+k

where α, γ, and δ are the smoothing parameters, and St, Tt, and It are the smoothing equations known as level, trend, and seasonality. The information from the observed values (Xt) is projected through a forecasting equation k steps ahead to obtain predictions (X^t (k)).

Errors

To analyse prediction data accuracy I use two error identifications: mean absolute error (MAE) and root mean squared error (RMSE) calculated by the below formulas.

Mean Absolute Error (MAE): Measures how close predictions are to the actual value. This value ranges between 0 and infinity. The closer to 0, the better the quality of the model.

Root Mean Squared Error (RMSE): Summarizes the error in the model. This value ranges between 0 and infinity. The closer to 0, the better the quality of the model.

Results

As you read earlier I do forecasting for exchange rate for USD/UAH. I design a tool for that. You can use it via link or via telegram bot link.

For SSA I use data source from 2146 days ~6 years, series length 24 days, window 7 days

  1. Hurst exponent calculated simple formula

2. Hurst exponent calculated with 1. formula but randomize position the source data, value should be lower than source data

3. Hurst exponent calculated using classic formula via regression and source prices converted into logarithm returns from successive values of the series

4. Check data by randomize position

Also, I check on previous data. Let’s make prediction from 22 April 2020.

And original data is:

For Holt-Winters

I use data source from 2146 days ~6 years, period is 90 days length because as I covered up currency rate our financial year divided into 3 month period, prediction period 7 days. From documentation I should take data minimum for last two years. Also from documentation we should take data minimum from last 2 years because method should compare data from first year and second.

For clarity I will show data into console:

This picture shows you original rate and predicted it using SSA and Holt-Winters.

CONCLUSION

In this article I described how I tried to apply technical analysis to currency rate USD/UAH in unstable times. I applied Hurst Exponent for rate time series analysis. For calculating Hurst exponent I used two formulas: classic and formula with input data transformed using the logarithmic relations (Peters’s proposed). Two Hurst Exponents are higher than 0.5 and show us trending in the market For 2196 days ~6 years of USD/UAH rate. This means that we can try to forecast next values. For Forecasting I used popular model SSA and Holt-Winters and they showed me acceptable forecasting result for 1 week.

REFERENCES:

  1. Fractal Market Analysis: Applying Chaos Theory to Investment and Economics Edgar E. Peters
  2. Chaos and Order in the Capital Markets: A New View of Cycles, Prices, and Market Volatility, 2nd Edition Edgar E. Peters
  3. N.Golyandina and A. Zhigljavsky, Singular Spectrum Analysis for Time Series,Springer,New York (2013).
  4. N. Golyandina, V. Nekrutkin, and A. Zhigljavsky, Analysis of structure of time series: SSA and related techniques, 2001.
  5. Winters, P.R. Forecasting sales by exponentially weighted moving averages. Management
  6. https://docs.microsoft.com/en-us/dotnet/machine-learning/how-does-mldotnet-work

--

--