Large companies (e.g. Google, Exxon Mobil, etc.) are not owned by a single person or a private group of individuals. Rather, these companies are split up into small pieces (shares) which are then sold to any individual who can afford them. The value of a single share depends on many factors, primarily its current and expected future profits. For example, a share in Apple (the largest company by total share value) is sold at approximately $140 [yahooapple]. As a company grows, its shares increase in value; Amazon shares sold for $18 each in 1997 [investopedia], but are now worth over $800 because of Amazon’s massive growth since [yahooamazon]. A company’s shares are refered to as its ”stock”. Stock investors try to buy shares in companies that will grow dramatically; an investor who bought shares of Amazon in 1997 would now be very rich.
In a neural network, neurons are grouped into layers, which are combined to form a network that simulates a brain. A single neuron takes in many inputs from the neurons of the previous layer, multiples each by a weight, sums the products, adds a constant bias, and finally runs that sum through an activation function, often the sigmoid or hyperbolic tangent function. If we represent the inputs as a vector, the weights as a vector , the bias as a scalar , the activation function as , and the final output as a scalar , then
A neuron accepts a vector of the previous layer’s values and outputs a scalar value, which is then sent to the next layer. By tuning the weights and biases, the neural network can learn how to interpret given data, a process called ”training.” A deep neural network has many layers, allowing it to find deeper patterns, leading to a dramatic rise in usage in the past few years, especially for tasks like image recognition and natural language processing [wired]. A shallow neural network is a neural network with only 1 or a handful of layers, making it simpler but less powerful.
This study explores the utility of a shallow neural network on stock trading, specifically on deciding whether to buy or sell shares of a given company when given only stock information on said company.
2 Methods & Procedure
2.1 Experimental Trial
The neural network was created in Python 2.7 using Numpy, but a similar design in another language or with other tools is expected to yield similar results.
From Yahoo Finance, the daily highs over the past year from for stocks in the Standards & Poors 500 (S&P 500) were downloaded. These highs were then grouped into chunks, each 10 days long.
The neural network takes a chunk as a 10-vector input. It has only 1 hidden layer, which has 20 neurons. It outputs a 2-vector of the form . and are both recommendations in the interval with 1 being a strong recommendation. recommends selling shares and recommends buying shares. The recommendation with the larger magnitude is used. For simplicity, the network’s output is used to generate a Boolean equal to the index of the larger component. If the two recommendations are equally strong, then buying more shares is suggested.
It is trivially shown that represents the recommendation to buy shares. If the network recommends buying, . If the network recommends selling (i.e. not buying), then .
To generate the training data, all but the most recent chunk were considered. To generate the training datum , let be the 10-vector chunk and be the correct value of for said chunk. To calculate , compare the highest high of the chunk with , that of the chunk. If the price rises (i.e. ), then shares shought be bought (i.e. ). If the price does not rise, then shares should be sold (i.e. ). To summarize,
It is trivially shown that
The training data
ignores the most recent chunk
so that it can be used to test the neural network. red The neural network then trains on the training data using standard backpropagation and gradient descent. To test it, the network makes its decisionon the second-most recent chunk . The decision’s accuracy (i.e. ) was then recorded.
Of the 500 stocks in the S&P 500 available, 385 stocks were given to the neural network, which trained and tested itself over each.
2.2 Control Trial
To know if the neural network is useful, a control that randomly recommends buying or selling was applied to the S&P 500 data. It generated a that was equally likely to be or . as in the experimental group. This decision’s accuracy (i.e. ) was then recorded.
The null hypothesis argues that the neural network knows nothing of the stocks on which it makes decisions and thus is no better than a random suggestion of either buying or selling.
Of the 500 stocks given to the control, 278 were decided correctly and 222 were decided incorrectly. Assume that the control’s results are not statistically significant. If so, then a chi-squared analysis should show that the control is not statistically significant. Applying the standard formula,
Because there are two possible classifications of a result, correct or incorrect, there are 2 degrees of freedom. Using a significance levelwith a single degree of freedom would require , which is not the case for the control group.
In the experimental trial, the neural network was given 385 stocks. If the null hypothesis is true, then 192.5 decisions would be correct and 192.5 would be incorrect. The neural network made an incorrect decision for 57 stocks and a correct decision for the remaining 328. Applying chi-squared,
190.755844 is significantly higher than the required 6.63, so the null hypothesis is rejected, showing that the neural network has learned from the stock data and can make an informed decision based on it.
4 Conclusions & Discussion
Neural networks have seen little success in stock-trading due to the lack of an obvious pattern in the stock market. This particular experiment was designed with simplicity in mind. The neural network has been shown to accurately predict whether the highest value of a stock for 10 consecutive days is higher than the highest value of said stock for the next 10 days. However, this is not very applicable to real-world stock trading because the network does not determine what the next high is, so the stock trader does not know when exactly to buy or sell shares in the stock, only that he or she should at some point.
Changes to the configurations of the neural network, such as its dimensions and learning rate, may improve the neural network’s accuracy. Improvements may also be found by an alternative design, such as a convolution neural network, or a significant alteration to the existing network, such as a deep neural network.
The authors thank hackNYU for providing food, drink, lodging, internet access, and countless other utilities during the development of the neural network. We also thank Yahoo for freely distributing stock data. We also thank Rufus Pollock for distributing a list of the tickers of the S&P 500 companies.