Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimization time

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

    #31
    Hi, Pete,

    I modify my code, here is the new result:

    100000: avg cross: 90.938 avg cross2: 404.219 avg orders: 6.719 [times in microseconds]
    200000: avg cross: 91.641 avg cross2: 368.359 avg orders: 5.703 [times in microseconds]

    I only have such so good little data.

    Thanks

    Comment


      #32
      Jenny:

      Whatever is inside the section labeled cross2 is taking, if my math is correct, ~80 seconds of time:

      ~400 microseconds * ~200,000 runs = ~80,000,000 microseconds or 80 seconds. If you are still running 4 iterations, that's 20 seconds per iteration. So that is probably the first problem area to look at. Can you give me as much detail as you can about what you are doing in there?

      Comment


        #33
        Pete,

        I just want to find 2 most recent Low and High points, then compare them to see good for Buy or Sale. I use MRO() and LRO(), MIN() and MAX().

        Maybe you have some way much easier?

        Thanks
        Last edited by Jenny; 01-09-2008, 03:03 PM.

        Comment


          #34
          There is only so much feedback I am going to be able to give without seeing code...in general, as I said earlier, your code is probably using a bad algorithm and looking at the input data too many times. Just curious; how many bars back are you looking?

          Even if you are just using min and max functions, you can do optimizations. MIN and MAX each loop through the input data. Here's an example. My breakout strategy uses the DonchianChannel indicator. The main section of the standard out-of-the-box DonchianChannel looks like this:

          Code:
          Value.Set((MAX(High, Period)[0] + MIN(Low, Period)[0]) / 2);
          Upper.Set(MAX(High, Period)[0]);
          Lower.Set(MIN(Low, Period)[0]);
          Each call to MIN or MAX is looping through the data Period number of times. I created a new indicator which uses this as the main logic:

          Code:
          int n;
          double high = -1, low = 1000000;
          for (n = 0; n < actualPd; n++)
          {
            if (High[n] > high)
              high = High[n];
            if (Low[n] < low)
              low = Low[n];
          }
          			
          MyMean.Set((high + low) / 2);
          MyUpper.Set(high);
          MyLower.Set(low);
          Notice there's only one loop. This was roughly 300% faster, as well as degrading in linear fashon, where the stock code degrades in a worse than linear fashon.

          Ideally, you wouldn't need to worry about this stuff, but optimizing for performance has really been a key part of my productivity improvement.

          Comment


            #35
            Pete,
            You are right!!
            I use a loop insteads of MIN, MAX, MRO() and LRO(), it works much fast.
            Thanks a lots and good luck in the market!
            Jenny

            Comment


              #36
              Thanks for this Pete S ...
              I can see where this could speed up my optimizations significantly ... one question - with this indicator, I'm a bit confused on the use of actualPd ... Is this a vairiable you have named above that is the desired lookback period of the indicator (replacing the period in MAX / MIN) that is an input for the normal Donchian Channel?

              Thanks again ...

              Learning1

              Comment


                #37
                I use an intraday-only version, so for me it contains either the Period or bars since the beginning of the day. You can safely ignore that and just use the standard period parameter, just make sure you check CurrentBar > Period.

                Comment


                  #38
                  Does this mean that the Max and Min calls could be improved by Ninja so they are not so 'intensive'? Certainly sounds like it!

                  I am off to change my coding!

                  Sunrise.

                  Comment


                    #39
                    It depends. For example, if you need to call a bunch of different functions that are going to iterate over 20 bars of data, there is no way for NT to restructure those calls so that can all be done at once.

                    I'll just emphasize again in my opinion it's not a problem per se, it's just that when you are running long backtests anything you can do to pick up efficiency really helps.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by GussJ, 03-04-2020, 03:11 PM
                    11 responses
                    3,227 views
                    0 likes
                    Last Post xiinteractive  
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    440 views
                    0 likes
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post FAQtrader  
                    Working...
                    X