Trading System Generator

Trading System Generator

event_note 12.01.2019

Intro

Once upon a time there was a term Artificial intelligence defined. It’s subcategories emerged soon after, some of them were inspired by nature. Be it reimplementation of evolution by natural selection proposed by Charles Darwin and Alfred Russel Wallace or deep learning inspired by the structures found in our own brains. Nowadays most of its implementations are tight to computational resources of universal processors, graphical cards, FPGA and ASIC circuits.

Genetic programming algorithm

We might have started from the easier target it seems. Genetic programming is a technique generating computer programs using evolution based algorithm.

As the start of a run the evolution algorithm is generating a population with set number of randomly generated individuals. Each individual is represented as a list of specific number of trees.

Each tree in the individual represents specific trading strategy behavior – be it asset selection, entry condition, entry filter, stop loss, exit condition, exit filter. Six trees in every individual in this specific case.

Each individual is run as a trading strategy. It might generate some trades then statistics are calculated. Various statistics can be used for the individual fitness. Right now we are using sharpe ratio multiplied by number of trades to push the evolution algorithm to prefer individuals with higher number of trades.

Based on fitness the evolution algorithm selects individuals for mating and mutating phase. Mated/mutated individuals are made part of the population and the individual’s fitness is calculated again. The best individual is kept in the hall of fame.

This iterative process goes on and after several generations we are expecting working trading strategy in the hall of fame.

Practicalities

“Slowness” of Python is negligent as most of the time is spend calculating an individual fitness. Our individuals are creating signals – genetic programming trees are made  with numpy and talib optimized functions (C code), the trading algorithm is represented as fully optimized state machine in Cython. In another words from programming point of view it’s mixed vectorized and event based approach to trading system programming.

Possibilities

By changing of fitness function we can push the evolution algorithm to generate specific trading strategies. Be it specific risk profile, maximum profit or optimized portfolio. There is a possibility to optimize just part of already existing strategy – for an example we will be taking an existing strategy with defined entries and the genetic programing will be evolving strategy exits. Additional inputs are possible to use as well – sources of sentiment information, market and intermarket indices, deep learning networks with pre-trained alphas and well known market alpha signals, etc.

Interesting thing with genetic programming and big amount of alpha factors might be ability to select ones which really matter in the market without being tight to usual evaluation within specific number of days to the future.

Miloň Krejča