Click here to Login





                                                   Minium number of trades per year in fitness formula is not working?

  0

0
Christian
2018-09-03 14:00:00


I am using the fitness formula from SystemTra.de and I made a small modification on the number or trades. line.
I replaced the fixed value of trades with the formula YearlyReturn.Count * 25, but that formula is not working.
Could somebody tell me, whats wrong on that coding line?



bool ok = NumberOfTrades >= YearlyReturn.Count * 25;
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;



QuantShare
2018-09-03 17:51:55

  0

You are comparing number of trades with Yearly return. That is of course not correct.


Christian
2018-09-04 03:35:43

  0

Let me describe the problem more detail, maybe you know a different way to solve.
On the optimizer you can only use one fitness formula for the in sample and out of sample tests.
Normally I make 80% in sample and 20% out of sample test and often I got not enough trades on the out of sample test.
With my formula, I want to count the years and multiplicate it with 25 trades per year.
For example, I have 10 years data and 80% for the in sample test (8 years) and two years for the out of sample test (2 years).
So I need minimum 200 trades for the in sample and 50 trades for the out of sample test.
If I use the fixed value of 200 trades I often get no results on the out of sample test, because there are not so much trades.
Now I was thinking that formula [YearlyReturn.Count] count the years of the test period and I must only multiplicated with 25.

On a other thread I found your fitness formula:
bool posYears = true
for(int i=0;i < YearlyReturn.Count;i++)
{
if(YearlyReturn[i] < 0)
{
posYears = false;
break;
}
}
if(posYears)
{
Fitness = AnnualReturn;
}
else
{
Fitness = double.NaN;
}

That formula is also using the same statement to control the loop?



QuantShare
2018-09-07 08:27:42

  0

I see. That formula is trying to detect whether there is was one year with negative return. If yes then return Nan, otherwise return the AnnualReturn.



Christian
2018-09-07 12:18:40

  0

Now we know, with that statemend we got the years of the simulation, but why is my reduced formula not working?
I tried it agein with an extra variable, but it's also not working, see here:

double vMinTrades = YearlyReturn.Count * 25; // Minimum trades per year
bool ok = NumberOfTrades >= vMinTrades; // Eenought trades?
if (ok)
{
Fitness = SharpeRatio; //or something else // If yes, set the fitness value
}
else
Fitness = 0;



SystemTrade
2018-09-07 14:27:06

  0

I just checked your formula (the last one you posted today) - it works! - so the problem must be somewhere else.
Periods can be set in the trading system and in the optimizer as well, please check if they are the same. What happens if you just put Fitness=YearlyReturn.Count without the "ok" logic? Will the result be the number of years in your trading system?


Off topic: pls expect an answer to your email some time next week



Christian
2018-09-07 15:19:38

  0

Now I have adjusted the optimizer from 01.Jan.2000 to 31.Dez.2014 and I have modified the formula, see here:

double vMinTrades = YearlyReturn.Count * 25;
OptimizerMetrics.AddMetric("Years",YearlyReturn.Count);
Fitness = vMinTrades ;

Now I got the following results, on the fitness column 350 and on the year column 15
The calculation is more or less correct (one year to much), but if I use the "OK" logic it is not working anymore.
I am getting trading systems with lower amount of trades?



Christian
2018-09-12 13:28:18

  0

Now it's working, thank you :)


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
Average Output Per Year
Number of Potential Splits per Trading Day
Number of dividend payments per day in the U.S. Stock Market
Number of Stocks per Industry
Number of IPOs per Day - Trading Composite

How-to Lessons
How to plot the number of stock tweets per day
How to display the number of notes per stock
How to display the number of stocks per day for different RSI gro...
How to add trades from one portfolio to another one
How to import trades into a portfolio

Related Forum Threads
Custom Multi-Dimensional Fitness Formula (CMDFF) for Optimizer
Backtest from a chart not resulting in any trades
Why is this not working?
% Annual Return per Year
Add Skipped Trades Due to Margin Constraints to Trade Log

Blog Posts
Programming skills are not that important
Working with the formula editor
Trading System Analysis: Backtesting report and custom measures
Trading System: Buy Stocks based on their Sharpe Ratio Rank
Sharpe Ratio - Part 1









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 © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.