Lukasz Wojtow
lukasz@wojtow.me
Genotick.com
London, 2016
Table of Contents
Abstract...................................................................................................................................3
Example systems.....................................................................................................................8
Detailed overview..................................................................................................................10
Parameter sensitiveness.........................................................................................................27
Conclusions...........................................................................................................................30
Literature...............................................................................................................................39
2
Abstract
market trading. Hence, it is no surprise that traders have been looking into
Artificial Intelligence (AI) from its very early days. However, most AI
type of trading systems with the equally simple instruction set. After all,
that reads historical data and comes up with some prediction. Our
Open Source Software that implements our method and allows for
3
We showed that these simple instructions grouped together can
create a profitable trading system. Our software does not require a list of
potentially profitable trading rules. It also does not have any rules built in.
When it is run for the first time, there are no systems. It has to learn how
Our method can build any type of system: trend following, mean reverting,
Network multiple times. If the Neural Network can see the data more
than once, it can learn to react to changes that are not market
inefficiencies but just noise. This can be reduced by selecting how much
is also data dependent and in the end is just another parameter that must
be adjusted.
Walk-Forward only. That is, similarly to actual trading in real life, our
and trading modes. Also, to better simulate real life, we forced the
algorithm to trade on the markets next price, instead of its last. This is to
4
simulate a real life delay between analysis and placing a trade.
lists. Each system has one list of instructions than can be up to 1024 long.
trust the system - its output will always be the same on the same data.
All systems are saved in a population which is adjusted (or learns) over
Our algorithm assumes that there are multiple systems, each a little
bit different. We then take all their predictions to calculate one cumulative
calculates profit yield by these predictions and reports it to the user at the
end. The final result is what a user would get in real life when executing
Secondly, rationale doesn't matter as much as people think. After all, the
market does not know why a trader put a position, so final result (profit
5
if a system is always Long, is it because it is trend following and it
system without knowing its deep logic and fully understanding underlying
Forward only. This makes its results to be trustable and repeatable in real
6
Why Artificial Intelligence?
chess programs that beat an average professional have been known for
methods, will reward those on the cutting edge of research. Best hedge
funds may be still be run by humans but if their method is really better, AI
will figure it out as well. Besides, most traders do not compete with the
best. Just like in the tale where two men are trying to escape from the
bear, they need to out run one another, not the bear. Because stock
market has so much randomness, it will take traders longer to notice that
using AI, they suddenly can reach to methods that were not available for
them before. By utilizing AI, traders can trade free from their believes,
7
Example systems
another. This chapter shows some simplest systems. Real systems are
Systems below assume that following data were fed to the software:
#Time, Open, High, Low, Close, Volume, PE ratio, Wide Market PE ratio
20060103,100,102,99,101,42,16,18
20060104,102,102,101,102,30,17,19
20060105,104,106,99,101,26,16,18
20060106,106,108,106,108,90,18,17
Lets assume that today is 4th January 2006, after market close.
means that system is betting Short. Zero means that system would like to
8
stay out of the market.
A system that bets Long if the stocks PE ratio is lower than that of wide
That means that systems would open a Long position at the next open
volume, days high or in fact any data that can be represented as a real
number.
9
Detailed overview
data from user supplied data files. For the purpose of system execution,
data is truncated (in memory) at the day being currently processed and no
future data is given to the system. System then execute its instructions.
indirectly by leaving register 0 with its last value. Processor then looks at
this value and returns systems prediction based on its sign. If value is
(Short). Value 0 means that the system has no prediction for the next day.
prediction for the market. For this it looks at each systems prediction and
10
Prediction Up Prediction Down
System with positive Add systems weight to Add systems weight to
weight Up votes Down votes
System with negative Add systems absolute Add systems absolute
weight weight value to Down weight value to Up
votes votes
This implies that systems that have very high negative weight are actually
useful. In other words, they are so bad, that it is worth betting opposite to
their predictions.
a trade was opened at the next available open price (so it will be second
than todays close is necessary to simulate real life trading: after all,
collecting data and running software to check prediction takes long enough
11
systems weight is very simple:
2. Return positive value from point 1 if the system was more often right
wether predicted direction of the change was correct and not how close
2. This does not force trader to take on particular option strategy. In other
words, if the algorithm punished systems based on how far they were from
short straddle with strike equal tomorrows price. Also, some option
strategies reward being right more than being wrong (at the same distance
other methods and only use AI for predicting future price, he would need
more practical to use AI for predicting delta and leave the choice of
12
bogus systems build on flawed ideas. To quickly determine if a system is
data. For example this is SPX chart for years 1999 2015:
13
Illustration 2: Reversed ("mirrored") SPX stock index
When a user wants to train Genotick to trade SPX, two data files need to
be provided: original SPX and its exact reflection. Later, while training
equal Shorts for each day, the system will be rejected making space for a
designed to remove systems that were good in the past (and still has some
weight) but the inefficiency they used to exploit may be long gone. It is
14
More important is the next stage where systems are removed based
The last stage of the main loop is where systems breed. Currently
weight. Two parents are selected and their instruction lists are copied in
15
Results on random data
One of the biggest challenge when creating any type of simulation software
is to make sure that there are no errors that make results bogus. One type
from the future making results look suspiciously good. This type of error
correctness.
It seems like the most reliable way to check for this type of error is to
try to predict completely random time series, for example one that is
generated by a fair coin toss. Traditional Neural Networks iterate over the
same data more than once and hence their results look as if it was
possible to make a profit trading white noise data [10]. This problem is
system would never make profit trading real market (except for just getting
lucky).
market where price changes a generated from a fair coin toss. Initial
down the same amount. There is no rule to the changes and there is
16
nothing to learn. Chart below shows two time series: original random and
its reverse. We then run Genotick ten times to see if it makes profit:
17
Results on fake data with known pattern
we already know. In the case of predicting changes in time series this can
there was 60 % chance that a food pellet would drop on left side of a
T-shaped maze. Rats quickly learned to ignore the right side and in the
They refused to believe that there was nothing more to predict and an error
has 60% chance that it will go up by 1.0 and 40% that it will go down by
18
Illustration 4: Fake market, going Up 6 out of 10 times
systems:
19
Then, we run Genotick with its default settings. Cumulative profit on
Next came fake trending data. We created a market where price had 55%
chance that the change between data points (n+2) and (n+3) will be the
same as change between (n) and (n + 1). There was 45% chance that the
20
Illustration 7: Fake trending market with its mirror reflection
Genotick struggled for a long time but in the end it learned the inefficiency
21
Similarly to fake trending data we created fake mean-reverting market.
This time, there was 45% chance that change from (n+2) to (n+3) will be in
the same direction as change from (n) to (n+1). There was 55% chance that
the change will be in opposite direction. Chart below shows main and
22
Illustration 10: Profit on fake mean-reverting market
Results on fake data with known inefficiency suggests that our algorithm
along. Therefore, it can be repeated in real life, trading and learning one
23
Results on real market data
We used 10 years of historical data for each market, from 2006 to 2015
draw-down would be 18 %.
24
Illustration 12:
11: Genotick's
Buy-and-Hold
profit
results
on SPX,
on SPX,
GoldGold
and USD
and USD
IndexIndex
For a comparison, we run Genotick with its default settings on the same
Algorithm continued training (and trading) until 31st December 2015, but
period from 1st January 2006 was on record. Table below summarizes
performance from 1st January 2006 to 31st December 2015 for both
methods.
Genotick Buy-and-Hold
CAGR (%) 8.7 5.5
Maximum draw-down (%) 12.5 18
MAR ratio 0.69 0.3
Sharpe ratio (1% risk free rate) 0.88 0.66
25
It is worth noting that presented results show only directional edge
26
Parameter sensitiveness
AI algorithm does not break down when run with parameters different
parameters.
was mainly due to the fact that some settings let it learn more quickly than
others. Once the inefficiencies were discovered, profit was fairly similar on
each run. Start date for simulations was 1st January 1999, last day was
31st December 2015. Table below shows profits (in percent) for each year
2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
Run 1 12.0 26.9 14.1 17.4 14.7 -0.9 -1.5 2.1 6.7 -1.1
Run 2 11.9 26.8 14.8 17.4 14.1 -0.6 -1.7 2.1 6.5 -1.2
Run 3 11.4 26.6 15.1 18.2 14.1 -0.7 -1.5 2.1 6.5 -1.0
Run 4 11.6 27.0 16.1 18.2 14.1 -0.8 -1.6 2.1 6.8 -1.0
Run 5 11.9 25.9 15.7 18.2 13.6 -1.1 -1.6 2.2 6.7 -1.1
Run 6 12.2 27.1 15.3 18.9 14.2 -1.1 -1.6 2.1 6.8 -1.1
Run 7 11.3 26.8 14.2 18.9 14.1 -1.1 -1.7 2.2 6.0 -0.8
Run 8 11.5 26.0 15.0 16.2 14.4 -0.9 -0.6 0.3 6.0 -1.8
Run 9 11.8 26.6 15.3 17.4 14.1 -0.8 -1.7 2.3 6.4 -1.1
Run 10 11.6 27.1 16.1 18.5 14.1 -0.6 -1.7 2.1 6.4 -1.0
Table 3: Results with randomized input parameters
27
As can be seen, programs results depend very little on initial parameters.
In fact, authors would like to achieve more variation between independent
runs.
28
License & Source Code
Genotick has been released under Gnu General Public License version 3.
modify and extend the program to their needs. Full text of the license can
https://github.com/alphatica/genotick
29
Conclusions
that implements it. We released software with liberal GPLv3 license, that
30
Appendix I: Software settings
31
Parameter Default Description
Value
PopulationDesiredSize 5000 Desired number of
systems in the
population.
ProcessorInstructionLimit 256 This setting prevents
systems to run forever.
Maximum instruction
count is calculated as
value * systems length.
MaximumDeathByAge 0.01 This setting is used to
calculate how many
systems is considered to
be removed based on
their age.
MaximumDeathByWeight 0.01 This setting is used to
calculate how many
systems is considered to
be removed based on
their weight.
ProbabilityOfDeathByAge 0.5 Probability of removing
a system because it is
too old.
ProbabilityOfDeathByWeight 0.5 Probability of removing
system because its
weight is too close to 0.
InheritedChildWeight 0 Initial weight for a child
calculated as average
parents weight * value.
32
Parameter Default Description
Value
DataMaximumOffset 256 This setting limits
system access to
historical data. Systems
cannot see further than
value data points ago.
ProtectRobotsUntilOutcomes 100 This setting regulates
how long systems are
protected for. Protected
systems cannot be
removed due to their
weight or age.
NewInstructionProbability 0.01 Probability of new
instruction when making
a child.
InstructionMutationProbability 0.01 Probability of mutating
existing instruction
when making a child.
SkipInstructionProbability 0.01 Probability of skipping
an instruction when
making a child.
MinimumOutcomesToAllowBreeding 50 This settings is used to
decide when a system
can have a child for the
first time. It is used to
prevent over-breeding for
one system.
33
Parameter Default Description
Value
MinimumOutcomesBetweenBreeding 50 This setting is used to
decide how soon a
system can have a child
after previous child.
KillNonPredictingRobots true This setting allows to
remove systems that vote
to be out of the market.
In such case the system
is removed even if it is
protected.
RequireSymmetricalRobots true This setting allows to
remove systems that do
not yield mirrored vote
on mirrored data. It is
used to prevent keeping
systems that have
permanent Long or Short
bias.
RandomRobotsAtEachUpdate 0.02 Number of totally new
and random systems to
be added at each time
point (as a fraction of
PopulationDesiredSize).
34
Parameter Default Description
Value
ProtectBestRobots 0.02 Elitism. Number of best
systems to protect (as a
fraction of
PopulationDesiredSize).
Protected systems are
not removed even if their
age is high.
IgnoreColumns 0 This setting allows to
ignore first value
columns while learning.
35
Appendix II: Instruction set
36
JumpIfRegisterEqualDouble, JumpIfRegisterEqualRegister,
JumpIfRegisterEqualZero, JumpIfRegisterGreaterThanDouble,
JumpIfRegisterGreaterThanRegister, JumpIfRegisterGreaterThanZero,
JumpIfRegisterLessThanDouble, JumpIfRegisterLessThanRegister,
JumpIfRegisterLessThanZero, JumpIfRegisterNotEqualDouble,
JumpIfRegisterNotEqualRegister, JumpIfRegisterNotEqualZero,
JumpIfVariableEqualDouble, JumpIfVariableEqualRegister,
JumpIfVariableEqualVariable, JumpIfVariableEqualZero,
JumpIfVariableGreaterThanDouble, JumpIfVariableGreaterThanRegister,
JumpIfVariableGreaterThanVariable, JumpIfVariableGreaterThanZero,
JumpIfVariableLessThanDouble, JumpIfVariableLessThanRegister,
JumpIfVariableLessThanVariable, JumpIfVariableLessThanZero,
JumpIfVariableNotEqualDouble, JumpIfVariableNotEqualRegister,
JumpIfVariableNotEqualVariable, JumpIfVariableNotEqualZero and JumpTo.
Finishing instructions
Any of these instruction will terminate execution of the program:
ReturnRegisterAsResult, ReturnVariableAsResult and TerminateInstructionList.
Computational instructions
These instructions compute a value for a given column in a data file:
37
Instruction name Description
AverageOfColumn Calculates the arithmetic average of
given column. Columns index and
length of the average are given as
arguments.
HighestOfColumn Calculates the highest value of given
column. Columns index and length are
given as arguments.
LowestOfColumn Calculates the lowest value of given
column. Columns index and length are
given as arguments.
SumOfColumn Calculates the sum of all values in
given column. Columns index and
length are given as arguments.
38
Literature
[2] - Language Log. (December 11,2005). Rats beat Yalies? Doing better by
getting less information?
http://itre.cis.upenn.edu/~myl/languagelog/archives/002700.html
[5] - Tetlock, P. (2005). Expert political judgment: How good is it? How can we
know?. Princeton University Press. ISBN-13: 978-0691128719
[6] Michalewicz, Z. & Fogel, B. (2004) How to solve it: Modern Heuristics ISBN
978-3-662-07807-5
[9] Surowiecki, J. (2005). The Wisdom of Crowds: Why the Many Are Smarter
Than the Few ISBN-10: 0349116059
39
[11] Vince, R. (1992). The Mathematics of Money Management: Risk Analysis
Techniques for Traders ISBN-10: 0471547387
[13] van Dyk, S. 2013. Genetick Programming. Evolving decission trees with
application in Investment Management
40