Stock Price Prediction using Dynamic Neural Networks
This paper will analyze and implement a time series dynamic neural network to
predict daily closing stock prices. Neural networks possess unsurpassed
abilities in identifying underlying patterns in chaotic, non-linear, and
seemingly random data, thus providing a mechanism to predict stock price
movements much more precisely than many current techniques. Contemporary
methods for stock analysis, including fundamental, technical, and regression
techniques, are conversed and paralleled with the performance of neural
networks. Also, the Efficient Market Hypothesis (EMH) is presented and
contrasted with Chaos theory using neural networks. This paper will refute the
EMH and support Chaos theory. Finally, recommendations for using neural
networks in stock price prediction will be presented.
David Noel
# Stock Price Prediction using Dynamic Neural Networks

###### Abstract

This paper will analyze and implement a time series dynamic neural network to predict daily closing stock prices. Neural networks possess unsupressed abilities in identifying underlying patterns in chaotic, non-linear, and seemingly random data, thus providing a mechanism to predict stock price movements much more precisely than many current techniques. Contemporary methods for stock analysis, including fundamental, technical, and regression techniques, are conversed and paralleled with the performance of neural networks. Also, the Efficient Market Hypothesis (EMH) is presented and contrasted with Chaos theory using neural networks. This paper will refute the EMH and support Chaos theory. Finally, recommendations for using neural networks in stock price prediction will be presented.

**Keywords:** market, neural network, prediction, regression, stock

## 1 Introduction

This paper uses a Dynamic Neural Network to predict a given stock's future daily closing price. These are models used for predictions and non-linear filtering by analyzing data for patterns and "learning" from said patterns. Two prevailing theories seek to qualify market behavior; EMH and Chaos.

The **EMH theory** states that no system can reliably 'beat' the market because a stock's price has already incorporated and reflects all factors into its valuation, thus being _random_ and _unpredictable_. In contrast, the contrary **Chaos theory** states that stock prices are made up of _deterministic_ plus _random_ patterns. [1]

Chaos represents deterministic but non-linear processes that appear random because they cannot be easily quantified. Through the neural networks' inherent ability to learn non-linear, dynamic, & chaotic systems, it is possible to outperform traditional stock price analysis; much to the liking of investors who can exploit this ability for huge profits.

Neural networks enable multivariate models, allowing parallel processing of input data, thus quickly processing large amounts of data. Their primary strength is that they can determine patterns and anomalies within data, but most importantly, their ability to detect multidimensional & non-linear connections within that data; this makes neural networks extremely suitable for the dynamic and non-linear data generated by the stock market [2].

## 2 Related Works

Several fundamental and technical indicators have been adopted for stock price predictions but with inconsistent results [2]. No single method or combination has succeeded enough to outperform the market reliably.

These time series predictions were linear parametric autoregressive, auto-regressive moving averages or moving averages in nature based on principles by Box and Jenkins. Due to their linear nature, these models failed to capture non-stationary/dynamic signals properly.

The use of technical indicators stems from the idea that stock prices move in trends governed by investors' emotions, views, and attitudes due to company news or macroeconomic data. Using data such as volume, momentum, opening/closing prices, and oversold/overbought conditions, technicians use many charts to predict a stock's future value or index under the _belief_ that history repeats itself. This methodology contradicts the EMH hypothesis but is used by over 80% of stock traders [5]. The major downside of technical analysis is that it is _highly subjective_ since each trader can interpret the charts differently, making this method inconsistent, biased, and maybe most appropriate for _very short-term_ predictions.

Fundamental analysis involves a more in-depth study of the company. Fundamental analysts study the company's financial performance, price/earnings, consumer demand, overall market conditions, and competitors to determine the _intrinsic value_ of a stock. This value indicates what a particular stock is "truly" worth, and they believe that the market will eventually realize this intrinsic value and reward the stock by maintaining or exceeding the said price. This method, however, involves processing huge amounts of data and is subject to individual interpretation. Thus, even if the data suggests a favorable movement in the stock, it may take a long time for the rest of the market to realize or catch up. This method, thus, is suitable for _long-term predictions_ and growth.

The algorithms, neural network architectures, and associated functions will be implemented using MATLAB(r) and its powerful Neural Network Toolbox.

## 3 Algorithm

The **L**evenberg-Marquardt (LM)** algorithm will be used for training purposes. This algorithm quickly updates weight and bias values using back-propagation techniques, and it seems to be the quickest method for training reasonable-sized feedforward neural networks (up to weights reaching several hundred). [3]

The design of the algorithm was such that it approaches 2nd order training speed without computing the Hessian matrix (unlike the Gauss-Newton method).

In the LM algorithm, a function \(f(x)\) is minimized to a sum of squares, i.e.

\[\min_{x}f(x)=\|F(x)\|_{2}^{2}=\sum_{i}F_{i}^{2}(x) \tag{1}\]
Assuming output,\(\boldsymbol{y}(\boldsymbol{x},\boldsymbol{t})\), for some continuous model trajectory, \(\varphi(\boldsymbol{t})\), at vector \(\boldsymbol{x}\) and scalar \(\boldsymbol{t}\), we have:

\[\min_{\boldsymbol{x}\in\mathbb{N}^{\boldsymbol{x}}}\left\{\begin{aligned} \boldsymbol{y}(\boldsymbol{x}, \boldsymbol{t})-\varphi(\boldsymbol{t})\end{aligned}\right\}^{T_{ \boldsymbol{t}}}_{t_{1}}\big{(}\boldsymbol{y}(\boldsymbol{x},\boldsymbol{t}) -\varphi(\boldsymbol{t})\big{)}^{2}\boldsymbol{dt}, \tag{2}\]

where \(\boldsymbol{y}(\boldsymbol{x},\boldsymbol{t})\)and \(\varphi(\boldsymbol{t})\) are scalar functions. Discretizing (2) using the appropriate quadrature formula, we get a least squares problem:

\[\min_{\boldsymbol{x}\in\mathbb{N}^{\boldsymbol{x}}}\boldsymbol{f}(\boldsymbol {x})=\sum_{i=1}^{m}\big{(}\vec{\boldsymbol{y}}(\boldsymbol{x},\boldsymbol{t} _{i})-\vec{\varphi}(\boldsymbol{t}_{i})\big{)}^{2}, \tag{3}\]

where \(\vec{\boldsymbol{y}}\) and \(\overline{\boldsymbol{\varphi}}\) include the weights. Now from (1),

\[\boldsymbol{F}(\boldsymbol{x})=\begin{bmatrix}\vec{\boldsymbol{y}}( \boldsymbol{x},\boldsymbol{t}_{1})-\vec{\varphi}(\boldsymbol{t}_{1})\\ \vec{\boldsymbol{y}}(\boldsymbol{x},\boldsymbol{t}_{2})-\vec{\varphi}( \boldsymbol{t}_{2})\\...\\ \vec{\boldsymbol{y}}(\boldsymbol{x},\boldsymbol{t}_{m})-\vec{\varphi}( \boldsymbol{t}_{m})\end{bmatrix}. \tag{4}\]

_Denoting:_

Jacobian \(F(\boldsymbol{x})\) as \(J(\boldsymbol{x})\),

gradient vector of \(f(\boldsymbol{x})\) as \(G(\boldsymbol{x})\),

Hessian matrix of \(f(\boldsymbol{x})\) as \(H(\boldsymbol{x})\),

Hessian matrix of \(F_{i}(\boldsymbol{x})\) as \(H_{i}(\boldsymbol{x})\),

_we get,_

\[\begin{split} G(\boldsymbol{x})&=2J(\boldsymbol{x})^{T} \boldsymbol{F}(\boldsymbol{x})\\ H(\boldsymbol{x})&=2J(\boldsymbol{x})^{T}J( \boldsymbol{x})+2Q(\boldsymbol{x}),\end{split} \tag{5}\]

_where,_

\[Q(\boldsymbol{x})=\sum_{i=1}^{m}F_{i}(\boldsymbol{x})\cdot H_{i}(\boldsymbol {x}). \tag{6}\]

as \(x_{k}\) approaches the solution, \(F(\boldsymbol{x})\to 0\) & \(Q(\boldsymbol{x})\to 0\).

Now as \(Q(\boldsymbol{x})\to\infty\), the Gauss-Newton method experiences problems resolved by the LM method. In such cases, the LM method uses a search direction, \(\boldsymbol{d}_{\boldsymbol{k}}\), that is a solution to the set of linear equations:

\[\Big{(}J\left(x_{k}\right)^{T}J\left(x_{k}\right)+\lambda_{k}\boldsymbol{I} \Big{)}d_{k}=-J\left(x_{k}\right)^{T}\boldsymbol{F}\left(x_{k}\right), \tag{7}\]

where, \(\boldsymbol{\lambda}_{k}\) dictates the magnitude and direction of \(\boldsymbol{d}_{\boldsymbol{k}}\)

The LM method thus uses a search direction that is a hybrid between the Gauss-Newton and the steepest descent direction.

The neural models used for training in this paper would adopt a series-parallel (open-loop) network since training adopts "true" output values. For this model, the prediction equations used to determine the output \(\boldsymbol{y}(k+1)\) uses past inputs of \(\boldsymbol{u}_{1}(k),\boldsymbol{u}_{1}(k-1),...,\boldsymbol{u}_{1}(k- \boldsymbol{d}_{u})\) for the \(1^{\text{st}}\) time sequence and \(u_{2}(k),u_{2}(k-1),...,u_{2}(k-\boldsymbol{d}_{u})\) for the second time sequence and past outputs(targets) of \(\boldsymbol{y}(k),\boldsymbol{y}(k-\boldsymbol{1}),...,\boldsymbol{y}(k- \boldsymbol{d}_{\boldsymbol{y}})\), all as input data. This can be written in the form:

\[\begin{split} y(k+1)&=\Phi_{o}\Bigg{\{}w_{ \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{ i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i} \boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\boldsymbol{i}\
non-linear time series data, such as stock data. Using NARX, the idea is to predict future values of a time series \(\gamma(t)\) from past values of said time series coupled with past values of a second time series \(x(t)\), which can be written as follows,

\[y(t)=f(y(t-1),...,y(t-d),x(t-1),...,(t-d))\]

The NARX network is a two-layer feedforward network consisting of a sigmoid transfer function in the hidden layer and a linear transfer function in the output layer. The network also makes use of tapped delay lines to store previous values of the \(x(t)\) and \(y(t)\) sequences. It is important to note here that the output, \(y(t)\), is then fed back as input to the network, which is needed in the dynamic nature of stock price prediction.

The architecture's open-loop (series-parallel) implementation, as shown in Figure 2(a), will be used to train the network since the 'true' output, instead of the estimated output, is used as input feedback. This has several advantages, the first of which is that the input to the feedforward network is more accurate, and second, the resulting network has a pure feedforward architecture, and thus a more efficient algorithm( static back-propagation )can be used for training.

Once the network is reasonably trained, it will be converted to a closed-loop network to perform multi-step-ahead predictions. While open, the network was predicting the next value of \(y(t)\) from the previous values of \(y(t)\) and \(x(t)\). When the network is closed, it can perform multi-step-ahead predictions. This happens because _predictions of \(y(t)\)_ will be used in place of _actual future values of \(y(t)\)_. i.e., a closed-loop network outputs \(y(t+1)\) instead of \(y(t)\), as shown in Figure 2(b) below.

### Data Acquisition

Four years (01/01/2010 - 03/31/2014) of prior stock data would be retrieved from _finance.yahoo.com_ using a custom-written function based on MATLAB data-feed plugin. This function automatically segments the data into _input_, _target_, _and sample_ sequences. The data would be in the format _[date, opening price, high price, low price, volume, closing price, adjusted close price]_ and prepared for input to the network using MATLAB preparets function. This function automatically shifts time series data (input and target) by as many steps as needed to fill the initial delay states, thereby greatly reducing errors and complexity. Table I shows the sample dataset used.

### Training, Testing, and Validation

As shown in Figure 1, the open-loop network will train the network using tapped delay lines with 2 delays for both the input and output. This will allow training to begin with the 3rd data point. The open-loop network takes 2 input sequences, \(x(t),y(t)\), where \(\chi(t)\) is the input signal and is composed of the: {_open price, high price, low price, volume}_ data for the stock being analyzed.

It is important to note that for this network,\(y(t)\), which is the _closing price_ of the stock, is a feedback signal and is also an input and an output (target). Furthermore, 70% of the input dataset is used for training, 15% for validation, and 15% for testing. The network was retrained 10 times to ensure maximum accuracy, using the MSEREG performance function to improve generalizations. See Figures 3 and 4 below for further performance and training parameters used.
To determine the best possible parameters for achieving a robustly trained network, the number of input and output delays and the number of neurons were changed systematically, and each combination's RSE and performance ratio were recorded. Table II shows the recorded data after several trials, and the best number of delays and neurons were selected based on depicted performance criteria.

One neuron was used in the feedback layer for all trials because our target is only 1 value. From the data in Table II, it could be seen that when the input delays were between 0 and 25 and the number of neurons was less than 21, the performance and RSE values indicated a very good fit between the actual and predicted data (the _pink portion of the chart_). However, it was observed that in those cases, the Input-Error correlation curves were significantly out of the confidence levels, as can be seen in Figure 5.

After further testing (_green portion of Table II_), it was observed that the performance and accuracy increased with delays above 25 and 10 neurons or less. However, this large number of delays gave a performance hit to the network and was not chosen as appropriate input. Throughout the trials, it was observed that input delays between 0 and 1 yielded the BEST results across all performance metrics when the number of neurons was between 22 and 30 inclusive. The best performance was seen using a minimum of 22 neurons and [0:1] input delays, as depicted in Figure 6 below.

As such, the network used for final training will use the parameter values depicted in Figures 3 and 4 above, with the Levenberg-Marquardt (LM) algorithm, 2 hidden layers, and 22 neurons.

### Model Acceptance Criteria

A Mean Squared Error (MSE) of Zero means no errors, and a Regression (R) value of 1 means a 'perfect' relationship between the input and output data. It measures how well the targets describe the variation in the output. The acceptance criteria would be MSE values close to Zero and R-Values close to 1. Results are further verified using correlation, performance, and time-series charts. Divergences greater than 10% of the nominal values would prompt retraining in which the number of neurons or delays would be changed. [7]

\begin{table}
\begin{tabular}{|l|l|l|l|l|} \hline
**Input** & **Feedback** & **Neurons** & & \\
**delays(d\({}_{a}\))** & **delays(d\({}_{b}\))** & **(N)** & **Performance** & **RSE** \\ \hline
2.5 & 1 & 3 & 0.016 & 0.99852 \\ \hline
0:1 & 1 & 5 & 0.0154 & 0.99846 \\ \hline
0:1 & 1 & 10 & 0.0156 & 0.99844 \\ \hline
2:5 & 1 & 10 & 0.024 & 0.99844 \\ \hline
6:25 & 1 & 10 & 0.0354 & 0.99849 \\ \hline
0:5 & 1 & 14 & 0.0209 & 0.99847 \\ \hline
0:5 & 1 & 16 & 0.0168 & 0.99862 \\ \hline
0:1 & 1 & 21 & 0.0217 & 0.9954 \\ \hline
26:30 & 1 & 10 & 0.0955 & 0.9977 \\ \hline
0:5 & 1 & 16 & 0.0254 & 0.9983 \\ \hline
0:5 & 1 & 18 & 0.038 & 0.99846 \\ \hline
0:1 & 1 & 22 & 0.0178 & 0.99857 \\ \hline
0:1 & 1 & 23 & 0.0182 & 0.99866 \\ \hline
0:1 & 1 & 25 & 0.01599 & 0.99876 \\ \hline
0:1 & 1 & 30 & 0.0466 & 0.99766 \\ \hline \end{tabular}
\end{table}
Table II: Performance Based on Input Delays, Target Delays, and Neurons

Figure 4: Training parameters used.

Figure 5: Input-Error correlation out of confidence limit with input delays 2:25 and \(\leq\) 21 neurons.

Figure 6: Best performance seen at d\({}_{a}\)=0:1, d\({}_{y}\)=1, N=22
Results

The model was first trained on 4 years of stock data (01/01/2010 - 1/01/2014) using the series-parallel model shown in Figure 1, after which 100 days of simulation was conducted to predict the closing prices, using the parallel(closed) network as seen in Figure 2(b).

### Training

#### 5.1.1 Performance Results - Trained Network

Table III shows the performance of the _open_ network. It meets our acceptance criteria with an RSE of 0.998 and an MSE of 0.0242. Its performance of 0.0147 indicates it has very high efficiency and is much better than any linear-modeled dynamic system for predicting stock prices [5].

Figure 7 depicts the relative performances obtained for training the network. The training targets and outputs, validation and outputs, and testing targets and outputs are extremely close, with less than 2% divergence from the targets. This close correlation is further verified by the Error vs. Time graph shown. This is important because we want the error in the trained network (one-step-ahead) to be very small so that the predictions (multi-step-ahead) made in the parallel network are as accurate as possible.

Figure 8 shows the errors between the "actual" outputs vs. the "predicted" outputs while training.

This graph clearly shows that the divergences/errors between actual and predicted outputs are small and contained around zero. The maximum divergence from the actual values was approx. 1.122%, which is acceptable for our model. The 5 very large spikes are most likely caused by extremely random events, such as the company unexpectedly reporting a dividend increase or share buy-back, in which the stock rallied.

The R-values between the outputs and targets measure how well the targets explain the variation in the output. A number equal to 1 signifies a perfect correlation between targets and outputs. In our model, the value is approx. 0.998, which signifies a very accurate correlation.

Figure 9 above shows the input-error cross-correlation function, which depicts how the errors are correlated with the input sequence\(x(t)\). In a perfect model, all the correlations should be zero, and if they are not, it signifies room for

Figure 8: Errors between actual and predicted values during training.

Figure 7: Correlations between training, validation, test, and error.

Figure 9: Regression curves between output and target values.
improvement by adjusting the number of neurons in the hidden layer or the number of delays until the bars fall within the confidence bounds around zero. In our model, the bars all fall within the confidence limits of [-0.018, 0.018]. This further signifies that our model has a very efficient design, thus, will produce great accuracy.

Figure 10 shows the error autocorrelation function, which validates the network performance by showing how the prediction errors are related to time. For a perfect model, there should only be one nonzero value occurring at Lag 0 (the _MSE_ of the network), which would signify that prediction errors are only white noise. For our model, all the bars except the one at Lag 0 fall within the 95% confidence limit of around 0, which validates this model as very accurate. The 5% loss in performance accuracy is mainly white noise, which is inherent in the dynamic nature of the stock market.

Figure 11 shows plots of performance, validation, and testing during training. The network errors decreased until iteration 5 (out of 11 iterations), where their gradients were no longer changing. Before iteration 5, the gradients of the curves were not increasing. Therefore, it can be concluded that overfitting did not occur, and this network will produce very accurate results.

Figure 12 shows the output values obtained during training vs. the target values. From this chart and the previous performance graphs, the network _VERY_ accurately models the _closing price_ of the stock index, given the four inputs of _opening, high, low_ price, and trading _volume_, for the training period of 4 years. _Red signifies the predicted values,_ while _blue represents the target values_. The slight deviations are mainly due to the white noise inherent in such data and could be minimized using an appropriate filter.

### Simulation and Prediction

Now that training is completed using the series-parallel(open) network with acceptable accuracy, the network will now be converted to a purely parallel(closed) one, as shown in Figure 2(b), and the target prices will be predicted for 100 days, using data from _1/1/2014 - 3/31/2014_.

Table IV shows the performance of the _closed_ network. It also meets our acceptance criteria with an RSE of 0.998 and MSE of 0.0242. Its performance of 0.0142 also closely matches the expected open network performance.

Figure 11: Performance plot of training, validation, and testing.

Figure 12: Output vs. target during training.

Figure 10: Error autocorrelation to validated network

Figure 13: Simulated output showing targets and predictions.
Figure 13 shows 3 charts combined. The _blue represents the Original (actual) targets_, the _red shows the expected outputs_ after simulation, and the _green shows the network's predictions_. The chart shows that the network predictions and the expected outputs are very close. The network predictions parallel the expected outputs with only a 1.17% maximum divergence.

This accuracy was expected because the trained network showed superior performance characteristics, the same characteristics used in the simulated network. I.e., the simulated network also has an MSE of 0.0242 and an R-Value of 0.998.

Figure 14 is an enlarged version of the circular region identified in Figure 13. It shows the _network predictions in green_ and the _target (actual) values in red_. Given the dynamic and random nature of stock prices, this prediction is a very good fit for the actual values, further validating the efficiency of the network model used and the potential of neural networks in general.

Figure 15 shows the errors between the _simulated outputs_ and the _target values_ for the 100 simulation days using the closed network. It represents the differences between the charts shown in Figure 14. The errors are very small and fluctuate around the zero line. The maximum error difference recorded was 1.17%, indicating that the predicted (simulated) and target (actual) values are sufficiently close to each other to be deemed negligible. Again, most of the error is due to white noise, which can be reduced by first filtering the data. This filtering could be implemented using an extended Kalman filter which would seek to predict random changes in the stock price movement due to company and other macro-economic activities.

## 6 Conclusion

From the above data and analysis, it is evident that well-trained neural networks can quickly learn patterns within very large, seemingly unrelated datasets and make intelligent and mostly accurate predictions. It is also clear that neural networks eliminate or minimize randomness even when human counterparts fail. This is most likely because neural networks can quickly recognize and learn extremely subtle patterns in large datasets, which may go unrecognized by humans. This ability to 'learn or model' randomness directly supports the Chaos theory and refutes the EMH theory, and thus can be used to 'beat' the market

## 7 Recommendations

The errors that appeared as white noise could be reduced in several ways. First, the input data could be pre-processed using the techniques of Independent Component Analysis or even another training algorithm, then fed as input to the neural network. Secondly, the input data could be filtered using an extended Kalman filter which also makes intelligent predictions, then fed as input to the network.
