TestimonialsAbout UsContact Us
ProductsServicesTechnical SupportBuy Online
 
 


Modulus Financial Engineering
“Trading Edge” Newsletter for January 2003

This issue 1-2003: “Neural Network Leading Indicator Design”

(Next issue: 2-2003: "Consensus Trading... YOU have the Power!")

The risk of loss in trading can be substantial. You should therefore carefully consider whether such trading is suitable for you in consideration of your financial condition. In no event shall Modulus Financial Engineering be responsible for your trading losses.

In this issue we will discus Leading versus Lagging indicators, and then design and code a neural network leading indicator using the Modulus FE TA-SDK.

First lets describe what a “lagging” indicator really is. Most technical indicators are considered to be “lagging” indicators. For example, MACD, RSI, moving averages, etc. are all lagging. By “lagging” I mean that they work best when prices are locked in strong trends, but the most current value of a lagging technical indicator doesn’t warn of upcoming changes in price. In other words, they tell you only what prices are doing or have already done but not what the prices will do in the future. On the other hand we have “leading” indicators, such as pattern recognition, neural networks or other types of adaptive filters and so on. Leading indicators process current and historic prices, other indicators, volume, and sometimes use inter-market analysis to predict the future price, or just as importantly, to predict the likelihood and magnitude of a price change in either direction within a certain time frame. There are many designs for producing a leading indicator but in this article we will construct one with a simple back propagation neural network that is part of the TA-SDK.

Neural Networks have been around awhile and many traders have implemented them in many ways for different markets. In our case, simple is better, so we’re going to construct a neural network leading indicator that takes your favorite lagging indicator and turns it into something useful… a pattern recognition system using lagging technical indicators.
But wait! Didn’t I just say that lagging indicators didn’t have any insight into future prices? No! I said, “the most current value of a lagging technical indicator doesn’t warn of upcoming changes in price”. For example, what patterns can be found in several periods of a lagging technical indicator that has an influence on future price? Can a neural network use a popular lagging indicator to predict price changes? Lets code our system so you can see for yourself and you just might be amazed at what a neural network can do under the right circumstances!

First, a neural network works in this manner: You input several samples of data (your lagging indicator and close price of several periods, for example) and then you tell the neural network what the outcome was for that historical period (e.g. the price n-periods into the future). Do this over and over for hundreds if not thousands of historical samples and the neural network eventually begins to “learn” what is going on. It picks up on whatever non-linear thing is happening even if it is not visible to you, the trader.

A neural network is a “garbage in / garbage out” system. If you input irrelevant information into the neural network, it will output trades that consistently loose money. So the first step is to choose a technical indicator for the neural network input. In this example we chose Tushar Chande’s VIDYA (Volatility Indexed Dynamic Average) although you should experiment with the indicators of your choice. Also experiment by changing the parameters like source field (the close price, open price, volume or you could even calculate VIDYA based on another indicator). You can also experiment with advanced settings using the TA-SDK source code, by changing the neural network’s properties in the NeuralNetwork.cls, .cpp or.java file.

This example uses TA-SDK for Visual Basic, although the same design will also work with TA-SDK for C++ and Java, the syntax would be different.

Note: The TASDK NeuralIndicator function of the NeuralNetwork class takes in seven arguments: The name of the database, the recordset, the periods for sample referencing, neural network learning rate, the number of epochs (times to re-sample), the percent for out of sample test data, and the field name alias.

The most important argument is the 6th, the “out of sample” test percentage. If you choose 50%, the neural network will use 50% of your data for TRAINING, and the remaining 50% will be OUT OF SAMPLE, e.g. the real predicted results. Feel free to back test with this data. If you have a small amount of data (< 1000 records), use a larger percent for training. Of course this means that you will have a smaller test set for back testing but the results will be much better but possibly not statistically significant. And remember, past performance isn’t necessarily indicative of future results. There is no better example of this than an over-trained neural network. Yes, neural networks can be over-trained and can actually curve fit to your data, but of course your out of sample set will show this problem very clearly. The recordset that is returned from the neural indicator function will only contain the predicted values, and the leading 50% training set will have NULL records (0), so there will be no confusion as to what is out of sample or what is used for the neural network training samples.

Interpretation
No matter what type of lagging technical indicator you use, the output of the neural network usually oscillates between –1 and 1. The most common interpretation is to buy when the value retreats from a high, and the signal to sell is when the value retreats from a low.

Source Code (this source code is also available for C++ and Java):

'To use the TASDK.dll ActiveX library from within Microsoft
'Visual Basic or Microsoft VBA (Word, Excel, Access...), point
'to Project > References and locate the TASDK.dll library.

Sub Main()

Dim Record As Integer
Dim DB As New TASDK.Database
Dim rsOHLCV As New TASDK.Recordset
Dim rsVIDYA As New TASDK.Recordset
Dim rsNN As New TASDK.Recordset
Dim MA As New TASDK.MovingAverage
Dim NN As New TASDK.NeuralNetwork

'Open the database (a text file in this example)
DB.OpenDatabase App.Path & "\msft.csv", ","

'Select all fields in the database
Set rsOHLCV = DB.getRecordset

'Calculate VIDYA from the close price with 9 periods and R2 scale of 0.65
Set rsVIDYA = MA.VIDYA(DB, rsOHLCV.getField("Close"), 9, 0.65, "A")

'Train the neural network using the VIDYA indicator that was just
'calculated, with 9 periods, 0.9 learning rate, 500 epochs on 90%
'of our test data. This may take several seconds to several minutes
'depending on how many samples the neural network must learn:
Set rsNN = NN.NeuralIndicator(DB, rsVIDYA.getField("A"), 9, 0.9, 500, 90, "NN")

'Now the neural network has finished, and we have a leading indicator!
'Print the results:
For Record = 1 To DB.getRecordCount
Debug.Print rsNN.getValue("NN", Record)
Next Record

'Clean up
DB.CloseDatabase
Set DB = Nothing
Set rsOHLCV = Nothing
Set rsVIDYA = Nothing
Set MA = Nothing
Set NN = Nothing

End Sub

Copyright(c) 2008 by Modulus Financial Engineering

 


TA-SDK source code is available in several programming languages. This means you get the actual technical analysis source in the programming language you are most fluent with. 
 



Develop powerful trading applications with Microsoft Visual C++ in record time. Read More



Use the TA-SDK ActiveX DLL with Microsoft Visual Basic, FoxPro, Excel, and Access. Read More



The TA-SDK CLR library and source code is available for Microsoft VS .net. Examples available for both C# and VB.net. Read More



Develop cross-platform trading apps in Sun Java with the TA-SDK JAR package and source code Read More



Link TA-SDK to any DDE or ActiveX real-time data feed in Microsoft Excel!
Read about TA-SDK Excel Edition  Read More 



Experience the power of TA-SDK coupled with the dependability of the UNIX or Linux OS. Read More

 

 
 
   Email This Page
Copyright ® 1999 - 2008 Modulus Financial Engineering, Inc.