EKF Finance
EKF Finance
Forecasting Trend and Stock Price with Adaptive Extended Kalman Filter Data Fusion
Abstractobtaining to the method with the least prediction error is one of the challenging issues of financial and investment markets analyzers. Investors often use two different views of technical and fundamental analysis of prices for buying and selling their desired shares. But each of these two methods alone may have not enough performance due to differences between the actual value of the share and its market price. This paper presents a predictive model named extended Kalman filter which simultaneously fuses information and parameters of technical and fundamental analysis. Then as a real test, the model implemented for the shares of one of industrial company in Iran. Finally, the obtained results will be compared with other methods results such as regression and neural networks which shows its desirability in short-term predictions
Keywords- Stock exchange, data fusion, Extended Kalman filter, technical and fundamental analysis.
I.
INTRODUCTION
The development and economic growth in each country has direct relation with the investments done in that country. So that in the developing country, capital formation is considered as an important factor in economic growth and making the process for development. In developed countries stock exchange is an official organization for capital, through attracting investment and stagnant savings of the society and conduct their affairs in production which led to increase economic growth and prosperity has been produced and this way effect on macroeconomic variables such as GDP, money, inflation and interest rates. That's why stock market boom and mobility known as a criterion of dynamic economies of the countries. Todays, investing in stock is an important part of society and economy, in the other hand, stock price volatility in the all stock exchanges is commonplace. Stock prices affected by external and internal factors like political, economic and etc, so the stock price prediction for capitalists is very important to be able to return most of their investment will earn. Meanwhile, given the unavailability of accurate
information about the factors affecting stock market fluctuations and of unknown factors affecting stock price changes, due on bringing people to predict price changes by the companies but this simply not possible. Generally there are two viewpoints of analyzing: Technical analysts and fundamental analysts. Technical analysts can calculate the intrinsic value of stock. They believe that the market has undergone a pseudo psychological mode and history is always repeatable and patterns at any time cause reputation of trends of price. Therefore by studying the past trend, the future could be predicted [1]. But in terms of fundamental analysts, the stock market has no memory and prices are changed randomly. As noted, the main purpose of technical analysis is predicting trends of stock price. However, predictions are often not correct and have some errors that the rate decreases with increasing of information. The other comment which was raised said: technical analysis based on the weak principles. For example, the expectation that some of historical patterns of the share prices will be repeated in the future may not necessarily occurs, because market conditions will change over time. But in 1970, Fama presented a new hypothesis which is called efficient market hypothesis (EMH), it is commonly believed that in each period of time, asset prices such as stock prices reflect all information about them [2]. And all Technical or fundamental analysis and prediction are failed. But this simple idea was a lot discussed of controversial financial investigators. In many of the arguments raised against the theory of market efficiency, there have been identified and repetitive patterns for prices, there are examples of this case, we can mention like: January effect or Blue Monday in Wall Street which are some of those predictable repetitive patterns [3]. According to a research done in Iran stock exchange market, very poor efficiency was dominated and a specific pattern of behavior can be observed in the changing of prices, so awareness of this model can help investors to obtain more benefits [4]. In the recent years many researches were done in this area, some tried to resolve the problem by classical methods such as exponential smoothing, trend analysis, and regression equations (Farrell, 2007), some uses intelligent methods such as neural networks and fuzzy or combination
119
methods. But a lot of bugs to any of these methods are entered. as a further example linear prediction models are used in the methods, whereas in reality most processes are nonlinear. Or intelligent methods require a lot more data for the learning system. in the absence of data; models of changes are not correctly identified and systems shall operate incorrectly in non-trained conditions. Or even the difference between the expected price stock market prices and lack of adherence to the theoretical model, prevent correct prediction of prices. This study presented a model, based on technical analysis in stock market prices. Method used in this study is kind of time series entitled the Kalman filter which acts based on analyzing change of data versus time. But according to the past researches on stock market areas, the use of linear models are not capable of predicting prices in the long time, so a kind of advanced methods which is called extended Kalman filter algorithm will be used, The advantage of developing this type of filter is able to use non-linear models as main system model [5]. By the data fusion method of extended Kalman filter the possibility of combining different indicators used in the fundamental analysis like economic variables with technical analysis and general trend of change is possible. II. EXTENDED KALMAN FILTER Kalman Filter is created from the name Rudolf E. Kalman in an article which was published in 1960 that presents recursive solution to filter the linear discrete data [6]. Kalman filter actually is a set of mathematical equations that is type of optimally estimator, predictor and corrector which sensibly minimizes the estimation error covariance [7]. Kalman filter is trying to understand the general issues n which are to estimate the state of X R discrete-time control process that has linear differential function. Now what happens if a process that should be estimated and (or) relationship with the measurement process is nonlinear? Many successful and interesting applications in the Kalman Filter are in these conditions. The Kalman filter that linear mean and covariance of states is known extended Kalman filter (EKF) [8]. n Assume that the process has X R state vector. and process given with a nonlinear random differential equation.
z k [9].
K k = P C k (C k PK C k + R) 1 k = x k k x + K k ( z k h( x ,0))
Pk = Ak ( I K k C k H ) P A
III.
+Q
According to the previous Section about the trend of change in stock price and the reasons offered by the stock market technical analysts, it seems that there is a strong relationship between price changes and the time. But according to fundamental analysts comments the internal and external economic factors originally influence on stock prices. Therefore, after different ways that were examined, this was resulted, perhaps the Kalman filter _according to its computational features that were introduced in the previous section_ is capable for data fusion of both stock market analysis and forecasting a more realistic price based on economic and time variables. So in this section a structure with multi input-output was developed which had an extended Kalman filter in its heart, Structure designed to combine information of fundamental and technical analysis presented as below. According to the structure data are entered from two sides. The first part is some economic and financial parameters used by that fundamental analysis. These variables after moving to the structure put in the system model and then changes to price.
x k = f ( x k 1 , u k 1 , wk 1 )
m By measurement z R in which:
(1)
(2) z k = h( x k , v k ) Where the random variable wk and v k represents the process and measurement noise. In this equation, nonlinear function of f in the differential equation 1 related to the state in the previous time step to current time k .These are also include function parameters u k and zero mean noise process ( wk ). Nonlinear function
h in measurement
Figure 1.
120
Second part is the general trend of market prices _which is technical analysis data. Kalman Filter can estimate and predict data with normal distribution. Therefore, it should be check if the stock price follows the normal distribution? According to the conducted research the answer is yes. Histogram on stock price of each company of Iran was drawn and then the normal curve was adjusted on the histogram and compared, the price changing of the shares follow from the normal distribution [10]. Next section is about implementation of the model on the stock of an industrial company as case study. IV. MODEL IMPLEMENTATION To implement the model, 183 records of information for one year of Bahman industrial group were explored from RAHAVARD NOVIN software. The following diagram shows trend of stock price.
Here, u are the financial and economic parameters of the stock market environment. On the other hand the technical analysis of data related to stock price changes, as input prices obtained from previous occurred observations_ are calculated in the function h and then entered to the EKF. k = h( x k , v k ) (8) z As mentioned in the previous section the Kalman filter performance need the use of parameters like Q , R , Wk and
Vk . These parameters are always set practically. Now lets calculate the statistical parameters by using available data. Q is covariance of process noise [11]
To calculate Q according to the parameters definition, an interval stock price changes should be calculated. For this purpose, in a specified period (one year) change in stock price Bahman Group is calculated by the formula.
e i (n) = Pi (n) - Pi (n - 1)
(9)
Figure 2.
The stock price trend of an industrial company in Iran in one year Figure 3. change of the stocks prices of the company during one year
To implement the model, other parameters such as EPS, efficiency ratio, market efficiency and the coefficient , were required for calculating the expected actual return and making economic model of stock price of Bahman group. After exploring data from the RAHAVARD NOVIN software, now, according to available information, the Gordon model can be assumed as a system model for the stock like Bahman group.
P0 =
E 0 (1 bi ) k i bri
parameter_ the difference between real price and the state model price. According to below equation:
ei is 0.777 which is Q , and according to p ( w) ~ N (0, Q) , Wk is calculated 0.001. R Is calculating, by_ considering the definition of the
The error variance
(6)
(10)
Where, P0 is the price of the stock in the first year, b, the percent of held interest, k, is Expected rate of return on shareholders, r, investment efficiency rate, br, is dividend grow rate. According to the parameters available in Fundamental Analysis, Gordon model was assumed as input state model of the system in this project.
x k = f ( x k 1 , u k 1 , wk 1 ) =
E 0 (1 bi ) k i bri
(7)
121
Figure 4.
Figure 5.
Prediction diagram of the next day stock price by EKF data fusion
f k , uk ) = Ak = f ( x E
f b
En (1 b) (k n - brn ) 2
f k
f br
(11)
1- b Ak = k n - brn En k n - brn En (1 b) (k n - brn ) 2
(12)
y k = h( x k ) + v k
(13) hx k ( n) = 0.0082n + 0.0467n + 1101.1 (14)
2
Figure 6.
k ) = 0.0164n + 0.0467 C k = h ( x
(15)
The extended Kalman filters formulas are according to equation (3), (4) and (5) mentioned in the previous section with the respect of price changing.
In the above graph, reduction of the error in the predicted price in compare with the actual price after leaving the Kalman filter is observable. In continue, for more examination of the method, forecasting was done in the different horizon of time. Table I shows the result of the experiments.
WITH EKF MODEL
TABLE I.
STOCK PRICE PREDICTION IN DIFFERENT TIME HORIZON Predicted price 1496 1681 1584 MSE 25.9 62.7 25.7 MAE 156.76 53.9 39.6
Pk = Ak ( I K k C k H ) Pk AT k + Q
V.
RESULTS
(19)
After the implementation of the simulated structure code with MATLAB 7 following results were obtained. For example, after analyzing of one year data by the structure the next day is predicted.
VI.
CONCLUSIONS
This article was trying to predict stock prices of the stock market in the short term, relying on a new fusion method called extended Kalman filter that enables to use fundamental analysis of stock price with technical analysis.
122
In the presented structure, simultaneous analysis of technical data (with the indicators) with fundamental analysis data (with financial variables that include general stock price model) were entered to prediction-correction filter named extended Kalman filter. Then, after statistical and possibilities calculation, a new stock price will be presented as the algorithm predicted price to the user. As the graphs in Figure 5 and 6 shows, it is clear that the error of prediction reduced much after passing through the filter, which shows the proper efficiency of the presented model in this research. Data in the table II, compare the calculated error values predicted in the three offered methods for the same time horizon of the same company [13]. For better comparison, scientific indicators such as mean square error (MSE) and mean absolute error (MAE) was measured for each method to show the success of the algorithm in this paper.
TABLE II.
ERROR COMPARISON IN DIFFERENT METHOD OF PREDICTION
[12] S.Maybeck,P.Stochastic models, estimation and control, Harcourt Brace Jovanovich Publisher , Academiv Press. 1979.. [13] Todd F., M.. Correa, A..,Gaussian Process Regression Models for Predicting Stock Trends, MIT technical report , 2007.
Methods Regression method Artificial neural networks Extended Kalman filter data fusion
REFERENCES
Pring, Martin J. Introduction to Technical Analysis;, Mc Grow Hill.1998. [2] Fugence,F. Fama., Efficient Capital Market: A Review of Theory and Enprical Work, The Journal of Finance, No.2, May1970, PP.383-417. [3] Donald B., Keim., Size-Related Anomalies and Stock Return Seasonality: Further Empirical Evidence, Journal of Financial Economics 12 , 1983. [4] Namazi, Mohammad, Shvshtryan, Zkyeh., "Stock Market Performance Analysis of Iran. Stock Exchange Market", Journal of Financial Research and Scientific Research, Second Year, No. 7 and 8, pages 82-104. 1994. [5] Qi, M. & G.S. Maddala, Economic Factors and The Stock Market: A New Perspective;, Journal of Forecasting18, pp: 151-166. 1999. [6] Kalman,R.E,A New Approach to Linear Filtering and Prediction Problems, Transaction of the ASME-Journal of Basic Engineering (series D):pp: 35-45. 1960 . [7] McMillan, D. G. Non-Linear Predictability of Stock Market Returns: Evidence from Non-Parametric and Threshold Models, International Review of Economics and Finance, Vol.10, pp. 353-368. 2001. [8] Welch, G., Bishop,G. An Introduction to the Kalman filetr. by ACM, Inc. 2001. [9] Haykin, Simon, Kalman Filtering And Neural Networks, AWiley&Science Publication,2001, ISBN 0-471-36998-5. [10] Francis, J.C., Investment: Analysis and management,New York, 1972, McGraw-Hill. [11] Huang , Shian-Chang, Online option price forecasting by using unscented Kalman filters and support vector machines, Journal of Expert Systems with Applications 34 , 2008, 28192825. [1]
123