Skip to content
All library documents

Encoding Trading Rules with Factor Models and Genetic Programming

Article Quant Q&A · Author: vonjd

Summary

The document surveys ways to turn trading signals into mathematical strategy rules. One suggestion is to combine implemented signals in a factor model and estimate coefficients, which can produce a fitted formula and measures of statistical fit. The response warns that selecting a strategy by historical fit risks data-snooping bias, and argues that economic reasoning matters because apparently effective patterns may not persist.

For cases where the structure of the rule itself is unknown, another response proposes genetic programming. In this approach, available indicators and operations form a vocabulary and grammar, and an evolutionary search develops candidate programs over generations. The document also points to a simple example rule and describes a research paper that evolves portfolio choices and investment signals using technical, fundamental, and macroeconomic inputs. The cited paper reports experiments on European equities and comparisons with other approaches, but the document supplies no details sufficient to assess robustness or reproduce the results. The methods require careful out-of-sample evaluation to limit overfitting.

Key ideas

  • Factor models can combine trading signals into a formula with estimated coefficients and statistical fit measures.
  • Searching many candidate signals against historical data creates data-snooping risk.
  • Genetic programming can search for strategy structures by evolving programs built from available variables and rules.
  • A cited portfolio method combines technical, fundamental, and macroeconomic analyses in a staged process.
  • Historical performance claims need independent validation and out-of-sample checks.

Tags

Full text
# How to encode trading strategies mathematically


# How to encode trading strategies mathematically












If you have a bunch of different econometric data (e.g. indexes, FX, commodities, interest rates...) you can try to find a formula to see if there is any relationship in the data - e.g. to forecast it by this discovered pattern.

What I am asking here is a little bit different: Is there another way in the sense that you can search for a formula f() such that the given form represents a trading strategy where certain indicators are found when to go long or short (or any derivative combinations)? The idea is that the formula itself lives in n-dimensional space of indicators/ trading-strategies and tries to survive as best as it can.

This must be a standard procedure for multi-agent systems simulating artificial stock markets. Alas, I am unable to find a simple approach to do just that...

## Answer by glyphard (score 12, accepted)

https://quant.stackexchange.com/a/633

Yes, you use an implementation of each signal and then use a statistical package like sas to generate a factor model for you. It generates a mathematical formula, with coefficients, and signals(variables) and even tells you the efficacy(R^2)

However you quickly find yourself exposed to data snooping bias by choosing this approach. Similar to the results outlined in this paper: http://www.eco.sdu.edu.cn/jrtzx/uploadfile/pdf/empiricalfinance/10.pdf

Data-snooping bias, is why people stress the economic reasoning for their strategies over the historic statistical efficacy, which often fails to replicate going forward.

## Answer by user40 (score 6)

https://quant.stackexchange.com/a/665

Maybe I completely misunderstood the question, but it seems to me that you are looking to find a model structure as opposed to fit a specified/known model. In your context the model specification (the trading rules) are unknown... Am I right?

If that Is the case, maybe genetic programming:

http://en.wikipedia.org/wiki/Genetic_programming

Is what you need?

In a nutshell, it is a sub-class of GA which applies evolutionary approach for finding a model structure (a program) which is most fit... Throughout generations of evolutionary improvements.

My guess is that a language dictionary in this case is a set of constructs (variables) you have at your disposal, and the language grammar are the rules...

Just a thought!

Btw. Good Question!

## Answer by Owe Jessen (score 3)

https://quant.stackexchange.com/a/674

Here is an example of the 75% trading rule coded in R: Can one beat the random walk

This is how the author describes the rule:

> The following script will generate a random series of data and follow the so called 75% rule which says, Pr[Price>Price(n-1) & Pr<(n-1) < Price_median] Or [Price < Price(n-1) & Price(n-1) > Price_median] = 75%.

## Answer by vonjd (score 2)

https://quant.stackexchange.com/a/37573

There is a new paper "A meta-grammatical evolutionary process for portfolio selection and trading" which evolves trading strategies with genetic algorithms (unfortunately behind a paywall):

Contreras, I., Hidalgo, J.I., Nuñez-Letamendía, L. et al. Genet Program Evolvable Mach (2017) 18: 411. https://doi.org/10.1007/s10710-017-9304-1

Abstract This study presents the implementation of an automated trading system that uses three critical analyses to determine time-decisions and portfolios for investment. The approach is based on a meta-grammatical evolution methodology that combines technical, fundamental and macroeconomic analysis on a hybrid top-down paradigm. First, the method provides a low-risk portfolio by analyzing countries and industries. Next, aiming to focus on the most robust companies, the system filters the portfolio by analyzing their economic variables. Finally, the system analyzes prices and volumes to optimize investment decisions during a given period. System validation involves a series of experiments in the European financial markets, which are reflected with a data set of over nine hundred companies. The final solutions have been compared with static strategies and other evolutionary implementations and the results show the effectiveness of the proposal.

In the paper two grammars are being used to encode trading strategies (in BNF):

One to encode a portfolio of companies:

The other to encode investment signals over a specific period:

More details can be found in the paper.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.