Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Basic Market Forecasting with Encog Neural Networks

Encog is an open source neural network framework released under the Lesser GNU Public License.


advertisement
In this article I will show how to apply a neural network to financial prediction. This program is implemented as a Microsoft WPF application using C#. For neural network processing, it makes use of the Encog Artificial Intelligence framework. This application attempts to use some of the same principles that technical market analysts use.

Technical analysts attempt to forecast future security direction through the analysis of past market data. Pure technical analysts are primarily interested in price and volume information, rather than any sort of fundamental information about the company, such as earnings, debt ratios, or product offerings. The theory is that all such fundamental data is already factored into the price and volume of the underlying security. Many investment disciplines advocate the use of both technical and fundamental components. However, the focus of this article is the use of pure technical data.

This article will use purely technical data. This is not necessarily the investing discipline that I advocate. Some of the research I have conducted uses fundamental data as well. However, to keep this article closer to the introductory level, only technical data will be used. This greatly simplifies the implementation of this application.



The program presented in this article is meant primarily as a starting point for further exploration. A neural network is a tool that recognizes pattern. This is in much the same way as one of the primary functions of our own human brains is to form memories and recognize patterns. The real trick in using neural networks for market prediction is representing the market data in a way that truly captures the essence of the underlying patterns in a way that the neural network will be able to recognize them. This program demonstrates a simple way to represent technical market data for recognition.

This program is by no means meant to be taken as an investment strategy. It is for educational purposes only, and you should not base an investment direction on it. However, this program is a very good starting point for further exploration in the application of neural networks to market forecasting. This is an area of ongoing research for me. I frequently use this program as a starting point. It has built in capabilities for Encog, charting, and accessing market data from Yahoo Finance. From here you can adjust how the market data is presented to the neural network, and how the results are interpreted. My personal goal in the area of market forecasting is to try a number of neural network architectures and perhaps ultimately produce a book on these findings.

The examples presented here will make use of the stock market. However, the same technical analysis principals are often applied to currency exchange markets (FOREX). This program could easily be adapted to work with currency pairings as well. This is an area I intend to research as well.

Candlestick Charts

We will begin by looking at one of the most common tools of the technical trader: the candlestick chart. Many neural network examples for market forecasting simply make use of the daily closing price of a security and attempt to predict patterns using this data alone. While this can give some insight, technical analysts typically use more data. The following five pieces of information, listed here, are of particular interest to the technical analyst.
    * Opening Price
    * Closing Price
    * Day High
    * Day Low
    * Volume
Using more than just the daily closing price allows the analyst to capture the "emotion" of the market. This is how the fundamental data is factored into the purely technical model. The first four data items are used to create something called a candlestick chart. The candlestick chart is a hybrid of the line and bar charts. An example of a candlestick chart is shown here.

The chart is made up of "candlesticks". Each candlestick shows one day's worth of activity. It is important to understand how to read each individual candlestick. This is illustrated below.

Candles are made up of bodies, with shadows (or wicks) at each end. Candles are either white or black. A white candle indicates a day where the closing price was higher than the opening price. The stock price increased on a day that had a white candle. A black candle indicates a day where the closing price was lower than the opening price. The stock price decreased on a day that had a black candle.

Candlestick Patterns

These candles are used to form patterns. There are several levels to these patterns. At the lowest level, the individual candles have names. The following chart shows some of the more common names for the various candlesticks.

You will notice that many of these candlesticks have Japanese names. Candlestick charts originated in Japan. A Japanese rice trader, who is credited with the invention of the candlestick chart, made his fortune using these charts to trade rice. As a result these same techniques can be used in markets other than the stock market, as the original creator used candlestick charts for the commodities market back in the eighteenth century.

It can be difficult to classify which pattern is which. For example, how long of legs does a long leg doji actually need. Or how big does the body of a spinning top become before it is a white or black candlestick. The program presented in this example uses a simple object I created to classify them. However, it picks arbitrary sizes for the body and shadows to classify them. One area that I want to experiment with, in the future, is using another neural network to figure out which of these micro patterns each candlestick falls into.

Each of these patterns has a meaning. For example the white marubozu is a bullish symbol, whereas the black marubozu is bearish. Some symbols, such as the hammer, can be bullish or bearish depending on what is around them. These individual patterns are often grouped into much larger patterns. One classic pattern is the cup and handle pattern, popularized by William J. O'Neal. It typically signals an upward trend. The following diagram shows one type of cup and handle.

Just as it can be difficult to identify the individual candlestick patterns it can be even more difficult to identify the larger patterns. You can see the cup and handle above. This is a more v-shaped cup. This cup is followed by a shallow dip, which is the handle. After the shallow dip the security experiences an upward movement.

Using the Encog Candlestick Example

This example program works by first obtaining data and then training the neural network. To obtain data choose the "Obtain Data" item from the "Neural Network" menu. This will present you with the following seven options. All are required fields.
    * Symbol
    * Starting Date
    * Ending Date
    * Prediction Window (in days)
    * Bull/Bear Window (in days)
    * Bearish Percent
    * Bullish Percent
Once you have entered these values, click the "Obtain Data" button. The program will pause briefly, while the data is downloaded from Yahoo Finance. The symbol is the company you are using for training. Any company can be used. Further, the training from one company can be used to predict for another. A future enhancement to this program will likely be the ability to use a whole series of companies to train the neural network.

The starting and ending dates define the range of data to train for. Usually you do not want to train all the way up to the current date. You want to leave a few years of data to evaluate the neural network with. You want to test the network with data that it was never trained with to see how truly effective of a neural network you have created.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap