# 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...

-

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.

-
Thank you. Could you please give an example for a trading rule (e.g. moving average) and its mathematical encoding. – vonjd Mar 2 '11 at 12:27
make a function like this: MA(int numdaysavg){return sum(x[i] thru x[i-numdaysavg] / numdaysavg} then use the results of this function over time, [a time series] along with a time series of returns or prices... (this wouldn't be much of a factor model because you only have one factor (moving avg). You can add as many as you like from there. – glyphard Mar 2 '11 at 13:46

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%.

-

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!

-
@user40: Thank you, in fact this was my original reference. Could you give me some ideas or references how to encode trading rules within the alphabet of GP? – vonjd Mar 8 '11 at 19:48