Using equity DNA to improve your portfolio
Post on: 26 Апрель, 2015 No Comment
Just as computers forced the evolution of technical analysis tools, such as static simple, moving averages to sophisticated indicators that dynamically adjust to market conditions, technology is again fueling a leap in trading system capabilities. We can now develop trading systems that are individually tailored to the issues in the portfolio while maintaining the robustness of the overall system.
The implication of having a trading system proven in out-of-sample testing for each stock is profound. No longer will portfolio performance depend on gains elsewhere to offset realized losses. Rather, stocks can be placed with prejudice. We can elect to trade certain stocks when their performance correlates to the periods when an individual trading system can be expected to produce positive returns.
COMPUTER AS ANALYST
This new horizon in system trading is possible by enabling the computer to write the system logic instead of just optimizing a previously established set of rules. In this process, the computer begins by evolving a set of rules. Those rules are then backtested on out-of-sample data to ensure robustness while determining the best trading solution for a given set of input parameters.
From here, the rule set is converted to a standard trading platform language, such as Tradestations EasyLanguage, to exercise the trades on real-time data. The complete trading system development process including input selection, design, testing and translation is fully automated and accomplished quickly.
In essence, we are employing software to write software. The complete process of creating these trading systems can be accomplished in a little over one minute on a readily available Core 2 Duo computer operating with the Windows XP operating system.
Genetic programming is perhaps thousands of times faster than other artificial intelligence algorithms. The central engine allowing this to happen is known as Automatic Induction of Machine Code with Genetic Programming (AIMGP).
Although technically complex, this power is available with a few clicks of your mouse. If you can cut and paste, you can design a trading system. You do not need to define a trading system before the evolution begins because the engine will sort out the inputs to form the trading rules. You do not need to select or develop your inputs unless you wish to do so. No trading system is defined at the beginning of a run; in fact, only raw inputs and operators are available at the beginning of a run.
The Trading System Lab platform, for example, uses an input data matrix visualized as 62 columns and a row for each bar to be used in the back- and forward-testing. Using at least several years of daily data is recommended. Although many data preprocessors exist, the data in each column can be virtually anything you like. It can be numeric or Boolean. It can be indicator values, pattern descriptions, intermarket data, etc. Although 62 columns of data are used as inputs, the platform typically selects only a small fraction of them for use in writing the final evolved trading system. However, unlike other artificial intelligence approaches, the AIMGP combines the selected inputs using dozens of other functions, such as addition, subtraction, trigonometry and exponential functions.
NOT SO NOISY
Of course, it makes sense to select inputs that have some logical relationship to reality to avoid a garbage-in/garbage-out scenario.
One important tangible characteristic of market data that can be measured is its cyclic content. Well look at two example trading systems evolved for the S&P 500 futures contract, trading both long and short over the past five years. Although this approach is demonstrated on the index, as discussed earlier, one of its best uses is in a portfolio of individual equities.
We start with a bandpass filter, developed by John Ehlers of Mesa Software. The bandpass filter allows only the signal energy within its band to get through, rejecting both higher and lower frequency components. Because the passband is relatively narrow, the filter output can be characterized as:
A*Sin(360*t/Period), where
A is the amplitude of the output signal, and
Period is the cycle period of the center frequency to which the filter is tuned
The first 21 columns of data are the filter outputs for filters tuned from eight-bar periods to 48-bar periods in even increments of two bars. In other words, the filter channels are tuned to 8-, 10-, 12-, 46-, and 48-bar cycles. The next 21 columns of data contain the rate of change of each of the filter outputs in the first 21 columns. You may recall from calculus that the rate of change of a sine wave is a cosine wave, which leads the sine wave by 90 degrees (characterized as A*Cosine (360*t/Period)). As every trader recognizes, having a leading indicator is crucial to creating an effective trading system.
The final 20 columns of data comprise the sum of the squares of the corresponding channels to obtain the instantaneous signal amplitude at the output of each filter channel. This is easily seen from the familiar trigonometric relationship. Therefore we have the complete phase and amplitude relationship of each bandpass filter over the range of periods that we think are applicable for an effective trading system. Bandpass code (above) shows the EasyLanguage code for the bandpass filters to generate the data matrix used in the evolution of the example trading systems.
Human logic would lead us to select the channel having the largest output the majority of time and then seek the phase relationship between the sine and cosine outputs that give the best trading signals. In fact, this author has even written trading systems that dynamically sense the dominant cycle and change the filter outputs used as a function of time.
GENETIC PROGRAMMING
PERFORMANCE
Genetic programming automatically selects the most significant columns of data and combines them in ingenious ways that often defy logical description. The result is an evolved trading system whose performance best meets the fitness criterion.
In our example, a single contract system evolved in four minutes, 20 seconds, evolving and evaluating trading systems at the rate of 770 systems per second. This is not curve fitting. The evolution is guided by parsimony pressure, multiple runs, randomization of parameters and an unbiased input set. Parsimony pressure forces the genetic program to use as few input parameters as possible.
Further, out-of-sample performance is evaluated and any given system is discarded if it is not robust in this evaluation. Its important to realize, however, that out-of-sample performance is not analyzed or used during the evolution or else it would not be out-of-sample. In situations where the input set is poor, the setup parameters are inefficient or the market is extremely random, out-of-sample performance will suffer. This is an important test of robustness.
For our runs, a total of five years of data were used, four years as in-sample development data and one year of data for out-of-sample performance verification. At the end of the evolution, sine wave channel periods of 14, 16, 32, 34, 36 and 38 bars were used in the example trading system. Cosine channel periods of 22, 34 and 48 bars also were used. No amplitude data were used, demonstrating that the phase relationships of the filtered outputs are crucial for the generation of trade
timing signals. Which waves? (above) shows the channel filters that were used by the platform in relationship to the price data and the trading signals.
A second trading system was evolved using the same data, but this time allowing for a multiple contract trading system to be developed, using money management during the development process. In this case, only the genetic program determined when and how many contracts to trade. If a trade were deemed risky, only one contract was traded. Multiple contracts, up to a maximum of five, were traded on the higher probability trades. This time, the evolution took only one minute, 13 seconds. Similar, but different, channels were used in the evolved trading system. More interesting, three amplitude channels were also used. Because a money management algorithm needs to respond to volatility of the underlying market, it seems natural that the genetic program chose the more extreme movements inherent in the amplitude segment of the input data matrix. A total of 43,930 trading systems were examined and only 17 of these were retained as having better performance over the course of the evolution, although far more systems were stored in the trading system buffer.
Out-of-sample improvement shows how the out-of-sample performance improved as the trading system evolved. Initially the drawdown (shown in red) increased as the net profit (shown in blue) was increased. However, as the trading system evolved, the out-of-sample net profit increased and the drawdown decreased, stabilizing at about $35,000, an indication of robustness of an evolved trading system.
The second chart in Out-of-sample improvement shows the out-of sample equity growth of the final evolved system. A more detailed examination of the trading system showed it had a total of 60.9% profitable trades and a profit factor of 2.47 over the period from August 2006 to August 2007.
BETTER TRADING WITH TECHNOLOGY
Using modern technology, including both signal processing and genetic programming, highly accurate and robust trading systems can be evolved in mere minutes. This means that each stock, exchange-traded fund or commodity futures contract in a portfolio can have its own customized trading system so that each element in the portfolio is highly profitable in its own right. Then, correlation between all the elements in the portfolio can be accomplished to enable further reduction in variations of the portfolio equity growth.
Other implementations of this algorithm are possible in financial analysis as well as options trading system design. Here, we used indicators created by human knowledge and an evolutionary machine learning algorithm to automatically write our trading system for us, thus demonstrating one successful cooperation between man and machine.
Mike Barna is president of Trading System Lab. He can be reached at mike@tradingsystemlab.com.