NexusFi: Find Your Edge


Home Menu

 





System Optimization Fitness Functions


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one fluxsmith with 7 posts (11 thanks)
    2. looks_two Trader.Jon with 4 posts (1 thanks)
    3. looks_3 gordo with 3 posts (5 thanks)
    4. looks_4 flyscalper with 2 posts (0 thanks)
      Best Posters
    1. looks_one pakricard with 2 thanks per post
    2. looks_two gordo with 1.7 thanks per post
    3. looks_3 fluxsmith with 1.6 thanks per post
    4. looks_4 baruchs with 1.5 thanks per post
    1. trending_up 15,830 views
    2. thumb_up 27 thanks given
    3. group 10 followers
    1. forum 27 posts
    2. attach_file 4 attachments




 
Search this Thread

System Optimization Fitness Functions

  #1 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322

My hope in starting this thread is that others will share their preferred fitness functions, that together we may come up with a better function. I know Big Mike has one I've never seen posted (hint), hopefully others also have ideas we can share in this area.

Here is mine at the moment (NT7), I would characterize it as a conservative variant of Van Tharp's System Quality Number:
 
Code
public override double GetPerformanceValue(SystemPerformance systemPerformance)
{
 // Normalize number of trades to one year
 int numTradesYear = (int)(systemPerformance.AllTrades.TradesPerformance.TradesPerDay * 365.0);
 
 
 // If it doesn't even trade once a week it isn't interesting to me
 if ( numTradesYear < 50 )
    return double.MinValue;
 
 
 // If it hasn't ever lost it is either unrealistic or doesn't have enough samples
 if ( systemPerformance.AllTrades.LosingTrades.Count == 0 )
    return double.MinValue;
 
 
 // Determine average profit with best outlier removed
 int numTrades = systemPerformance.AllTrades.Count - 1;
 double avgProfit = (systemPerformance.AllTrades.TradesPerformance.Currency.CumProfit - systemPerformance.AllTrades.TradesPerformance.Currency.LargestWinner) / numTrades;
 
 return Math.Sqrt(numTradesYear) * avgProfit / Math.Max(systemPerformance.AllTrades.TradesPerformance.Currency.StdDev, avgProfit * .20);
}

Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
Battlestations: Show us your trading desks!
26 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
17 thanks
  #3 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


Hi,
I don't know if there is something called the best "fitness function".
The fitness function that I use gives the best results for the tested data.
It is - Net Profit divided by minus Draw Down. This gives you the best result PERIOD!
But what we are looking for is not the best result for the tested data, but the better predictor for future data.
As I always say optimization is worthless. The only allowed action is walk forward.

Baruch

Reply With Quote
  #4 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322


baruchs View Post
...Net Profit divided by minus Draw Down. This gives you the best result PERIOD!...

Thank you for responding. In my function I found if I don't impute some variance it greatly favored parameters that claim little or no variance (or drawdown), but only take a couple of ticks per trade. I can imagine the same problem with drawdown as a divisor, do you impute a threshold level of drawdown in your calculation?

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

No I don't.
If you find a setup with Zero draw down you found a holy grail!!
Comparing two setups the best is with higher NP/DD

Baruch

Reply With Quote
  #6 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


baruchs View Post
Hi,
I don't know if there is something called the best "fitness function".
The fitness function that I use gives the best results for the tested data.
It is - Net Profit divided by minus Draw Down. This gives you the best result PERIOD!
But what we are looking for is not the best result for the tested data, but the better predictor for future data.
As I always say optimization is worthless. The only allowed action is walk forward.

Baruch

I have a high degree of agreement with the walk forward. My gut feeling there is to do a default opt on a challenging month (ie periods of both high and low volatility, both bulls and bears getting greedy, and then use the best results are midpoints for the genetic optimization walk forward: 7 days test 1 day walk and then repeat.

Can you post your 'fitness function'? It would be very helpful to me to see the actual code.

TIA!
Jon

Reply With Quote
  #7 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322

I'm still trying to find the ideal fitness function. Net Profit / Drawdown as suggested here previously doesn't do it for me, as that ignores consistency and unrealized risk. The attached is the best I've come up with so far. For me the goal is to have a function that will sort to the top the same parameters I would select by hand based on visual analysis of the cumulative profit graph, which ideally would be a smooth progression from bottom left to top right; and when otherwise comparable preferring the smallest stops.

Attached Files
Elite Membership required to download: Quality3.cs
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #8 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


fluxsmith View Post
I'm still trying to find the ideal fitness function. Net Profit / Drawdown as suggested here previously doesn't do it for me, as that ignores consistency and unrealized risk. The attached is the best I've come up with so far. For me the goal is to have a function that will sort to the top the same parameters I would select by hand based on visual analysis of the cumulative profit graph, which ideally would be a smooth progression from bottom left to top right; and when otherwise comparable preferring the smallest stops.

fluxsmith,

I very much appreciate the analysis, and your sharing it with us ... I am a believer in removing those pesky outliers, as you have done in your code, and that leaves me confused as to the reasons for the different values used in the multiples (*.20 vs. *.382 ,to me, is huge for 1 trade difference). I am sure there is a good reasom, that is why I am asking to be educated, and as it wasnt included in the .cs :

.... this from Quality3.cs ... (.382)
// Determine average adusted profit
int numTrades = systemPerformance.AllTrades.Count;
double avgProfit = profit / numTrades;

return Math.Sqrt(numTradesYear) * avgProfit / Math.Max(systemPerformance.AllTrades.TradesPerformance.Currency.StdDev, avgProfit * .382);

compared to the original post ... (.20)
// Determine average profit with best outlier removed
int numTrades = systemPerformance.AllTrades.Count - 1;
double avgProfit = (systemPerformance.AllTrades.TradesPerformance.Currency.CumProfit - systemPerformance.AllTrades.TradesPerformance.Currency.LargestWinner) / numTrades;

return Math.Sqrt(numTradesYear) * avgProfit / Math.Max(systemPerformance.AllTrades.TradesPerformance.Currency.StdDev, avgProfit * .20);

TIA!
Jon

Reply With Quote
  #9 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322

Experimentally I found .20 wasn't high enough, I settled on .382 as being representative of one standard deviation. What I'm doing there is imputing a minimum variance I'll accept for use in the calculation. Without that I found it gave too much preference to parameters that had low deviation only because they had minimal profit targets.

Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:
  #10 (permalink)
 flyscalper 
Barcelona, Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: Futures
Posts: 24 since Jul 2009
Thanks Given: 35
Thanks Received: 7


Hello,

I would like to get an optimization type as a Calmar Ratio: Annual Profit / DD max, but the problem is that I do not know how to compute the Annual Profit with the systemPerformance variables.

Un saludo,

Pablo

Reply With Quote




Last Updated on April 29, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts