Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Genetic Optimizer Needs to be Penalized

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Genetic Optimizer Needs to be Penalized

    If you run the GO on, say, 1 min bars, and then use a range of 2;20;1 for the variable length of e.g. EMAs of lows and highs with trailstops calculated within the indicator, and then set a variable delta of price range of say 0.01;5;0.01 to execute trades if the stops are breached, the GO will simply make 1 trade if the asset did nothing but go up over the entire period used (1 month). For example, say that on day 1 the price was $50, and on day 30 it was $80 (price went up $1 every day), the GO will simply select an EMA period and price delta to make 1 trade, since it can see that it doesn't need to trade every day -- it recognizes the price went up straight over the 30-day period, and then makes 1 long entry on day 1 and an exit on day 30.

    However, using other trading platforms with the same 1 min bars, asset, ranges of parameters, their GO penalizes for doing this and also yields about 10x better net profit and +20-30% winner percentage for dozens of more trades. Based on your GO applied to an intra-day chart, the results are not intraday trading -- more like you need to trade monthly bars. So can you check with your GO developers and ask them why the GO does not penalize for this, while GO's in other platforms don't do this at all?

    Couple other things:

    You should probably set the default generations to 25, and population size to 100 chromosomes, with a mutation rate of 5%. The default settings essentially don't harness the power of genetic algorithms since the # generations and population size are too small.

    Also, do you offer anything that will assist in finding a better ranges of input values, given that your GO doesn't penalize? With your GO, I have to shorten everything and play around with different input parameter ranges.

    Last, can I watch fitness as a function of generation? If I can't see winner% or net profit increase with increasing generations, there is no way to judge if the parameters are getting better.
    Last edited by pel11; 06-22-2018, 11:31 AM.

    #2
    Hello pel11,

    Thanks for your post.

    I'll be happy to put in a feature request for adding a penalty function to the Genetic Optimizer as well as your suggestion to change the default parameters.

    So we can better note this for the development team to look into, could you provide a screenshot of a backtest using a penalty function in another trading platform?

    As for finding better ranges of input values, I could not point out a behavior that would provide different ranges outside of comparing tests with normal optimization backtests that test a full range of variables.

    For your final question, I am not aware of a way to sort each generations performance in a backtest's results. We could submit this as a suggestion however.

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jim; 06-26-2018, 07:26 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Probably send this to the genetic algorithm (GA) developers:

      Assume:

      1. you are running the Strategy Optimizer on 5 days of 1-minute bars (daytime sessions).
      2. also assume that the price return (e.g., Close) of the asset (future, forex, stock) went up straight every day almost forming a straight line over all the 1-minute bars.

      Problem: (which is what I noticed with the GA optimizer):

      When using a custom indicator (strategy) to determine programmed trailing stops on the Lows and Highs, if the range in NT8 is for example 5;30;1 in the strategy optimizer, for this type of stock only 1 trade will be made with an entry the morning of the first day, and an exit near the close of session on the last day.

      This is because of the fitness function, and the fact that the GA noticed only 1 trade needed to be made. I do not see this in Amibroker's optimizer (particle swarm optimization) or in Wealth Labs GA optimizer. Instead it seems these other GA's are going down in the "weeds" and looking for more trades.

      What could be done is to penalize for a low number of trades or too many trades, but it requires that the user has an option called "Reward for #trades: ".

      Say I optimized with another platform and obtained very a profitable daily profit factor (or cum net profit) which resulted in about 5 trades per day, or 25 trades for the 5 days. Either that, or a user wants to reward the GA for 25 trades over 5 days. The user would enter 25, and then your code would do the following:

      Let:

      t = iteration in optimizer run
      d = the number of trades desired, to reward over the backtest period
      n(t) = #trades made by optimizer during iteration t
      x(t) = -3+(n(t) -1)*6/d (intermediate number, actually a standard normal variate)

      the weight for iteration t is then

      w(t) = 1/sqrt(2*Math.Pi) * Math.Exp(-0.5*x(t)^2)

      A plot of w(t) as a function of the #trades the optimizer makes per iteration for 25 desired trades is attached. w(t) should be multiplied by the value of the GA fitness function for iteration t.

      Recall, the other GA optimizers I use do not make 1 trade when very long periods are in the range of the parameters, but the NT8 GA seems to bite on the single trade. So they are doing something to penalize for a low number of trades.
      Attached Files
      Last edited by pel11; 06-25-2018, 03:55 PM.

      Comment


        #4
        Thanks pel11,

        That information helps. I have included this with the a feature request for a penalty function.

        Here are the ticket ID's for the feature requests submitted.
        • SFT-3313 Penalty function for Genetic Optimizer
        • SFT-3314 Ability to sort GO backtest results by generation number
        • SFT-3315 Request for new default GO properties


        Feature request interest is aggregated before it is determined if the feature should be implemented, so we can't offer an ETA. Upon implementation, the number for the ticket IDs can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

        Release Notes: https://ninjatrader.com/support/help...ease_notes.htm

        If there is anything else we can do to help, please let us know.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Today, 09:43 PM
        0 responses
        4 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        36 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        44 views
        0 likes
        Last Post bill2023  
        Started by yertle, Today, 08:38 AM
        6 responses
        26 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        24 views
        0 likes
        Last Post algospoke  
        Working...
        X