Hoggums
Senior member
- Messages
- 2,176
- Likes
- 878
I thought I'd share with you a little experiment I'm performing to see if a neural network can be trained to successfully trade an index and/or forex.
Generally speaking, neural networks are trained by comparing the output it produces with an expected result and feeding the error back into the network so it can correct itself slightly. The next time the neural net is tested the output is slightly closer to the expect result.
But herein lies the problem with teaching a neural network how to trade - who's to say the way you are teaching it is either the best or correct way. You are teaching it with your own knowledge and therefore own misconceptions and mistakes and the neural net will repeat those mistakes after training. I've seen neural nets use moving averages, entry/exit rules and other such inputs to make trading decisions. I want to get away from this.
Wouldn't it be better to let the neural network figure out how to trade for itself?
So the aim of the experiment is to start off with a completely random network and let it trade and record the results. I am not going to tell it what results I am expecting, but just reward the best results. I am going to use Darwins theory of natural selection to let the network "evolve" itself into a better trader. The network will spawn off several copies of itself with small random variations, let them all trade and take the best few networks and discard the rest. Then repeat the process until consistent and reliable results are achieved and no more improvements can be found.
I also want to see what the optimum amount of data is necessary to produce the best network - e.g. for trading on daily candles do you need only 1 week of data or several months to make an accurate prediction.
That's the theory anyway. Currently I have no idea if it will work and it may take several neural net configurations before I have some consistent data. What will be interesting is to see what kind of trading approach evolves, I'm going to start trading with daily candlesticks and it'll be interesting to see whether it decides buy and hold is the best or whether it tries to trade short term swings.
Simple steps to start with, I am going to build a direction predictor. The output of the network will be a single neuron with 2 states - either BUY or SELL. I will input a range of candlestick data into the net and count how many pips are won/lost by the time the next candlestick is completed, then the net will evaluate BUY/SELL again.
For the first experiments, networks will be kept/disgarded purely on the basis of the total number of points they achieve over the historical data. However I will weigh the points according to the index level. Gaining 1 point when the S&P was at 100 is a lot more significant than gaining one point when it was at 1200.
I'm going to train the network on daily data from the S&P from 3-Jan-1962 to 31-Dec-2006. The S&P is relatively friendly to indicators given it's large number of constituents. I am keeping data from 1-Jan-2007 aside for forward testing, I think it will be interesting to see how any evolved network will cope with the credit crunch. I'm hoping by training on such a large range of data from '62 - '07 that the net will not become too optimised, however I can't guarantee this and I'm deliberately leaving out a pretty volatile period in history to see if the network can cope with this unseen data.
Afterwards I will increase the complexity of the outputs - stating trade size, stop size and limits. I will also see if the evolved network is capable of trading other more tricky indices like the Dow Jones Industral and the Nikkei without ever having seen the data before.
If any of this is successful I will move onto shorter timeframes in forex to see if a similar network can be built.
keep tuned more will follow in the coming days..
Generally speaking, neural networks are trained by comparing the output it produces with an expected result and feeding the error back into the network so it can correct itself slightly. The next time the neural net is tested the output is slightly closer to the expect result.
But herein lies the problem with teaching a neural network how to trade - who's to say the way you are teaching it is either the best or correct way. You are teaching it with your own knowledge and therefore own misconceptions and mistakes and the neural net will repeat those mistakes after training. I've seen neural nets use moving averages, entry/exit rules and other such inputs to make trading decisions. I want to get away from this.
Wouldn't it be better to let the neural network figure out how to trade for itself?
So the aim of the experiment is to start off with a completely random network and let it trade and record the results. I am not going to tell it what results I am expecting, but just reward the best results. I am going to use Darwins theory of natural selection to let the network "evolve" itself into a better trader. The network will spawn off several copies of itself with small random variations, let them all trade and take the best few networks and discard the rest. Then repeat the process until consistent and reliable results are achieved and no more improvements can be found.
I also want to see what the optimum amount of data is necessary to produce the best network - e.g. for trading on daily candles do you need only 1 week of data or several months to make an accurate prediction.
That's the theory anyway. Currently I have no idea if it will work and it may take several neural net configurations before I have some consistent data. What will be interesting is to see what kind of trading approach evolves, I'm going to start trading with daily candlesticks and it'll be interesting to see whether it decides buy and hold is the best or whether it tries to trade short term swings.
Simple steps to start with, I am going to build a direction predictor. The output of the network will be a single neuron with 2 states - either BUY or SELL. I will input a range of candlestick data into the net and count how many pips are won/lost by the time the next candlestick is completed, then the net will evaluate BUY/SELL again.
For the first experiments, networks will be kept/disgarded purely on the basis of the total number of points they achieve over the historical data. However I will weigh the points according to the index level. Gaining 1 point when the S&P was at 100 is a lot more significant than gaining one point when it was at 1200.
I'm going to train the network on daily data from the S&P from 3-Jan-1962 to 31-Dec-2006. The S&P is relatively friendly to indicators given it's large number of constituents. I am keeping data from 1-Jan-2007 aside for forward testing, I think it will be interesting to see how any evolved network will cope with the credit crunch. I'm hoping by training on such a large range of data from '62 - '07 that the net will not become too optimised, however I can't guarantee this and I'm deliberately leaving out a pretty volatile period in history to see if the network can cope with this unseen data.
Afterwards I will increase the complexity of the outputs - stating trade size, stop size and limits. I will also see if the evolved network is capable of trading other more tricky indices like the Dow Jones Industral and the Nikkei without ever having seen the data before.
If any of this is successful I will move onto shorter timeframes in forex to see if a similar network can be built.
keep tuned more will follow in the coming days..