Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Genetic Optimizer

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

    Genetic Optimizer

    Here's the first public version of my genetic optimizer for NT. I've published some documentation here: http://www.ov-trading.com/geneticoptimizer

    There are some issues I know about, including:
    1. If you have any non-int or -double params this will break
    2. Somehow an extra 0-byte file is getting created if you use the GASaveAll option
    3. If you use very small population sizes the random number generation doesn't work right

    and I'm sure others I don't, but I've been using this myself for about 1 1/2 months now and it's really opened up possibilities of what I can do. If you're going to use this, please read the documentation carefully once before getting started.

    I have not tested this on futures or forex at all. I don't know of any reason why it won't work, but I haven't tried it.

    I am not an expert in programming GA algorithms by any stretch. What I used I learned from various web sites & hacking the code.

    Update: you need to download both of these files if you are going to use this.
    Attached Files
    Last edited by Pete S; 02-14-2008, 07:14 AM.

    #2
    Excellent! Thanks for sharing.

    Comment


      #3
      Awesome

      I definitely will try this, awesome thanks for sharing

      Comment


        #4
        I see the download counts don't match; you need both of those files. This SQN.cs is required even if you have the old one I posted. This is explained more in the documentation.

        Comment


          #5
          Great !!

          Thanks

          Comment


            #6
            WTFG Pete!

            Rok

            Comment


              #7
              Nice work Pete, will give it a go. Thanks for sharing your work in this area.

              Regards,

              Whitmark
              whitmark
              NinjaTrader Ecosystem Vendor - Whitmark Development

              Comment


                #8
                Great work Pete! Please see my comments below:
                • I've created a small test strategy (MA Xover with Profit Target and Stop Loss) to test out the Genetic Optimizer, see attached. If I were to optimize this strategy via the default brute force method given the min/max/increment settings I've selected, I estimate it would have had to process 6.25 million iterations and have taken approximately 9 days to do so. Your GA optmizer, with default GA settings, obtained reasonable profitable results within 2.7 minutes underscoring the power of smart optimization methods.
                • The updates to the output window is a nice touch (see below). Very useful information including the iterations per second and a recap of the best results with parameter values:

                ES ##-##: Genetic Optimizer start: 2/15/2008 4:36:22 PM, parameters: 8, population: 256, generations: 5, save all results: True
                ES ##-##: completed generation 1/5, iterations per second: 7.7, max SQN so far: 2.12
                ES ##-##: completed generation 2/5, iterations per second: 7.7, max SQN so far: 1.97
                ES ##-##: completed generation 3/5, iterations per second: 7.9, max SQN so far: 2.15
                ES ##-##: completed generation 4/5, iterations per second: 8.0, max SQN so far: 2.15
                ES ##-##: completed generation 5/5, iterations per second: 7.9, max SQN so far: 2.22
                ES ##-##: completed: 2/15/2008 4:39:04 PM, total iterations: 1280, total time (minutes): 2.7, best result:
                GASaveAll: 1
                FastPeriod: 47
                SlowPeriod: 53
                ProfitTgtTicks: 23
                StopLssTicks: 25
                • I tried various combinations of maximum generations and population sizes and agree with your defaults as offering the best trade offs between search depth and breadth. Would be nice to also be able to modify the reproduction percentage and mutation rates from the parameters too.

                • Initially, I tried to segment the listing of GO parameters in the sample strategy by using a different [Category("GO Settings"] in the code but this did not work in the strategy. Plus I see that specific references are made in the GAOptimizer code to overwrite the default values. Would be nice not to comingle the GO settings and strategy parameters as you point out.

                • I was also working with file output recently in a separate indicator and was getting an extra 0 size file written out in addition to a populated text file. Sounds like this is worth a follow-up with NinjaSupport.

                • When I created a GA for another platform I had the benefit of using a third-party GO dll and just had to managed the inputs and outputs. Using another dll may have more bells and whistles, but I am very impressed you've successfully developed all of the operations directly in the GAOptimizer code. Did you consider any open source solutions as an alternative?

                • I suspect transforming non-integer parameters to and from what the GO can work with is high on the enhancement list. Do you have any other thoughts on what other enhancements you would like to make over and above what you have posted on the forum?


                Thanks again, Pete, for sharing your work. Good to know such great work is being done just up the road in VA. I hope our friends at NT are taking note of the power a GO can bring to enhance their platform offering.

                Regards,

                Whitmark
                Attached Files
                whitmark
                NinjaTrader Ecosystem Vendor - Whitmark Development

                Comment


                  #9
                  Pete, could you please PM me at "dierk AT ninjatrader DOT com"? I would want to discuss some issues with you. Thanks

                  Comment


                    #10
                    Mail sent. (I sent one on Saturday as well after I saw your PM.)

                    Comment


                      #11
                      Guess I need to monitor my spam filter ...

                      Comment


                        #12
                        Hi Pete,

                        Great job, you have effectively complete the "missing links" to be used with SQN. I 'll get back to you when I will have the beta version working.

                        Best reagrds,

                        Comment


                          #13
                          Hey Whitmark, sorry it took so long to respond to your feedback.

                          I tried various combinations of maximum generations and population sizes and agree with your defaults as offering the best trade offs between search depth and breadth. Would be nice to also be able to modify the reproduction percentage and mutation rates from the parameters too.
                          The user has to use a certain amount of judgement in selecting these values. As I mentioned in my docs, if you have a simple strategy you can end up actually running more iterations than you would using brute force. I haven't come up with a specific rule of thumb for the pop size yet but I find myself using values between 100 and 200 for the most part.

                          Initially, I tried to segment the listing of GO parameters in the sample strategy by using a different [Category("GO Settings"] in the code but this did not work in the strategy. Plus I see that specific references are made in the GAOptimizer code to overwrite the default values. Would be nice not to comingle the GO settings and strategy parameters as you point out.
                          Yeah, this is hacky right now. I proposed something here: http://www.ninjatrader-support.com/v...ead.php?t=4790 and am chatting about it with Dierk offline.

                          I was also working with file output recently in a separate indicator and was getting an extra 0 size file written out in addition to a populated text file. Sounds like this is worth a follow-up with NinjaSupport.
                          I need to do a little more debugging here myself, I have done this in another case without any issues. I still think this is is my code.

                          When I created a GA for another platform I had the benefit of using a third-party GO dll and just had to managed the inputs and outputs. Using another dll may have more bells and whistles, but I am very impressed you've successfully developed all of the operations directly in the GAOptimizer code. Did you consider any open source solutions as an alternative?
                          To be honest, in my searching, I did not run across anything appropriate.

                          I suspect transforming non-integer parameters to and from what the GO can work with is high on the enhancement list. Do you have any other thoughts on what other enhancements you would like to make over and above what you have posted on the forum?
                          I don't have a good feel for what other people are using for parameter types. I have never, in about 8 months of doing this, used anything other than an int or double parameter. If people need this support I am willing to implement it. The only other significant thing I can think of at this point is a "screening mode", where the optimizer runs until a threshold SQN value is reached. This would be useful on the stock side for running a list of lets say 200 symbols as quickly as possible to come up with a list of candidates for refinement.

                          Comment


                            #14
                            And by the way -- you can add the GA parameters into your UserDefinedMethods file so you don't need to put them in every strategy if you use the GA optimizer frequently.

                            Comment


                              #15
                              Hi Pete. Thanks for your reply. Here are some additional thoughts for your consideration:

                              1. In the GAOptimization code, I did notice two CreateLog() calls in the code and no CloseLog() call which could be the reason for the extra output file. I didn't give it much more investigation than that.

                              2. It would be nice to accommodate decimal parameter values including decimal increment values since using decimal multiples of ATR, StdDev, Parabolic inputs, for example, are quite common. Given GA parameters can only have integer values if you wanted to optimize a parameter between 1 and 10 in increments of 0.1 the min and max values would need to be converted to 10 and 100 respectively before loading into the GA. When the parameter is used later in the strategy, it is simply divided by 10. If increments of 0.2 was required, the defined min/max values would be 5 and 50 and the actual parameter would be divided by 5 when it is used.

                              3. Yes, I can't imagine support would be needed for anything beyond int or double. Boolean parameters can be converted to int's easily enough as a part of the strategy design.

                              4. Would be nice to be able to seed the parameter values of the initial generation of the GA (vs random number generation) when you already know that value X is pretty good, through previous testing or trading, but you want to explore other min and max values. This would likely require the input GUI to be expanded to accommodate a Seed value as well as Min, Max, and Increment. Perhaps there is a way to use the strategy parameter defaults as the seed values.

                              5. Have you considered implementing a parameter stress test feature. If not, you might be interested in learning more about it and how it can promote more stable parameter selection.

                              Thanks again for your generous contribution. Feel free to incorporate any or none of the above as you see fit and contact me if you need any development assistance with this.

                              Regards,

                              Whitmark
                              whitmark
                              NinjaTrader Ecosystem Vendor - Whitmark Development

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by mmckinnm, Today, 01:34 PM
                              3 responses
                              5 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by f.saeidi, Today, 01:32 PM
                              2 responses
                              6 views
                              0 likes
                              Last Post f.saeidi  
                              Started by alifarahani, 04-19-2024, 09:40 AM
                              9 responses
                              55 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_SeanH  
                              Working...
                              X