Click here to Login





                                                   Custom Multi-Dimensional Fitness Formula (CMDFF) for Optimizer

Back to threads - Tags: --
  1

0
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;



clonex
2012-03-23 13:18:23

  0

Excellent, thank you!

I was using this:

double factor1 = 1.5*SharpeRatio;
double factor2 = 0.5*AnnualReturn;
double factor = (factor1*factor2);
Fitness = factor;

or this:


double factor = 1;
if(NumberOfTrades > 10)
factor = 1.1;
else if(NumberOfTrades > 20)
factor = 1.2;
else if(NumberOfTrades > 50)
factor = 1.3;

 
Fitness = factor * SharpeRatio;



Mike
2012-03-26 06:09:54

  0

Well done. I have to say that this a very powerful script.

Any improvements you have seen in the simulation results produced by the AI Optimizer?

To all:
With few modifications, this script can also be used with the list of rules, ranking system and prediction model optimizers.



SystemTra.de
2012-03-30 02:36:05

  0

@ Mike

Thank you! Yes, I have seen improvements, but according to the nature of the formula, not so much with the absolute return but with the stability of the return over time.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
History of dividend payment for stocks in the US stock market
Lagged Data From a Custom Database
Black-Scholes Option Pricing Model formula
News data for US companies from Google RSS feed
Valuation ratios for US stocks

How-to Lessons
How to create a custom trendline
How to download earnings calendar data for various stocks
How to get fundamental data for U.S. Stocks
How to add custom position-based metrics to your trading system
How to use a custom drawing tool

Related Forum Threads
Best way to precompute a custom formula and store it
How do I find the close price for an entry matching a custom DB
Guru, formula for line cross
Chart for 1m bars over a custom time range
Formula for Full Stochastic?

Blog Posts
Create custom metrics for the statistical data analysis tool
How to Create Custom Metrics for Your Trading Positions
How to Backtest Your Trading System for Each Industry
Trading System Analysis: Backtesting report and custom measures
Custom Indicator: Accumulation Distribution Line









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2012 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items