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):
Oggi desidero approfondire l’utilizzo degli algoritmi evolutivi (degli algoritmi genetici in particolare), al servizio dell’asset management. L’esempio che utilizzerò vuole essere un omaggio agli amici e colleghi dell’AATI (Asosiasi Analis Teknikal Indonesia) e di IFTA (International Federation of Technical Analysts) più in generale. Siamo infatti a tre settimane dall’inizio dell’IFTA International Conference 2023, che si terrà a Jakarta, per la prima volta in Indonesia (potete leggere tutti i dettagli qui). L’articolo è una seconda anticipazione di ciò che avrò l’onore di presentare in quell’occasione.
Iniziamo elencando un primo insieme di azioni ad elevata capitalizzazione quotate all borsa di Jakarta (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.
Per costruire una base statistica sufficiente, tra questi abbiamo isolato quei titoli i cui storici contengano almeno vent’anni di record giornalieri. Si potrebbe obiettare (a ragione) che questo tipo di selezione ricada nel rischio di “Selection Bias”, ma per puri fini dimostrativi utilizzeremo comunque questo primo approccio grossolano.
[“BBCA.JK”,”ASII.JK”,”BBRI.JK”,”TLKM.JK”,”BMRI.JK”,”UNVR.JK”,”INDF.JK”,”BBNI.JK”,”GGRM.JK”,”HMSP.JK”,”BN.JK”,”UNTR.JK”,”ICBP.JK”,”BNGA.JK”,”KLBF.JK”,”PGAS.JK”]
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.
L’idea è quella di costruire un motore genetico che, a partire da uno specifico “Genetic Pool”, generi un DNA capace di discriminare gli asset da acquistare su base periodica.

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.
Immaginiamo di utilizzare dati daily (“period”) e di muoverci su base settimanale (“trigger”). Determiniamo la regola che ottimizzi una determinata “Fitness Function” (ad esempio lo Sharpe Ratio od il Kestner Ratio) su un periodo di addestramento “In Sample” e verifichiamo cosa accada su dati sconosciuti “Out of Sample”. Durante lo speech di Jakarta approfondiremo come sia più opportuno costruire tale architettura di validazione.
La prima settimana la macchina allocherà il proprio denaro sugli asset 1,2,5 (che terrà fino al termine della settimana), la seconda settimana sugli asset 2,3,4,6, la terza sugli asset 1,3,5,6 e così via. La curva di portafoglio risultante, cui possiamo imputare anche dei costi fissi opportuni, verrà confrontato con una strategia Buy & Hold in cui venga acquistato l’intero basket per l’intero periodo.
Tornando al Pool Genetico in questo esempio stiamo utilizzando 48900 regole elementari.

An example of a rule (gene) that we have used is the following:
Un esempio di regola (gene) che abbiamo utilizzato è la seguente:
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%.
che possiamo interpretare come “la media a 10 variazioni percentuali giornaliere misurata due giorni fa sia maggiore della media a 10 variazioni percentuali giornaliere misurata tre giorni fa”. Ulteriori dettagli sul pool genetico e sulla ricombinazione delle regole verranno forniti all’IFTA Conference e all’interno dell’acceleratore didattico “Machine Learning Academy” (per adesso fruibile soltanto in lingua italiana, qui i dettagli).
I parametri di progetto, che non seguono l’approccio darwiniano, come riportati nella figura seguente, caratterizzano una popolazione di 10 individui per 1000 generazioni (per un totale di 10000 individui totali in competizione tra di loro), un DNA composto da 3 geni ciascuno, un 30% di migliori individui da salvare per ciascuna generazione, un 30% prodotti dal solo crossover, una probabilità di mutazione del 20% (piuttosto elevata in questo test), una fitness function data dal rapporto tra profit e drawdown medio ed un instability factor del 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.
Il miglior individuo della prima generazione è un organismo dall’equity piuttosto regolare (nel periodo di addestramento alla sinistra della linea verticale rossa, che separa In Sample ed Out of Sample) che perdura in termini di pendenza e varianza nel periodo successivo.

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”.
Dopo poche generazioni aumentano le prestazioni in In Sample (ad eccezione dell’estremizzazione del drawdown del periodo 2008-2009), ma l’algoritmo non sembra più in grado di portare profitto su dati sconosciuti. In un modello di validazione multi-dimensionale, possiamo ipotizzare di essere usciti dalla “Fascia di Persistenza”.

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.
Oltre 400 generazioni dopo, osserviamo un miglioramento della metrica di evoluzione (al costo di una riduzione del rendimento in In Sample) ed il recupero di un massimo di equity line in 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.
In generazione 750 la curva si addolcisce ulteriormente e, nonostante non sembri esserci la capacità di evitare fattori esogeni (come quelli del covid nel 2020) si continuano a registrare nuovi massimi a destra della linea rossa.

At the end of evolution, we can display the swarm of the best organisms per generation in relation to the Buy & Hold curve.
Al termine dell’evoluzione possiamo mostrare lo sciame dei migliori organismi per generazione in rapporto alla curva di Buy & Hold.

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.
Quello che si evince è che siamo di fronte a DNA compresi in famiglie genetiche molto simili che, seppur non riescano a superare il Buy & Hold in termini di rendimento, riescono invece a batterlo in termini di rischio atteso. Per confermare questa prima analisi “qualitativa” diamo un pò di dettaglio ai migliori organismi determinati nel periodo di addestramento.

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.
La colonna “robustness” indica la capacità di tenuta metrica tra In Sample ed Out of Sample. Quello che si evince è come già dalle primissime generazioni sia possibile ottenere organismi robusti, se pur meno performanti, in quanto meno specializzati.
La curva di evoluzione, con la sua conformazione erratica, tipica dell’utilizzo dell’Instability Factor, si muove per macro-livelli in una dinamica che ricorda gli orbitali degli elettroni.

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.
Al termine del processo gli organismi migliori sono in grado di generare un profitto 100 volte superiore al drawdown medio.
Per concludere analizziamo più in dettaglio alcuni dei migliori individui genetici validati.

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.
L’organismo 7 tiene alla prova del tempo e sembra in grado di lenire le fasi di sofferenza (2008,2020) al prezzo di un degrado del profitto rispetto alla curva di benchmark. Di seguito invece il confronto sul drawdown: dapprima quello relativo alla strategia Buy & Hold.

Subsequently, the genetic drawdown.
Successivamente quello genetico.

Organism 800 has the following profile instead.
L’organismo 800 ha invece il seguente profilo.

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!
La dinamica fa pensare che la macchina abbia intercettato una specifica famiglia genetica e abbia iniziato a lavorare sui dettagli preservando la robustezza grazie all’ausilio dell’Instability Factor.
Quello che abbiamo visto (qui solo a scopo dimostrativo) non risponde ancora a tutte le domande: ad esempio la selezione dei migliori investitori genetici a valle dell’analisi della zona di Out of Sample, snatura tale intervallo a causa (ancora una volta) del Selection Bias. A questo e ad altri quesiti proverò a rispondere durante il mio prossimo speech a Jakarta. È ancora possibile acquistare i biglietti per partecipare di persona, insieme a molti relatori provenienti da tutto il mondo (potete trovare il programma completo e ulteriori dettagli qui).
Ci vediamo in Indonesia!
Giovanni Trombetta
Founder – Head of R&D
Gandalf Project