Today, I wish to delve deeper into the use of evolutionary algorithms, particularly genetic algorithms, in the context of asset management. The example I will be using is a tribute to the friends and colleagues of AATI (Asosiasi Analis Teknikal Indonesia) and IFTA (International Federation of Technical Analysts) at large. We are now just three weeks away from the commencement of the IFTA International Conference 2023, which will be held in Jakarta, Indonesia, for the first time (you can read all the details here). This article serves as a sneak peek into what I will have the honor of presenting on that occasion.
Let’s begin by listing a initial set of high-cap stocks traded on the Jakarta Stock Exchange (Indonesia Stock Exchange ISX):
- PT Bank Central Asia Tbk (BBCA.JK)
- PT Astra International Tbk (ASII.JK)
- PT Bank Rakyat Indonesia Tbk (BBRI.JK)
- PT Telkom Indonesia Tbk (TLKM.JK)
- PT Bank Mandiri (Persero) Tbk (BMRI.JK)
- PT Unilever Indonesia Tbk (UNVR.JK)
- PT Indofood Sukses Makmur Tbk (INDF.JK)
- PT Bank Negara Indonesia (Persero) Tbk (BBNI.JK)
- PT Adaro Energy Tbk (ADRO.JK)
- PT Gudang Garam Tbk (GGRM.JK)
- PT HM Sampoerna Tbk (HMSP.JK)
- PT Bank Danamon Indonesia Tbk (BDMN.JK)
- PT United Tractors Tbk (UNTR.JK)
- PT Semen Indonesia (Persero) Tbk (SMGR.JK)
- PT Indofood CBP Sukses Makmur Tbk (ICBP.JK)
- PT XL Axiata Tbk (EXCL.JK)
- PT Bank CIMB Niaga Tbk (BNGA.JK)
- PT Indo Tambangraya Megah Tbk (ITMG.JK)
- PT Charoen Pokphand Indonesia Tbk (CPIN.JK)
- PT Jasa Marga (Persero) Tbk (JSMR.JK)
- PT Kalbe Farma Tbk (KLBF.JK)
- PT Perusahaan Gas Negara (Persero) Tbk (PGAS.JK)
- PT Bank Tabungan Negara (Persero) Tbk (BBTN.JK)
- PT Wijaya Karya (Persero) Tbk (WIKA.JK)
- PT Tower Bersama Infrastructure Tbk (TBIG.JK)
To build a statistically sound foundation, we have isolated those stocks whose historical data spans at least twenty years of daily records. It may be rightfully argued that such a selection could introduce “Selection Bias”, but for purely demonstrative purposes, we will proceed with this initial, albeit crude, approach.
The idea is to construct a genetic engine that, starting from a specific “Genetic Pool”, generates a DNA capable of discriminating the assets to be purchased periodically.
Let’s imagine using daily data (“period”) and operating on a weekly basis (“trigger”). We establish a rule that optimizes a specific “Fitness Functio”, such as the Sharpe Ratio or the Kestner Ratio, over a training period (“In Sample”), and observe what happens with unknown data (“Out of Sample”). During the Jakarta speech, we will delve into the most suitable approach for constructing such a validation architecture.
In the first week, the system will allocate its funds to assets 1, 2, and 5 (which it will hold until the end of the week). In the second week, it will allocate funds to assets 2, 3, 4, and 6, and so on. The resulting portfolio curve, which can also account for appropriate fixed costs, will be compared to a Buy & Hold strategy where the entire basket is purchased for the entire period.
Returning to the Genetic Pool, in this example, we are utilizing 48,900 elementary rules.
An example of a rule (gene) that we have used is the following:
mean_10(2) > mean_10(3)
Which can be interpreted as “the 10-day moving average of daily percentage changes measured two days ago is greater than the 10-day moving average of daily percentage changes measured three days ago”. Further details on the genetic pool and the recombination of rules will be provided at the IFTA Conference and within the educational accelerator “Machine Learning Academy” (currently available only in Italian, details here).
The project parameters, which do not follow the Darwinian approach, as shown in the following figure, characterize a population of 10 individuals for 1000 generations (for a total of 10,000 individuals competing with each other), a DNA composed of 3 genes each, a 30% of the best individuals to be saved for each generation, a 30% produced by crossover only, a mutation probability of 20% (rather high in this test), a fitness function defined by the ratio of profit to average drawdown, and an instability factor of 5%.
The best individual of the first generation is an organism with fairly consistent equity (in the training period to the left of the red vertical line, which separates In Sample and Out of Sample) that persists in terms of slope and variance in the subsequent period.
After a few generations, performance improves in the In Sample period (with the exception of the extreme drawdown during the 2008-2009 period), but the algorithm no longer appears capable of generating profits on unknown data. In a multi-dimensional validation model, we can hypothesize that we have exited the “Persistence Zone”.
Over 400 generations later, we observe an improvement in the evolution metric (at the cost of a reduction in performance in the In Sample), and the recovery of a maximum equity line in the Out of Sample.
In generation 750, the curve further smoothens, and despite not appearing to have the ability to avoid exogenous factors (such as those of COVID in 2020), new highs continue to be recorded to the right of the red line.
At the end of evolution, we can display the swarm of the best organisms per generation in relation to the Buy & Hold curve.
What is evident is that we are dealing with DNA within very similar genetic families that, although they cannot outperform the Buy & Hold in terms of returns, are able to beat it in terms of expected risk. To confirm this initial “qualitative” analysis, let’s provide some details about the best organisms determined in the training period.
The “robustness” column indicates the metric’s ability to hold between In Sample and Out of Sample. What is evident is that from the very first generations, it is possible to obtain robust organisms, albeit less performant, as they are less specialized.
The evolution curve, with its erratic shape typical of using the Instability Factor, moves in macro-levels in a dynamic reminiscent of electron orbitals.
At the end of the process, the best organisms are capable of generating a profit 100 times greater than the average drawdown.
In conclusion, let’s analyze in more detail some of the best genetically validated individuals.
Organism 7 stands the test of time and appears capable of mitigating periods of distress (2008, 2020) at the cost of a degradation in profit compared to the benchmark curve. Below is the comparison of drawdowns: first, that of the Buy & Hold strategy.
Subsequently, the genetic drawdown.
Organism 800 has the following profile instead.
The dynamics suggest that the machine has intercepted a specific genetic family and has started to work on the details while preserving robustness with the help of the Instability Factor.
What we have seen (here, for demonstration purposes only) still does not answer all the questions. For example, the selection of the best genetic investors after analyzing the Out of Sample area distorts that interval due to (once again) Selection Bias. I will try to answer this and other questions during my next speech in Jakarta. It is still possible to purchase tickets to attend in person, alongside many speakers from around the world (you can find the complete program and additional details here).
See you in Indonesia!
Founder – Head of R&D