Generating Trading Signals by ML algorithms or time series ones?
GG ENERATING T RADING S IGNALS BY ML ALGORITHMS OR T IME S ERIES ONES ? A P
REPRINT
Omid Safarzadeh ∗ Department of EconomicsBilkent UnversityAnkara, Turkey [email protected]
July 23, 2020 A BSTRACT
This research investigates efficiency on-line learning Algorithms to generate trading signals. Iemployed technical indicators based on high frequency stock prices and generated trading signalsthrough ensemble of Random Forests. Similarly, Kalman Filter was used for signaling tradingpositions. Comparing Time Series methods with Machine Learning methods, results spurious ofKalman filter to Random Forests in case of on-line learning predictions of stock prices. K eywords Random Forests , ARIMA , Kalman Filter , Expectation Maximization , Ensemble of Random Forests ,On-line Learning , Algorithmic Trading
Prediction of stock market prices has a wide literature and is a difficult task. Nowadays, Wall-Street companies employtrading algorithms to process High Frequency stock prices. These algorithms should be able to prepare trading signals(long /short /Do nothing) based on financial technical analysis. Some of these analysis, technical indicators, are derivedfrom stock price fluctuations to signal on the direction of market. In absence of shocks to Market Fundamentals,Wall-Street companies generally use technical analysis to track and trace HF stock movements. This research willexamine how ML algorithms can be used to generate trading signals. To do so, several steps needs to be done beforeapply ML algorithms to data.
In this research, I will use Minuets by Minuets data of several stocks from NYSE. Blomberg Financial station will bethe source of stock data. Here is a sample data for Abbott Laboratories company. The data is from 1 Dec. 2017 to 15Feb. 2018 minutes by minutes intervals. There is 20277 observations of Abbott Laboratories stock price. I will alsoconsider other assets from SP100 stock index.
The above mentioned data needs to be processed to generate some information about direction of markets. Generally,this will need technical analysis with some parameter calibration to extract proper information of historical behavior ∗ Corresponding author a r X i v : . [ q -f i n . S T ] J u l PREPRINT - J
ULY
23, 2020Date Open Close Low High Value Volume Number_Ticks1 12/1/2017 16:31 170.01 170.40 170.01 170.71 8119385.00 47651 2912 12/1/2017 16:32 170.38 170.67 170.37 170.69 5024126.00 29450 2073 12/1/2017 16:33 170.68 170.39 170.36 170.95 5591862.00 32758 2204 12/1/2017 16:34 170.42 170.42 170.28 170.50 4946603.50 29027 2215 12/1/2017 16:35 170.44 170.50 170.30 170.57 5864560.50 34406 1846 12/1/2017 16:36 170.50 170.47 170.24 170.50 4071876.25 23904 150
ABT Stock Price traded in NYSE; Source: Bloomberg MinMinData − train set Time from 2017 − −
01 14:30:00 to 2018 − −
16 17:01:00 C l o s i ng P r i c e Figure 1: Abbott Laboratories NYSE: ABTof financial asset. It is very common in literature to use financial indicators to provide more information on directionof stock prices, (see [1] , [2]). These technical indicators are calculated based on daily trading data (open, high, lowand close prices) to provide patterns and trends of stock behavior in the incoming trading days. Main stream financeliterature ignores them, due to their lack of mathematical foundations following asset pricing models. [3] believed thatstock prices are following random walk process, leading that future prices are independent than todays prices; implyingno memory price time series. Efficient Market Hypothesis [4] supports random walk theory of prices by stating that,stock prices already include all information about stock value and only new information will change the price. Butthese theories are violated by some financial economist scholars by providing evidence of market anomalies ([5] and2
PREPRINT - J
ULY
23, 2020[6]). Hence, analyzing future prices based on historical data can be seen as another empirical evidence of anomalies inmarkets.[7] survey analysis revealed that almost 85 % of foreign exchange traders use both technical and fundamental analysis.They also found that technical analysis is the favorite tool of market traders. The use of technical indicators, ease the com-plexity of market prediction and transfers it to a pattern recognition problem. we can use technical indicators to providesome features of future market directions. This data transformation, will also eliminates the needs of human interpreta-tion of indicators and helps to implement automated trading algorithm. This transformation is explained in details by [8].
Following [9] paper, I will use the following technical indicators as features of daily stock prices and their parameters(see [8] for more details on parameters adjustments): • CCI (Commodity Channel Index) • Simple Moving Average (SMA) where n = 10 , , • Exponential Moving Average (EMA) where λ = 0 . , . , . • Moving Average Convergence Divergence (MACD) • Momentum: change in prices ( P tc ) for n periods. When it is above (below) zero, indicates is upward(downward) trend. n = 12 , , • Relative Strength Index (RSI) where n , , • Bollinger Bands (BB) where s = 2 , n = 20 , , • Chaikin Oscillator • Stochastic OscillatorsFor each of above indicators, there are some parameters such as number of day lags of stock and so on. Here I will useparameters adjustments proposed in [8], [9] and [10]. Using these features, I could provide almost 90 features for eachtrading days.
Once, the raw data is processed and proper features are extracted to signal the direction of stock prices, the questionis what position we should take today, to collect proper profit tomorrow. This means that we have three actions fortoday state which has some values in tomorrow state. These trading signals will be Long (Buy), Short (Sell) , and"Do Nothing". I am adding the third one as it will take into account some market frictions. Generally, it is commonin literature to not consider market frictions such as tax, transaction costs and etc. But introducing the above threeactions will be useful when the tomorrow’s return is not enough if investors have to also cover market frictions. Henceif prediction of market direction signals a bull market, we long the stock and if it is bear market we short the position.Here, I will also consider closing long (or short) positions the day after we opened the position. So our trading strategywill be as: | ˆ X t − X t − | − T AX = 0 ⇒ N oT rade (1) if | ˆ X t − X t − | − T AX > ⇒ T hen : (2) Sign ( ˆ X t − X t − ) = 1 ⇒ Long ( Buy ) (3) Sign ( ˆ X t − X t − ) = − ⇒ Short ( Sell ) (4)(5)This means, we will execute the trade if the predicted profit for next minute is higher than market friction. Thendepending on market direction we will open long/short position and we will close the position the next minute.3 PREPRINT - J
ULY
23, 2020 . . . . . . . Boolinger Bands ABT for last 120 Min of train data time in Min Min P r i c e Figure 2: Bolinger Bands financial technical indicators applied to ABT prices
Time series data are prone to have "random sampling" problem as the order of data is important. In addition, due toexternal shocks of markets, the underlying random process might not have stationary distribution. So one needs to becareful of using ML algorithms as shuffling data will cost losing auto correlation of data. This means non-stationarityof distribution of data generating process will contradict the assumption of identically distribution of data. This justifiesstationarity test of distribution of data before approaching any prediction procedure. It is well-known that stock pricesare random walk and also exhibit auto correlation in time series analysis. Detecting such behavior is possible by usingunit root tests in Times Series analysis. This is tested via augmented Dickey Fuller test (ADF) which is well known inEconometrics literature (see [11]). Appendix A, provides the R-codes and sample ADF test report for one security. Thistest is applied for all above mentioned stock prices and similar results have been found. Moreover, density plot of logreturns are also demonstrated. The Kolmogorov–Smirnov test applied to detect the probability distribution of log-returntimes series, and result was close to skewed-Laplace time series. The green plot is empirical density of series and redlines shows skewed Laplace distribution fitted to data. 4
PREPRINT - J
ULY
23, 2020 − − Skewed Lapace Density plot of log − returns for ABT log − returns F r equen cy EmpricialFitted
Figure 3: Skewed Laplace Density plot fitted to log returns of Abbott Laboratories NYSE: ABT5
PREPRINT - J
ULY
23, 2020
Two approaches has been explored by scholars to predict stock market prices: Time Series analysis and MachineLearning. The former approach considers Financial data as a linearly correlated time dependent information and tries toexplain tomorrow prices based on historical data. Machine learning techniques try to capture nonlinear relationship ofhigh dimensional stock prices. Neural Networks, Random Forests and Support Vector Regressions has been widelyapplied to forecast market prices in literature. [12] explains in details how to construct, use and apply neural networksto predict stock prices. [13] surveys on recent developments of Machine learning techniques which are used to forecastfinancial markets.
The main question of this research is which algorithm we should use to predict and generate trading signals? Whichone has superior results? Well, this won’t be difficult if we look from investor’s viewpoint. Investors don’t care aboutmethodology but their profit within a given period. Let’s call explained methods in previous section as an Expert. Sowe are facing two expert types: Time Series and Machine Learning ones. As we are using High Frequency data, weneed to define a proper Test time interval. Although it is rule of thumb to split data into 80-20 groups of data as test andtrain data. Because of sensitivity of stock prices to financial news (which are exogenous to markets) we might need toreconsider this rule. Recall that for some trading days we will have 400 observations for one asset, which will be veryvolatile. For example for Abbott Laboratories (ABT), we have 20000 observations from 1 Dec. 2017 to 15 Feb. 2018.(Figure 1). The proper time interval to check performance of several trading experts might be last two hours time periodfor all Experts. So for this time period, I will prepare profitability of each Expert based on proposed trading signal ofeach expert and then calculate the return of each signal within this time period. This will be out of bag sample for allExperts. For Cross-validation of each expert, we need to consider the same size time period. More details of how tocross-validate the results of each Expert will be discussed later.6
PREPRINT - J
ULY
23, 2020
ARIMA process simply, takes to account some lag of historical prices and weights them to predict today’s prices.Although it might look simple, the question of number of lags to take into account is not an easy task. But it is commonamong scholars to select the proper lag by considering information criterion such as Akaike information criterion (AIC),and Hannan Quinn Information Criterion (HQIC). In this we assume stock log-returns (say X t ) are related to pastprices. Then we can model: X t = α X t − + α X t − + ... + α p X t − p + (cid:15) t + θ (cid:15) t − + ...θ q (cid:15) t − q (6)(p,q) are called lag parameters. Given that log-return prices follow stationary process (refer to appendix A for moredetail.), we can estimate above procedure through MLE estimator. The proper lag parameters of ARIMA model isselected by AIC condition: AIC = − Log ( L ) + 2( p + q + k + 1) (7)For example, the ARIMA process applied to Abbott Laboratories log-returns , from: "2017-12-01" to: "2018-02-1617:01:00", and the following result is obtained. This implies that we can model the mentioned stock price as follow X t = 0 . − . X t − − . X t − − . X t − − . X t − − . X t − (8)Now according to above formula we can generate our forecast for future log-returns of underlying asset. For ARIMAprocess, I will keep 120 last observations for out of bag test and 120 as cross-validation of trading strategy.The forecast results for Abbott Laboratories for 120 Minutes are depicted in following figure. Red line correspondsto real price, and blue line depicts ARIMA(4,0,0) process forecast. If trading signals (as discussed in its section) aregenerated based on our forecast and allowing for short-selling in the market and getting advantage of selling strategyprofits, ARIMA(4,0,0) will generate -%16.62 loss for this asset within the 115 minutes trading time.7 PREPRINT - J
ULY
23, 2020 . . . . ABT ptice forecast ARIMA model 120 min window ending to 2018 − −
16 19:01:00
Time Min. by Min. p r i c e Stock PriceARIMA Forecase
Figure 4: Abbott Laboratories price, Online-learning ARIMA forecast8
PREPRINT - J
ULY
23, 2020today forecast position tmw porfit_loss4 60.15000 60.15101 Long 60.18000 0.030005 60.18000 60.17922 60.19000 -0.000006 60.19000 60.19020 60.19000 0.000007 60.19000 60.18903 60.19990 -0.000008 60.19990 60.19939 60.18500 0.000009 60.18500 60.18556 60.15000 -0.0000010 60.15000 60.15084 60.17000 0.0000011 60.17000 60.17031 60.18500 0.0000012 60.18500 60.18608 Long 60.18640 0.0014013 60.18640 60.18580 60.17000 0.0000014 60.17000 60.17004 60.17000 0.0000015 60.17000 60.17017 60.17500 0.0000016 60.17500 60.17568 60.17000 -0.0000017 60.17000 60.17035 60.17000 0.0000018 60.17000 60.17002 60.21000 0.0000019 60.21000 60.20926 60.24000 -0.0000020 60.24000 60.23924 60.24500 -0.0000021 60.24500 60.24342 Short 60.25000 -0.0050022 60.25000 60.24882 Short 60.27000 -0.0200023 60.27000 60.26938 60.25500 0.0000024 60.25500 60.25535 60.26000 0.0000025 60.26000 60.25933 60.29000 -0.0000026 60.29000 60.28989 60.30000 -0.0000027 60.30000 60.29965 60.37500 -0.0000028 60.37500 60.37191 Short 60.40000 -0.0250029 60.40000 60.39882 Short 60.38000 0.0200030 60.38000 60.37778 Short 60.43000 -0.0500031 60.43000 60.42778 Short 60.42000 0.0100032 60.42000 60.42104 Long 60.40000 -0.0200033 60.40000 60.39890 Short 60.39000 0.0100034 60.39000 60.39084 60.39500 0.0000035 60.39500 60.39587 60.42500 0.0000036 60.42500 60.42476 60.40500 0.0000037 60.40500 60.40548 60.41500 0.0000038 60.41500 60.41382 Short 60.42500 -0.0100039 60.42500 60.42560 60.43000 0.0000040 60.43000 60.42968 60.42000 0.0000041 60.42000 60.42006 60.40000 -0.0000042 60.40000 60.40058 60.43000 0.0000043 60.43000 60.42980 60.35000 0.0000044 60.35000 60.35312 Long 60.37000 0.0200045 60.37000 60.36878 Short 60.37000 -0.000009
PREPRINT - J
ULY
23, 2020
In this section linear State Space Model is considered to estimate future trading signals. To do so, I used Kalmanfiltering ,see [14] , method to estimate tomorrow’s state of trade and then employed Expected Maximization Algorithmto estimate initial parameters for KF of each state. This will help to improve performance of KF in estimatingtrading signals. The State-Space model has two conditions: Hidden or latent process x t , state process, assumedto be a Markov process. The future { x s ; s > t } , and the past past { x s ; s < t } , are independent conditional on thepresent, x t . The observations, y t are independent given the states x t . This means that the dependence among theobservations is generated by states. Consider linear Gaussian state space model or (DLM), order one, p-dimensionalvector autoregression as the state equation x t = Φ x t − + w t , w t iid ∼ N p (0 , Q ) (9)Note that w t is a p × iid, zero-mean normal vectors with covariance matrix Q; the process starts with a normal vector x , such that x ∼ N ( µ , Σ ) . We do not observe the state vector x t directly, but only a linear transformed version ofit with noise added, hence observation model, follows : y t = A t x t + v t , v t iid ∼ N q (0 , R ) (10) A t is a q × p measurement or observation matrix. The observed data vector, y t , is q-dimensional, which can be largerthan or smaller than p, the state dimension.The additive observation noise is vector of Normally distributed data. Forsimplicity, x , { w t } and { v t } are assumed to be uncorrelated.Our goal is to produce estimators for the underlying unobserved signal x t , given the data y s = { y , ..., y s } , to time s.When s < t , the problem is called forecasting or prediction. When s = t , the problem is called filtering. Given asequence of observations y t the goal in stochastic filtering is to compute the posterior distribution of the internal states p ( x t | y t ) . If X, Y process is jointly Gaussian, then the distribution of any subset of X conditioned on any subset of Ywill also be Gaussian. It follows that the filtering distributions are fully specified by their means and variances. When s > t , the problem is called smoothing. Hence the goal is to compute p ( x t | y s ) where s > t . This is a non-causalprocess. So we use future observations to estimate the present state. Call: x st = E ( x t | y s ) P st ,t = E { ( x t − x st )( x t − x st ) (cid:48) | y s } .When t = t (= t ) then P st is used for convenience. P = Σ is initially known. Formula’s to estimate Kalman Filter([14] for the prove and more details): 10 PREPRINT - J
ULY
23, 2020 x t − t = Φ x t − t − (11) P t − t = Φ P t − t − Φ (cid:48) + Q (12) Σ t = A t P t − t A (cid:48) t + R (13) K t = P t − t .A (cid:48) t [ A t P t − t A (cid:48) t + R ] − (14) x tt = x t − t + K t ( y t − A t x t − t ) (15) P tt = [ I − K t A t ] P t − t (16) (cid:15) t = y t − E ( y t | y t − ) = y t − A t x t − t (17) [15] proposed an EM algorithm conjunction with the Kalman Filter algorithm and derive a recursive procedure forestimating the parameters by MLE. The basic idea, is that if we know the states and observations, so we have completedata. So the joint distribution will be : P Θ ( x, y ) = P ( x n (cid:89) t =1 P ( x t | x t − ) (cid:89) t P ( y t | x t ) (18)so the Log-likelihood will be : − lnL X,Y (Θ) = ln ( det (Σ )) + ( x − µ ) (cid:48) Σ − ( x − µ ) (19) + nln ( det ( Q )) + n (cid:88) t =1 ( x t − φx t − ) (cid:48) Q − ( x t − φx t − ) (20) + nln ( det ( R )) + n (cid:88) t =1 ( y t − A t x t ) (cid:48) R − ( y t − A t x t ) (21)Now, we need to construct the iteration steps. First we need expectation step: E j = ln ( det (Σ )) + tr (Σ − [ P n + ( x n − µ )( x n − µ ) (cid:48) )+ nln ( det ( Q )) + tr ( Q − [ F − F φ (cid:48) − φF (cid:48)
10 + φF φ (cid:48) )+ nln ( det ( R )) + tr ( R − n (cid:88) t =1 [( y t − A t x nt ) (cid:48) ( y t − A t x nt ) + A t P nt A (cid:48) t ]) where F = n (cid:88) t =1 ( x nt x n (cid:48) t + P nt ) (22) F = n (cid:88) t =1 ( x nt x n (cid:48) t − + P nt,t − ) (23) F = n (cid:88) t =1 ( x nt − x n (cid:48) t − + P nt − ) (24)For min minimization step, one can derive the following updated estimations:11 PREPRINT - J
ULY
23, 2020 Φ j = F F − (25) E j = F − F F − F (cid:48) n (26) R j = (cid:80) nt − =1 ( y t − A t x nt ) (cid:48) ( y t − A t x nt ) (cid:48) + A t P nt A (cid:48) t n (27) µ j = x n (28) Σ jo = P n (29)Now, one can estimate above parameters by employing EM algorithm together with KF in each iteration. Thecorresponding code follows can be found in appendix. Now, by iterating above procedure, we get the estimations forour initial parameters.Using above formula’s, I estimated state-space model and plotted for ABT firm in following graph. (for detail of codesplease refer to Appendix). The green plot demonstrates the minute by minute stock prices and the red ones is predictionby the model. Kalman Filter can be considered as an online learning method. Employing this method on 265 minutes(test data), profits 0.89 per share. Trading strategy was taking long position in case of our prediction for tomorrow priceis higher than today’s price and taking short position if we predict price will fall tomorrow. The next day, the currentposition will be closed, no matter what happens. (Here tomorrow means next minute as I have used minutes by minutesdata). 12 PREPRINT - J
ULY
23, 2020
Kalman Filter Prediction of Stock price: ABT Firm time p r i c e Stock PriceKalman Filter Prediction
Figure 5: Abbott Laboratories Stock prices prediction with Kalman filter13
PREPRINT - J
ULY
23, 2020 . . . . . . . Kalman Filter Prediction of Stock price: ABT Firm time p r i c e stock priceKF PredictionsFiltering Figure 6: Abbott Laboratories Stock prices prediction with Kalman filter- for 264 minutes14
PREPRINT - J
ULY
23, 2020today forecast position tmw porfit_loss1 59.11000 59.11086 59.11000 0.000002 59.11000 59.11033 59.11000 0.000003 59.11000 59.11012 59.14000 0.000004 59.14000 59.11005 Short 59.15000 -0.010005 59.15000 59.12856 Short 59.12000 0.030006 59.12000 59.14181 Long 59.11000 -0.010007 59.11000 59.12833 Long 59.09000 -0.020008 59.09000 59.11700 Long 59.11260 0.022609 59.11260 59.10031 Short 59.06000 0.0526010 59.06000 59.10791 Long 59.02000 -0.0400011 59.02000 59.07830 Long 59.04500 0.0250012 59.04500 59.04227 Short 59.04000 0.0050013 59.04000 59.04396 Long 59.05000 0.0100014 59.05000 59.04151 Short 59.06500 -0.0150015 59.06500 59.04676 Short 59.07800 -0.0130016 59.07800 59.05803 Short 59.09000 -0.0120017 59.09000 59.07037 Short 59.13000 -0.0400018 59.13000 59.08250 Short 59.11500 0.0150019 59.11500 59.11186 Short 59.16000 -0.0450020 59.16000 59.11380 Short 59.15000 0.0100021 59.15000 59.14235 Short 59.15500 -0.0050022 59.15500 59.14708 Short 59.16500 -0.0100023 59.16500 59.15197 Short 59.18000 -0.0150024 59.18000 59.16002 Short 59.20000 -0.0200025 59.20000 59.17237 Short 59.20440 -0.0044026 59.20440 59.18945 Short 59.22500 -0.0206027 59.22500 59.19869 Short 59.24500 -0.0200028 59.24500 59.21495 Short 59.25000 -0.0050029 59.25000 59.23352 Short 59.25000 -0.0000030 59.25000 59.24371 Short 59.26000 -0.0100031 59.26000 59.24760 Short 59.27000 -0.0100032 59.27000 59.25526 Short 59.25000 0.0200033 59.25000 59.26437 Long 59.23680 -0.0132034 59.23680 59.25549 Long 59.24000 0.0032035 59.24000 59.24394 Long 59.22000 -0.0200036 59.22000 59.24150 Long 59.23500 0.0150037 59.23500 59.22821 Short 59.24200 -0.0070038 59.24200 59.23241 Short 59.24000 0.0020039 59.24000 59.23834 Short 59.25000 -0.0100040 59.25000 59.23936 Short 59.25500 -0.0050041 59.25500 59.24594 Short 59.23000 0.0250042 59.23000 59.25154 Long 59.25500 0.0250043 59.25500 59.23823 Short 59.25500 -0.0000044 59.25500 59.24859 Short 59.27000 -0.0150045 59.27000 59.25255 Short 59.28000 -0.0100046 59.28000 59.26334 Short 59.30000 -0.0200047 59.30000 59.27363 Short 59.26500 0.0350048 59.26500 59.28993 Long 59.27000 0.0050015
PREPRINT - J
ULY
23, 2020 [16] and [10] compared different ML algorithms which are applied to predict stock price movements. They comparedensemble of random forests, with Neural Network, Support Vector Regression, and OLS, and found the superior resultsof the former over other methods. In this paper, I will compare performance of these methods: Ensemble of RandomForest, in contrast to Times series data. Although [17] survey, is hopeless on employing NN methods on stock marketprediction, due to its non-stationarity movements, but there might be a better chance of trying NN with predictingtrading signals (which, as discussed,is bounded time series) as an extension of this research. [8] and [16] report that among several Machine learning algorithms, ensemble Random Forests perform better to predictdirection of stock prices. Random forests (RF) algorithm introduced by [18] as an average of some random regressiontrees to avoid over-fitting of each tree. Although some scholars implemented RF successfully to predict financialmarkets ([9]), but problem arises when data is time dependent, or sequential data. The novelty of this research onpredicting trading signal might have some positive impact to solve this problem. Also, I will work onFigure 7: Ensemble of Random Forestsnew weighting algorithm to combine several RF. This is normally called Ensemble of RF in literature. [19] proposedonline Random Forest algorithm which is based on the online bagging, randomized forests and online regression tree.Moreover, they implemented a weighting algorithm to punish some regression trees based on their out-of-bag-errorto grow new regression trees. This idea looks similar to Adaboost learning algorithm of [20], which repeatedly uses16
PREPRINT - J
ULY
23, 2020a simple learning algorithm, called weak learner to different weightings of training data. While Adaboost performsrelatively good for predicting direction of financial markets, one might be interested to see its performance on magnitudeof future prices. Some scholars combined the Adaboost algorithm with RF algorithm in this manner. First they trainedseveral RF on time intervals of time series data, then considered each RF an weak expert to predict tomorrow prices.Then they punished weak RF experts based on the outcomes of each expert to predict prices (see [8]. In this study, Iused this idea, but with some modifications on weighting algorithm of each weak RF. Each RF will be applied to someinterval of data. Then, I will weight each RF based on inverse of their absolute prediction error. Then will update theweights of each RF, to predict tomorrow’s (next minutes here) trading signals based on ensemble of weighted RandomForests. After that, I will try to benefit from new Minutes by Minutes data and update each prediction by correctingprevious predictions measures. So for each next Min. we will best use of today’s information. In the following plot, Iillustrated the the results of RF on test data set of Minutes by Minutes prices for ABT company. Next, I have consideredour predictions as trading signals and check the profitability of proposed algorithm. For now, the algorithm has 7.5 %success in direction estimation. . . . . . . ABT Stock Price Prediction Using Ranfom Forest 120 min window ending to 2018 − −
16 19:01:00
Index S t o ck P r i c e Stock PriceRandom Forest Prediction
Figure 8: Abbott Laboratories Stock prices prediction with Random Forest17
PREPRINT - J
ULY
23, 2020row today.price forecast.tmw signal tmw profit.loss1 1 60.0900 60.1054 Long 60.1200 0.03002 2 60.1200 60.1196 60.1350 0.00003 3 60.1350 60.1371 60.1554 0.00004 4 60.1554 60.1604 60.1700 0.00005 5 60.1700 60.1581 Short 60.1550 0.01506 6 60.1550 60.1379 Short 60.1600 -0.00507 7 60.1600 60.1461 Short 60.1500 0.01008 8 60.1500 60.1376 Short 60.1800 -0.03009 9 60.1800 60.1638 Short 60.1900 -0.010010 10 60.1900 60.1605 Short 60.1900 0.000011 11 60.1900 60.1690 Short 60.1999 -0.009912 12 60.1999 60.1693 Short 60.1850 0.014913 13 60.1850 60.1603 Short 60.1500 0.035014 14 60.1500 60.1422 60.1700 0.000015 15 60.1700 60.1576 Short 60.1850 -0.015016 16 60.1850 60.1686 Short 60.1864 -0.001417 17 60.1864 60.1678 Short 60.1700 0.016418 18 60.1700 60.1553 60.1700 0.000019 19 60.1700 60.1496 Short 60.1750 -0.005020 20 60.1750 60.1576 Short 60.1700 0.005021 21 60.1700 60.1633 60.1700 0.000022 22 60.1700 60.1666 60.2100 0.000023 23 60.2100 60.1836 Short 60.2400 -0.030024 24 60.2400 60.2069 Short 60.2450 -0.005025 25 60.2450 60.2074 Short 60.2500 -0.005026 26 60.2500 60.2189 Short 60.2700 -0.020027 27 60.2700 60.2838 Long 60.2550 -0.015028 28 60.2550 60.2648 60.2600 0.000029 29 60.2600 60.2836 Long 60.2900 0.030030 30 60.2900 60.3051 Long 60.3000 0.010031 31 60.3000 60.3109 Long 60.3750 0.075018
PREPRINT - J
ULY
23, 2020 [21] proposed Long Short-term Memory (LSTM) Networks, which are a type of recurrent neural networks and appliedsuccessfully to predict stock markets data. It will be worth to see the performance of LSTM method to predict thetrading signals of stock prices, in future research.
The goal of this report is to compare the time series methods versus some machine learning based algorithms for stockprice movements and generating trading signals. The use of on-line learning algorithms is forced by nature of stockmarkets price behavior, as they are prone to exogenous shocks. To avoid effect of these shocks (some news shocks andsome macro-foundations shocks) using on-line learning algorithms will be helpful. The study shows, random forestalgorithm performs considerably better than Arima (which is simply regressing today’s prices on history of prices).But employing Kalman filter together with Expectation Maximization algorithm, results way better than Ensemble ofRandom Forest Algorithm. One might need to check if Kalman Filter performs better than other Machine Learningalgorithms such as Long-Short Term Memory in future research.19
PREPRINT - J
ULY
23, 2020
References [1] John J Murphy.
Technical analysis of the financial markets: A comprehensive guide to trading methods andapplications . Penguin, 1999.[2] Lamartine Almeida Teixeira and Adriano Lorena Inacio De Oliveira. A method for automatic stock tradingcombining technical analysis and nearest neighbor classification.
Expert systems with applications , 37(10):6885–6890, 2010.[3] Michael D Godfrey, Clive WJ Granger, and Oskar Morgenstern. The random-walk hypothesis of stock marketbehavior.
Kyklos , 17(1):1–30, 1964.[4] Eugene F Fama. The behavior of stock-market prices.
The journal of Business , 38(1):34–105, 1965.[5] Werner FM Bondt and Richard Thaler. Does the stock market overreact?
The Journal of finance , 40(3):793–805,1985.[6] Michael C Jensen. Some anomalous evidence regarding market efficiency.
Journal of financial economics ,6(2-3):95–101, 1978.[7] Yu-Hon Lui and David Mole. The use of fundamental and technical analyses by foreign exchange dealers: Hongkong evidence.
Journal of International Money and Finance , 17(3):535–545, 1998.[8] Germán Creamer and Yoav Freund. Automated trading with boosting and expert weighting.
Quantitative Finance ,10(4):401–420, 2010.[9] Yakup Kara, Melek Acar Boyacioglu, and Ömer Kaan Baykan. Predicting direction of stock price index movementusing artificial neural networks and support vector machines: The sample of the istanbul stock exchange.
Expertsystems with Applications , 38(5):5311–5319, 2011.[10] Ash Booth, Enrico Gerding, and Frank McGroarty. Performance-weighted ensembles of random forests forpredicting price impact.
Quantitative Finance , 15(11):1823–1835, 2015.[11] David A Dickey and Wayne A Fuller. Distribution of the estimators for autoregressive time series with a unit root.
Journal of the American statistical association , 74(366a):427–431, 1979.[12] Edward Gately.
Neural networks for financial forecasting . John Wiley & Sons, Inc., 1995.[13] Rodolfo C Cavalcante, Rodrigo C Brasileiro, Victor LF Souza, Jarley P Nobrega, and Adriano LI Oliveira.Computational intelligence and financial markets: A survey and future directions.
Expert Systems with Applications ,55:194–211, 2016.[14] Rudolph Emil Kalman. A new approach to linear filtering and prediction problems.
Journal of basic Engineering ,82(1):35–45, 1960.[15] Robert H Shumway and David S Stoffer. An approach to time series smoothing and forecasting using the emalgorithm.
Journal of time series analysis , 3(4):253–264, 1982.[16] Jigar Patel, Sahil Shah, Priyank Thakkar, and K Kotecha. Predicting stock and stock price index movementusing trend deterministic data preparation and machine learning techniques.
Expert Systems with Applications ,42(1):259–268, 2015.[17] Martin Längkvist, Lars Karlsson, and Amy Loutfi. A review of unsupervised feature learning and deep learningfor time-series modeling.
Pattern Recognition Letters , 42:11–24, 2014.[18] Leo Breiman. Random forests.
Machine learning , 45(1):5–32, 2001.[19] Amir Saffari, Christian Leistner, Jakob Santner, Martin Godec, and Horst Bischof. On-line random forests. In
Computer Vision Workshops (ICCV Workshops), 2009 IEEE 12th International Conference on , pages 1393–1400.IEEE, 2009.[20] Yoav Freund and Robert E Schapire. A desicion-theoretic generalization of on-line learning and an application toboosting. In
European conference on computational learning theory , pages 23–37. Springer, 1995.[21] Sepp Hochreiter and Jürgen Schmidhuber. Long short-term memory.