Neural Networks in Trading: Could we Build a System that Learns to Learn? : Mixing NNs with Genetic Programming

One of the most intriguing goals of algorithmic trading has always been to achieve a level of flexibility and adaptability which is similar – at least in some ways – to the way in which a human brain works. Many people regard the lack of “market awareness” of strategies as the reason why failure happens when market conditions change significantly (when compared to the back-testing data experience) and therefore the aim is to build systems which can learn to adapt to market conditions as they evolve. In Asirikuy we have already achieved some level of market awareness with our Sunqu neural network based trading strategy – which constantly adapts to evolving market conditions – but I still believe that Sunqu is very far away from trading like a human being does because it lacks the ability to change the very nature of the way in which it trades. What does it mean to trade and see the market like a human? and most importantly, can we achieve this with an algorithmic trading strategy? I believe the answer to this question is a big YES.

Why would we want to trade like humans? Well first of all we should remember that humans actually hold no advantage against current algorithmic strategies when trading. As some of you may remember – within an article I published about a year ago – the Algorithmic Vs Discretionary Barclay indexes have almost the same level of profitability through the past 20 years, revealing that both types of trading have the same overall edge over the market. Note that I am not looking to achieve a system that trades like a regular discretionary trader does – as this would bring no clear advantage – but I want to build a system which can use methods akin to higher human cognitive powers (in a sense total adaptability) to be able to better tackle changing markets. You could say that my challenge here is to go beyond what both regular algorithmic and discretionary traders can do, to build a trading system which can have the absolute best of both worlds (market awareness and the capability to be evaluated through back-testing, etc).

-

-

Now why isn’t Sunqu trading like a discretionary trader? What is it missing? In general Sunqu adapts to changing markets in some sense as its neural network abilities allow it to change its entry logic so that it can have some plasticity against the market. The main problem here is that Sunqu still has some “hard” rules in its core which determine how it should trade. For example it always uses a fixed stop loss of a given percentage of the ATR and it always enters trades depending on a particular behavior given by an evolving neural network. So yes, Sunqu adapts in a certain way to the market but it also has some inflexibility which is the main reason why it cannot be profitable on every pair. Sunqu trades wherever an inefficiency related with its primary trading methodology exists, therefore limiting its trading to a few pairs. We could say that Sunqu is a partially adaptive trading technique but the fact that it is not universal and the fact that some aspects of its trading logic never change makes it only that.

How can we go even further? One of the biggest challenges here is to take the level of adaptability to a point where there is enough abstraction about a trading logic as to make it potentially universal. How can we do this? We could build a trading strategy which mixes both neural networks and genetic programming. What does this mean? Well, imagine a trading system which has no prior knowledge about the market than what a discretionary trader has. The system knows some past data, it knows that certain indicators exist and it knows that OHLC data is there, the system then runs a neural network with each one of these different components, attempting to predict different things which might lead to inefficiencies and then it chooses whichever network gives the best result. Neural network choices are tried through genetic optimization techniques meaning that only a small subset of the total parameter space is evaluated and in the end the system chooses the best neural network and money management which achieved the best result over some past period. Using this information the system then draws a prediction for the future and repeats the whole process after the next trade is closed.

What we have here is a way in which a trading system can “build itself” with very little knowledge about the past. A trading strategy simply takes information that a regular trader would also have available and it attempts to build different predictive paths which could lead to market inefficiencies, a genetic optimization then tells it what the best path would be and it then chooses this path to execute the next trade, the process is repeated after this and the system is able to remain constantly adaptive in many ways, in a very similar way to how a human would adapt to changing market conditions. With a system like this we would have something akin to the “ultimate” trading machine, a system which is able to adapt to changing market conditions in virtue of a very deep evaluation of what has “worked” or “hasn’t worked” in the past. In my mind such a system would be tremendously valuable as it would have the ability to adapt to any trading symbol and any developing market conditions as long as there is some sort of inefficiency in the market.

Certianly there are many challenges which need to be overcome in order to build this type of trading system. The first one would be to build the code for neural genetic optimization and to include all the coding flexibility needed for the program to be able to choose a network in an entirely dynamic way. The system would be able to choose things ranging from topology to actual input and output choices. Although the actual choices would be finite – as they are for a human trader – the actual parameter space would be so large that they would be practically infinite when viewed from a computational power perspective (this is why we would need genetic optimization). Once you build the genetic optimization and neural network structure you would also have the challenge of actually doing evaluations since every trade would require extensive computational power to perform all neural network calculations (which would be potentially in the tens of thousands of network test runs).

-

-

But how would this exactly work? First of all the system would figure out what the best method of trading for the past X days has been. The system would look for the best inputs, the best outputs, the best topology and the best money management techniques in order to figure out what the most successful way of adapting to market conditions has been. This means that the system needs to try many different neural networks and perform back-tests of this whole period, each one as if it was a single “sunqu” type test. Once this is finished the system will then use the “best” technique found in order to tackle its next trade. The process would then be repeated and the system would therefore be able to adapt to changes in market conditions in the most absolute sense. Most probably such a testing procedure would need to be coded in something different to MT4 so potentially this EA would need to run tests using many computers or cores in an ANSI C environment.

Is this worth all the effort? This is one of the biggest questions I currently have and the reason why I am developing a small approach in this direction to be able to choose between several network inputs with fixed topology to see if there is really an advantage in doing this type of trading analysis. If my first results show that this can be successful I wouldn’t have any doubts in developing a much more powerful NN genetic framework which could serve as a very good solution to the algorithmic trading problem. Sounds exciting? It definitely does to me :o) If you would like to learn more about my work in automated trading and how you can learn more about algorithmic trading through knowledge and understanding please consider joining Asirikuy.com, a website filled with educational videos, trading systems, development and a sound, honest and transparent approach towards automated trading in general . I hope you enjoyed this article ! :o)

Print Friendly
You can leave a response, or trackback from your own site.

6 Responses to “Neural Networks in Trading: Could we Build a System that Learns to Learn? : Mixing NNs with Genetic Programming”

  1. Bryan says:

    Hi Daniel,

    One thing popped up in my mind.
    Can you reproduce the same results, for instance started with 10 years and 20 years historical data?

    I have a simple adaptive system. With in the system, there are 3 subsystems, A, B, C. I will allocate certain ratio of capital to each subsystem at the beginning of each year. The ratio are calculated using previous year results. A, B and C are of different kind of strategies, ie. Trend Following, Sideways and Combination of 2. What do you think?

  2. Franco says:

    Sounds VERY exciting! Daniel I would not ever bother with this if there is no way of testing this within an adequate amount of time. A Sunqu test can take days, a project such as this could take months per backtest!

    One solution that I already looked at (and asked J. Heaton (developer of Encog) to implement it with Encog) is from Dew Research. They have object oriented based mathematical libraries that are extremely fast (Assembler speed) for many languages (including .NET and Delphi). The basic math library (Math387) for basic math functions are free.

    Are you looking at writing this from scratch? You can also take a look at a NEAT network that uses genetic to build a the best network for the given inputs and outputs.

    I wish you good luck my friend this is a big project!

  3. Gabor says:

    How about creating a BOINC project to add up the idle computational capacity of Asirikuy community?

  4. Igor says:

    Good idea Daniel but very difficult to code and test.

    As a step in this direction, how about taking an existing Asirikuy system such as Coatl and enabling it to geneticly optimize itself every x days using y amount of most recent data. This could give us a system that works on any instrument without changing the system parameters.

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!