Qnet 2000 |
Stock Trading Model |
|||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
This example investigates the viability of using neural networks for developing financial market forecasting tools. Academic arguments have often been waged as to whether the stock market exhibits a random walk with virtually unpredictable trends or whether prices and trends can be forecast at better than random probabilities. This example creates a simple forecasting model to help investigate this question. We will use historical market prices that represent past trends in an attempt to predict future behavior. If the price is a true random walk we can expect to see results similar to the Random Mapping example. In that case, the neural model was able to memorize the training set, but it could not respond accurately to cases that were not part of the training set. If certain historical trends can be used to predict future prices, the neural model should be able to (at least partially) improve its response to test set cases, unlike the random problem.
In addition, we will use this example to show Qnet's ability to apply case weighting factors. To do this we will train two forecasting models: the first has all cases weighted equal and the second will apply a higher weight to cases representing the biggest market moves (possibly improving the response to large moves).
Our sample forecasting model will use the Dow Jones Industrials Index from a period of 1993 through 1998. We will compute a series of simple technical indicators using the market's closing prices. Five input indicators will be computed for each case using historical Dow data. The target will be the market's percent change 5 days from the current close. The desire is to develop a short term trading model that will improve the odds of predicting the proper market direction. The training data has been formulated as follows:
Input nodes:
5 day moving average/current close
10 day moving average/current close
20 day moving average/current close
50 day moving average/current close
200 day moving average/current close
Output node:
Percent change in price 5 days from close
This is a very simple model with only 5 basic inputs. One benefit of using a simple model is that fewer inputs can help reduce memorization mapping (see the random problem). While more inputs can be successfully used in more advanced stock market models, it is best to insure that each input is providing new and relevant information. Just adding inputs that are different calculations with the same data may result in reducing a model's predictive effectiveness (i.e. reduced generalized learning).
The two models presented for training are DOW.net and DOWWeighted.net. For the weighted model, the case weighting factors are set to 1 for all cases where the percent market change (target) is less than or equal to 1 standard deviation. All cases greater than 1 standard deviation get factored by the size of the standard deviation. Thus if a market change was 2 standard deviations the case would be considered twice as important and get a weighting factor of 2.. The period covered by our training data encompasses mostly bull market activity with several short periods of sharp declines. We will compare the results of our models against the simple assumption that the market will always be higher in 5 days (since up is the predominant trend). Beating this always higher strategy on a percentage basis (especially in the test set), will indicate whether any confidence can be placed in these forecasting models The trained results are located in "DOWTrained.net" and "DOWWeightedTrained.net".
Training results from these models indicate that a small but statistically significant amount of generalized learning takes place. First, this is evidence that the market is not a random walk and that past prices can be used (in part) to predict future trends. As expected, the initial training iterations show the network starts with an "always higher" prediction of .36% for the 5 day target (similar to our best guess scenario of always up). As the network organizes, it improves from that nominal prediction strategy in both the training and test RMS errors. After several thousand iterations, both the weighted and unweighted models develop global minimums in the test errors indicating that generalized learning has ended and memorization is taking over. The trained networks available in DOWTrained.net and DOWWeightedTrained.net have been saved near their optimal test set minimum RMS error (via AutoSave)..
To analyze the output results we selected .7 as an upper threshold (about twice the .36 nominal up prediction). This means when the model prediction is higher than the threshold we would consider the model to be providing an up prediction. A correct result is counted if the market is higher in 5 days (by any magnitude). For down market predictions we used a .2 positive prediction and below as the threshold. This is because there were a statistically insignificant number of true negative predictions prior to overtraining. But, since the network predictions started at .36 for every case, any prediction of .2 or below had it's prediction lowered during training. The chart below shows the results:
| Up Market Predictions | Training Set Correct | Training Set Wrong | Training Set Percentage | Test Set Correct | Test Set Wrong | Test Set Percentage |
| Bull Market - Always Up | 537 | 341 | 62% | 174 | 126 | 58% |
| Dow Unweighted Model (0.7 used as upper threshold) | 11 | 3 | 79% | 28 | 8 | 78% |
| Dow Weighted Model (0.7 used as upper threshold) | 27 | 10 | 73% | 37 | 19 | 66% |
| Down Market Predictions | Training Set Correct | Training Set Wrong | Training Set Percentage | Test Set Correct | Test Set Wrong | Test Set Percentage |
| Always Up | 0 | 0 | NA | 0 | 0 | NA |
| Dow Unweighted (0.2 used as lower threshold) | 69 | 57 | 55% | 21 | 17 | 55% |
| Dow Weighted (0.2 used as lower threshold) | 47 | 45 | 51% | 11 | 9 | 55% |
The unweighted market model for this test clearly provides the best percentage of winners. The numbers are significant in both the training and test set results, especially for upside predictions. The weighted model has less success on a percentage basis, however, it has a significant increase in the number of predictions (cases that exceed the upper threshold). A good model has both good percentages and many active predictions. The downside picture, while not bad, is clearly less successful. One reasons for this could be that the number of training cases for down periods are less than the number of upside cases. Also, overtraining set in prior to getting a significant number of true negative predictions. This meant we ended up setting our downside threshold in positive territory (a definite contradiction). While the two models have mild success at downside predictions, more modeling work in this area would be appropriate. In conclusion, it is clear that relatively simple models can have good results in market forecasting. It should be noted, however, that profiting on market models requires the consideration of transaction costs such as commissions, bid/ask spreads, execution timing, etc.