Wow, I enjoyed replicating this neatly written paper by Ronald Hochreiter.

Ronald is an Assistant Professor at the Vienna University of Economics and Business (Institute for Statistics and Mathematics).

In his paper he applies **evolutionary optimization** techniques to compute optimal **rule-based trading strategies** based on **financial sentiment data**.

- Title: Computing trading strategies based on financial sentiment data using evolutionary optimization
- Author: Ronald Hochreiter
- Book: Mendel 2015, Recent Advances in Soft Computing,

The series “Advances in Intelligent Systems and Computing”, Volume 378 2015, Springer - Sources: doi: http://dx.doi.org/10.1007/978-3-319-19824-8_15

http://arxiv.org/pdf/1504.02972v1.pdf

The evolutionary technique is a general **Genetic Algorithm (GA). **

The GA is a mathematical optimization algorithm drawing inspiration from the processes of ** biological evolution **to breed solutions to problems. Each member of the population (

**) encodes a solution (**

*genotype***) to the problem. Evolution in the population of encodings is simulated by means of evolutionary processes;**

*phenotype**.*

**selection**,**crossover**and**mutation**Selection exploits information in the current population, concentrating interest on high-fitness solutions. Crossover and mutation perturb these solutions in an attempt to uncover better solutions. Mutation does this by introducing new gene values into the population, while crossover allows the recombination of fragments of existing solutions to create new ones.

After reading Ronald’s paper I immediately wanted to test the hypothesis that the model is good at predicting the 1-day ahead direction of returns. For example, when the rule determines to go long, are the next day returns positive and when the rule determines to exit the long position or stay flat, are the next day returns negative. The results are not much better than a flip of a coin (see the results in the attachment below). Also, turnover is high (see the plot) which may warrant the strategy useless.

However, many variations on this genetic algorithm exist; different *selection* and *mutation* operators could be tested and a *crossover* operator could be added. Instead of using financial sentiment data a variety of **technical indicators** could be used for generating an optimal trading rule – *e.g. see “Evolving Trading Rule-Based Policies“.*

I emailed Ronald to get clarification regarding several questions I had. He kindly and swiftly responded with appropriate answers.

- No crossover is used as the chromosome is too short.
- The target return for the Markowitz portfolio is calculated as the mean of the scenario means, i.e. mean of the mean vector.
- Pyramiding is not considered. The rule just checks whether we are invested (long) in the asset or not.
- A maximum number of iterations is specified as the stopping rule.

Like my earlier post, End-of-Day (EOD) stock prices are sourced from QuoteMedia through Quandl’s premium subscription and the StockTwits data is sourced from PsychSignal.

The following comparisons and portfolios were constructed:

- In-Sample single stock results – Long-only buy-and-hold strategy vs. Optimal rule-based trading strategy
- Out-of-Sample Buy-and-hold optimal Markowitz portfolio
- Out-of-Sample Buy-and-hold 1-over-N portfolio
- Out-of-Sample Equally weighted portfolio of the single investment evolutionary strategies

I used R packages **quadprog **and **PerformanceAnalytics **but I wrote my own Genetic Algorithm. I’ll continue using this algorithm to evaluate other *indicators*, *signals* and *rules* 🙂

Here’s some code with the results. The evolutionary risk metrics (pg. 11) are not as good as those in the original paper (I used 100 *generations *for my GA) but as you can see, my output is almost identical to Ronald’s. A *clone* perhaps – hehe.

*If you have a specific paper or strategy that you would like replicated, either for viewing publically or for private use, please contact me.*