 |
SystemTra.de
2012-03-23 05:25:37
|
|
Probably you have made similar experiences while optimizing your trading system: the optimizer throws excellent results (e.g. on the fitness function "AnnualReturn") but the system drawdown is too bad or the number of trades is below statistical significance and so on.
I was thinking of a customizable fitness function that allows more than one parameter, because what we are all looking for is a trading system with e.g. high annual return, low drawdown and high Sharpe Ratio.
Below I will share a C#-script with you, you can just copy it to your fitness formula editor (don't forget to set the compiler to C#). I would appreciate your feedback once you have tested it.
This is the idea behind and the assumptions for the example:
You would weigh the output of your trading system by Annual Return, Maximum System Drawdown in % and by the Sharpe Ratio.
You would weigh Annual Return and Maximum System Drawdown in % equally and Sharpe Ratio is only half important for you.
You expect a minimum annual return of 0% from your trading system and a value above 30% would be perfect.
Maximum System Drawdown shall not be above 30% and anything below 10% would be your optimum.
The Sharpe Ratio shall not be below 0.5 and you do not expect more than 2.
And finally the minimum number of trades generated by your system shall be 100.
In the script it looks like:
bool ok = NumberOfTrades >= 100;
only if the ok variable is true, the function will calculate the other parameters, you can change to whatever rule you need, if you don't need it, just change to "bool ok = true"
double[] parameters = {AnnualReturn, MaximumSystemDrawdownInpercentage, SharpeRatio};
list the parameters you want to include in your fitness function here
double[] weight = {10, 10, 5};
specify your weighing factors, the total does not have to be 100
double[] worst_value = {0, -30, 0.5};
list the worst values you expect from your parameters here, note that the output of MaximumSystemDrawdownInpercentage has a negative sign
double[] best_value = {30, -10, 2};
list the best values you expect from your parameters here, note that the output of MaximumSystemDrawdownInpercentage has a negative sign
The output of the fitness function will be normalized between 0 and 100 and can be interpreted as follows:
A result of 0 means that either the number of trades is below 100 or none of the 3 minimum parameters is fulfilled.
A result of 100 means, that the number of trades is above or equal 100 and all of the 3 parameters are above maximum value.
A number between 0 and 100 indicates the comfort level with your parameters and weighing factors.
Note that the number of dimensions of the fitness formula is not limited, you can add or remove according to your needs, but in any case make sure that the number of dimensions in the arrays "parameters", "weight", "worst_value" and "best_value" is always the same.
And here is the script, enjoy!
// -------------- C# ------------------
// ---------- define your fitness parameters here ----------
bool ok = NumberOfTrades >= 100;
double[] parameters = {AnnualReturn, MaximumSystemDrawdownInpercentage, SharpeRatio};
double[] weight = {10, 10, 5};
double[] worst_value = {0, -30, 0.5};
double[] best_value = {30, -10, 2};
// ---------- end of parameterization ----------
double fit_param = 0;
double total_weight = 0;
if (ok)
{
for (int i = 0; i < parameters.Length; i++)
{
total_weight = total_weight + weight[i];
if (best_value[i] != worst_value[i])
fit_param = fit_param + weight[i] *
(Math.Max(Math.Min(parameters[i], best_value[i]), worst_value[i]) - worst_value[i]) /
(best_value[i] - worst_value[i]);
}
if (total_weight != 0) Fitness = 100 * fit_param / total_weight; else Fitness = 0;
}
else
Fitness = 0;
|
|