# The Application of SVMs Method on Exchange Rates Fluctuation

Authors: Zuoquan Zhang; Qin Zhao
Journal: Discrete Dynamics in Nature and Society
 (2009)

---

## Abstract

Technical indicators are very important tools in the analysis of securities investment. In this paper, considering several main technical indicators prevailed in China security market, we predict whether the price of a stock rises or falls with the support vector machines (SVMs). We represent the technical indicators of current four days as input vector. If the price of next day rises, we say that the vector belongs to opposite set, if it falls, we say it belongs to negative set. Studying the samples, the SVMs construct a classification model. Then, based on the data of today and three days before, the SVMs give a prediction of tomorrow price. The experiment shows that the predicting accuracy is all greater than 60%.


---

## Body

## 1. Introduction

Technical analysis is a very important tool in the analysis of securities investment. It analyzes the past and present behavior of market by mathematical and logical methods and summarizes the typical behavior, in order to forecast future trends of the foreign exchange market. Analysis of indicators is an extremely important branch of technical analysis. Short-term operators always have their own commonly used technical indicator system, which usually based on four or five main indicators [1], supplemented by other indicators. Each technical indicator observes on the market from a particular perspective, reflecting the underlying connotations of the market.There are various technical indicators for foreign exchange investment analysis, taking into account almost all aspects of the market. Therefore, it is necessary to master a few more technical indicators. However, it is a very heavy work to analyze a large number of foreign exchange rates by using a variety of technical indicators. And it also needs a wealth of experience. In this paper, considering several main technical indicators prevailed in China security market, we predict whether the price of a stock rises or falls with the support vector machines (SVMs). Because technical indicators have specific value and the results of the analysis only have two cases, up and down, it is entirely feasible that we transform qualitative analysis to quantitative analysis. At present, the SVMs have made great achievements in the application field, such as weather forecasting, pattern recognition, and DNA classification. In the financial sector, it also has a wide range of applications, such as financial time series forecasting [2–4], stock selection of listed companies [5, 6], credit rating [7].


## 2. SVMs and Technical Indicators

SVM is a method that based on statistical learning theory. Commonly, there is a given set of training sampleT⃗={(x⃗1,y1),(x⃗2,y2)⋯(x⃗l,yl)}, in which x⃗i∈Rn is an n-dimensional input vector, whose components are known as the characters, while yi∈{1,-1} is an output vector. Besides, we define the forecast data sets x⃗l+1,x⃗l+2,…,x⃗m(m>l), by learning the data of training sample set, we establish classification model y=M(x⃗), then the forecast data can be classified correctly, in another word, corresponding to the x⃗j(l<j≤m), we can get the output data yj(l<j≤m). The method of technical indicators is based on the past historical data, and with some discriminate indicators which derived by using specific mathematical formula, then predicts the trend of foreign exchange rates in the future. So, it is reasonable that we select a set of indicators of foreign exchange rates as input data. If the forecast exchange rate will rise, then we have the output data yi=1, otherwise yi=-1. Taking the Granville rule, that is, the rule of MA line, for example, (1) the average line becomes even after descent, and the price line crosses average line underneath; (2) price has risen continuously and walk away from the average line, then falls suddenly, and rises again near the average line; (3) the price line is under average line, which has fallen for long time, and is far from average line. The three conditions talked above are all buying signals. Skilled operators can combine their experience and these rules, inspect the relationship between the price line and MA line of 4 or 5 days ago, and make their decision to sale, buy, or just stay. We can also use the SVMs to do this. Take the data of exchange rates and MA line of 4 or 5 days ago as input vectors, using nonlinear mapping map the input data to a high-dimensional space, then depending on the model which is adopted from the training samples, we can decide whether we sale or not. One of the basic assumptions of SVMs is that “the hand of God” will select the input data of the sample set. We believe that the selection of data sets is regular (and in this case, part of the regulation is represented by the relationship of positions between the price line and the MA line). However, we cannot completely confirm this regulation. We can only learn on the training samples by experience to look into one point of the mystery. So, the operators find the Granville rule, while the support vector machine finds the classification model.To determine whether the price of an exchange rate rises or falls, the operators need plenty of operating experiences, after studying a variety of technical indicator lines of recent, and then make decisions. However, the Support Vector Machine needs to study the historical data of exchange rate, and then establishes a classification model. It only uses the price data that a few days before, and input the recent technical indicators data which calculated by the computer program, and by then it can make the decision whether the exchange rate will rise or not. Classification model does not need to update every day, in principle, it will not need to relearn as long as there are no major changes of the exchange rate structure, but we are best to learn at intervals of every cycle of movement. It is worth pointing out that, whether the classification model of sorter can give a valuable forecast, that is, whether their classification is valid in theory? At this point, Takens theorem gives an affirmative answer. The theorem says that, under certain conditions, between the vectors composed of the past and future values of time series, there is a smooth mapping. Based on our common sense on market, this smooth mapping does not exist in the series of exchange rate, but we can input other market information, such as volume and various technical indicators, in order to study the samples, and then construct a classification model.


## 3. The Technical Indicators Model Based on SVMs

Support Vector Machine is developed from the Learning problems of statistics. Learning problems often can be expressed as follows. We already known that there is an unknown relationshipF(x⃗,y) between the output variable y and the input variable x⃗. Based on l independent and identically distributed samples
(3.1)(x⃗1,y1),(x⃗2,y2)⋯(x⃗l,yl),
an optimal function f̅(x⃗,a0) is selected from a group of functions {f(x⃗,a)}. We say the function is best, because it can minimize the Expected Risk Prediction
(3.2)R(a)=∫Q(y,f(x⃗,a))dF(x⃗,y).
The function {f(x⃗,a)} is called Learning Function Collection, a∈Λ (Λ is generalized parameters set), while Q(y,f(x⃗,a)) is called Losing function. In the classification problems, the loss function is usually defined as follows:
(3.3)Q(y,f(x⃗,a))={0ify=f(x⃗,a),1ify≠f(x⃗,a).
The learning goal is to minimize the R(a), known as expected risk minimization criteria.Foreign exchange technical indicators analysis can be described as a general learning problem. Firstly, we recognize that technical analysis is valid; that is, technical indicators and exchange rate trend have some intrinsic link. Supposing that the change of pricesy and technology indicator x⃗ have a functional relationship F(x⃗,y), the goal of learning is that to find a function f̅(x⃗,a0) which minimizing the Expected Risk, by using a large number of samples. Here, the inputs are the technical indicators, and the outputs which indicate the change of the future price are derived basing on the relationship f̅(x⃗,a0).The change of the price only has two situations, up marked by1 and down by -1. However, the selection of input variables is not that easy. As for, there are many different types of technical indicators, the market software can provide hundreds of technical indicators in general. There are mainly four kinds of indicators: the trends, the over buy and sale, the best seller, and the most potential. Because of the difficulty of collecting data, in this paper, we did not select the indicator from the kind of the most potential. Refering to [1], we select five kinds of technical indicators appropriately which are more popular and effective in the foreign exchange market, including MA (moving average line), MACD (moving average convergence and divergence line), KDJ (random index), RSI (the relative strength index), and BIAS (bias index). Their calculation formulas are as follows.(1)
The trends
(i)
MA:(3.4)MAt(n)=1NCt+N-1NMAt-1(n)
in which, Ct is the stock price on the current day, n is the number of days, t means time; n=5,10,20,50.(ii)
MACD(3.5)MACD=2(DIF-DEA),DIF=EMA(12)-EMA(26),DEAt=210DIFt+810DEAt-1.
Of which,
(3.6)EMAt(n)=2N+1Ct+N-1N+1EMAt-1(n).(2)
The Over Buy and Sale
(iii)
KDJ:(3.7)Kt=23Kt-1+13RSVt,Dt=23Dt-1+13Kt,J=3D-2K.
Of which,
(3.8)RSVt(n)=Ct-LnHn-Lt×100%.
Here, Hn and Ln represent the highest closing price and the lowest closing price in n days, respectively, and n=9.(iv)
RSI:(3.9)RSI(n)=AA+B×100%.
Finding out the closing prices in n+1 days, including the current day, and then we can get n digits by using the daily closing price minus the closing price on the day before. Here A= the sum of positive numbers in the digits, while B= the sum of negative numbers ×(-1); n=6,12,24.(v)
BIAS:(3.10)BIAS(n)=Ct-MA(n)MA(n)×100%,n  =  5,  10,  20,  50.The goal of traditional statistical learning theory is to minimize the empirical risk, for example, the regression analysis. But this would result in over-fitting. Vladimir N. Vapnik's statistic learning theorem introduces the two components of real risk, the empirical risk and the regularized risk. In the process of statistic learning we try to minimize the real risk, that is,(3.11)R(a)<Remp(a)+Φ(lh).
Here, Remp(a) represents the empirical risk; while Φ(l/h) represents the regularized risk, which is depended on the number of the training sample l and the VC dimension of learning function set {f(x⃗,a)}. The SVM is to optimize both empirical risk and regularized risk, which both have smaller errors and can avoid over-fitting. Therefore, the model will provide better generalization ability, that is, it will have good predicting ability.To select the functional relationship,F(x⃗,y), by using the SVMs, is to solve the following quadratic programming problem.(1)
Given a training sample,(x⃗1,y1),(x⃗2,y2)⋯(x⃗l,yl) where x⃗i∈Rn, yi∈{1,-1}, i=1,2,…,l.(2)
Well choose a kernel functionK(x⃗,x'⃗) and a penal parameter C, then construct and solve the optimal problem
(3.12)minα12∑i=1l∑j=1lyiyjαiαjK(x⃗i,x⃗j)-∑j=1lαjs.t.∑i=1lyiαi=00≤αi≤C,i=1,2,…,l.
Find the optimal solution α⃗*=(α1*,α2*,…,αl*)T.(3)
Choose a positiveαj* in α⃗*, satisfying 0<αj*<C. And according to it work out b*=yj-∑i=1lyiαi*K(x⃗i,x⃗j).(4)
Construct the decision-making functionf(x⃗)=sign(∑i=1lyiαi*K(x⃗,x⃗j)+b*), where sign(·) is a symbol function.


## 4. Empirical Research

The change of an exchange rate depends on the government policy adjustment. Stock prices are closely related to the results of their fundamental analysis. Generally speaking, the change of an exchange rate is more close to stochastic process. We choose the historical data of the euro/dollar exchange prices for research, and the data is from the Bloomberg. The value interval is from July 10, 2007 to July 9, 2009, which includes 523 days’ data. And then the six kinds of technical indicators can be calculated, respectively, by these price data. However, some of the parameters were too large, such as MA (50). The value of first 50 days’ data of MA (50) does not have practical significance. So from the 60th day, we start to select indicators data for 463 days. And then the price has a correspondence output result every day, which rise or fall differently (variation≤0.5% is seemed as no change). When the result rises yi=+1, it falls yi=-1, besides (it has no change) yi=0.The input vectorxi→ takes the indicators and price data of i-4,i-3,i-2,i-1 days’, that is, x⃗i=(P,MA,MCDA,K,D,J,RSV,RSI,BIAS)', in which P,MA,MCDA,K,D,J,RSV,RSI,BIAS∈R4. Every indicator takes four days’ data, and the meaning of words is a little different from before. Ignoring those days of data when yi=0, then we can use the Support Vector Machine to classify prices according to their rise or fall.We choose to use Gaussian Radial Basis Function (RBF) as our Kerner function(4.1)K(x1→,x2→)=exp(-∥x1→-x2→∥σ2),
in which σ2 is the parameter.When we solve the optimal problem, we choose to use the quadprog function from the optimal toolbox of MATLAB. As it does not have definite method of finding out theσ2 and the optimal values of the punishing parameters C, we would better to use “heuristic searching method.” The main ideology is to use the cross-test and the wide-area searching method. From a larger range, we found out the best cross-test results of the two parameters σ2 and C. But from the searching process, we found that the predict accuracy is not sensitive to σ2 and C (shown in Table 1).Table 1
Accuracy rate with different parameters.
CategoryThe training  sampleThe forecasting samplesTotal number21750Positive number13523Negative number13227Correct classification72%60%Table 2
Predicting results of USD/EUR.
σ2C50001000050000100000150000105565458565810652526060582*10644525460585*1063842525460In Figure1 the dotted line shows the actual profit rate for predicted samples. “+” point line shows that the price rises, and “o” point line shows that the price falls. From Figure 1, the numbers of actually rising days were 23, and there are 11 days that were forecasted correctly. On the other hand, the numbers of actually falling days were 27, and there are 19 days that were forecasted correctly. If we use the forecast results to do some investment operations, the profit rate would be 28.24%. This method will be effective for other exchange rates forecasting analysis. In this paper, we have only list several main exchange rates forecasting results, which were shown in Table 3.Table 3
Predicting results of other exchange rate.
CategoryUSD/JPYUSD/AUDValue interval2007.7.10–2009.7.92007.7.10–2009.7.9The number of training sample223268The number of forecasting sample5050σ25000050000C300005000The forecasting accuracy of training80.72%70.04%sampleForecasting accuracy62%60%Figure 1
Predicting results of USD/EUR.


## 5. Results

It can be found from the results that Support Vector Machine has high correct classification rate, especially for theforecasting sample. It is encouraging that we canmake this kind of prediction results, no matter how complex the financial market system is. From a practical perspective, we do not know whether the future exchanges are obviously different (in this paper, i.e., whether the variation>0.5%). When we calculate the rates, it is still necessary to modify the decision-making function f(x⃗) according to the actual situation. Regardless of how the future exchange rates change, we can always use Support Vector Machine to forecast.Set(5.1)z=∑i=1lyiαi*K(x⃗,x⃗j)+b*.
And then the decision-making function is f(x⃗)=sign(z). Obviously, the larger the absolute value of z is, the more accurate the classification is. We can set that the decision-making function f(x⃗) is valid when the absolute value of z is more than a particular value z̅. In the case of EUR/USD, when the training sample set was tested by decision-making function, the scope of z was [-0.8,0.8]. So we can take z→=0.1. And then the prediction accuracy of the test samples will reach 63.2% for future 50 days. In order to improve the forecasting accuracy, we can increase the value of z. For example when z→=0.5, the forecasting accuracy can reach 69%.  As the value of z increases  there will be more data points that cannot made predictions. It is a dilemma that whether we should give up more data points. On one side, we must give up more data points that cannot help to make a judgment to improve the accuracy. On the other side, it means lower prediction accuracy that uses more data points as much as possible.



---

*Source: 250206-2010-02-08.xml*