[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Tips for reducing CPU load



PureBytes Links

Trading Reference Links

thanks TJ,

I just finished a quick and "accademic" test of the static variable tip... it solved!

I wrote a dummy TS with my very time consuming indicator and did an optimization on 4 years EOD data of only one symbol. The optimization had only 5 steps

with Static variable --> lightning fast

without Static variable --> 27s (!!) --> not useful in real conditions

I don't believe that my indicator is extremely complex, it's more likely extremely bad coded... nevertheless I did my best. but let's speak later about it

let's consider for a moment that it's well coded, or that it is a more complex array well coded by a professionist, I wonder that declaring as Invariant an array in AFL, to avoid to be recalculated n times during optimization, would give an other edge to AB against other sw. something like: 

Invariant( "MyComplexArray" );

or better something like #calculate_once<invariant.afl> (similar to #include_once <Common.afl>)  to refer to some code to be executed once at the beginning of the process 

maybe I didn't explain well but I am sure that you get what I mean.

-------------

my time consuming indicator finds *for every bar* which was the value of RSI that was exceeded for a limit % number of times in the last N months. it's useful to have an adaptative value of iperbought and ipersold limit of RSI. never mind about the need to adapt at every bar or that it's useful in general. Up to now this is only prepatory for an other my project about pivot points.

I didn't find a way to use array operators to do it but I was forced to use nested loop... it looks ugly even to my eyes... any tip?


Limit = 5;

NMonths = 6;

periods = Param( "Periods", 15, 1, 200, 1 );

IperSArray = IperBArray = Null;

DayLimit = NMonths * 22 * Limit / 100;

Oscill = RSI( periods );

for ( i = NMonths * 22 ; i < BarCount; i++ )

{

IperS = 1;

IperB = 99;

DayIperS= DayIperB= 0;

while ( DayIperS< DayLimit )

{

DayIperS= 0;

for ( j = 0; j < NMonths * 22; j++ )

if ( Oscill [i-j] < IperS )

DayIperS++ ;

IperS ++ ;

}

while ( DayIperB< DayLimit )

{

DayIperB= 0;

for ( j = 0; j < NMonths * 22; j++ )

if ( Oscill [i-j] > IperB )

DayIperB++ ;

IperB -- ;

}

IperSArray[i] = IperS;

IperBArray[i] = IperB;

}

StaticVarSet("IperSArray",IperSArray);

StaticVarSet("IperBArray",IperBArray);


--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> IMHO, it is not worth the effort, unless you are doing something _extremely_ complex.
> AFL execution is just a fraction of total time, you would end up spending lots of time with very
> little effect. Remember that your time is way more precious that CPU time.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "Bisto" <bistoman73@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Tuesday, October 06, 2009 4:03 PM
> Subject: [amibroker] Re: Tips for reducing CPU load
> 
> 
> > Thanks TJ,
> >
> > your posts are always very instructive, it seems that you know well how AB works :-)
> >
> > good to know that using static variables is the best way, I try to summarize:
> >
> > 1) to create static variables using a single pass of an AFL on a symbol/watchlist, like an Explore with CreateStaticVariables.AFL
> >
> > 2) to optimize TradingSystem.AFL on the same symbol/watchlist who points to the static variables created in point 1 who are 
> > "alive" till overwritten or AB closed
> >
> > of course this is not the case of MA( C,15) but something a lot more complex
> >
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> wrote:
> >>
> >> Hello,
> >>
> >> They are indeed recalculated when going through several backtests.
> >> You could store such values in static variables and use them later in subsequent runs,
> >> but it is in most cases _wasted_ effort, because array functions like MA( C, 15 ) are EQUALLY fast
> >> as STATIC variables. This is so because static variables requires one pass any way (date/time synchronization)
> >> the same as MA. MA can actually be slightly faster than static array variable because of locality of reference.
> >>
> >> Situation is different with normal variables (as I pointed out in my previous post), because normal variables
> >> do not require synchronization (they are already in perfect sync) and do not require extra memory
> >> nor ANY computation as they are simple POINTERS to values that were returned by function.
> >> Storing/reading a pointer to array is a matter of single CPU instruction, i.e. is blazing fast (one CPU clock cycle).
> >>
> >> Regarding AddToComposite/Foreign - they are way slower than Static variables, so it makes no sense to use them for that purpose.
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >> ----- Original Message ----- 
> >> From: "Bisto" <bistoman73@>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Tuesday, October 06, 2009 1:52 PM
> >> Subject: [amibroker] Re: Tips for reducing CPU load
> >>
> >>
> >> >I was thinking about this issue yesterday and I have a question, please correct me if I am wrong:
> >> >
> >> > During an optimization process there are so many repetitions of a function with invariant parameter equal to the total number 
> >> > of
> >> > the steps of the optimization.
> >> >
> >> > In this case MA(C,15) will be calculated for every set of optimization parameter even if it is invariant, OK?
> >> >
> >> > If we have a very time consuming invariant function in the TS it will be calculated a lot of times even if it is not needed. 
> >> > This
> >> > is true if I have well interstood how AB works, please correct me
> >> >
> >> > my idea is to store this very time consuming invariant function in a "fake" symbol (using Addtocomposite) and access to its 
> >> > values
> >> > by Setforeing.
> >> >
> >> > Is it a good idea?
> >> >
> >> > Bisto
> >> >
> >> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> wrote:
> >> >>
> >> >> Hello,
> >> >>
> >> >> For example, take a look at this simple code:
> >> >>
> >> >> Buy = Cross( MA(C, 5 ), MA( C, 15 ) );
> >> >> Sell = Cross( MA( C, 15 ), MA( C, 5 ) );
> >> >>
> >> >> There are 2 repetitions of same function call with invariant parameters:
> >> >> MA(C, 5 ) - is called twice
> >> >> MA( C, 15 ) - is called twice
> >> >>
> >> >> This can be written in more efficient manner using variables:
> >> >>
> >> >> shortma = MA(C, 5 );
> >> >> longma = MA( C, 15 );
> >> >> Buy = Cross( shortma, longma );
> >> >> Sell = Cross( longma, shortma );
> >> >>
> >> >> That is what I meant.
> >> >>
> >> >> Best regards,
> >> >> Tomasz Janeczko
> >> >> amibroker.com
> >> >> ----- Original Message ----- 
> >> >> From: "Rob" <sidhartha70@>
> >> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> >> Sent: Tuesday, October 06, 2009 10:21 AM
> >> >> Subject: [amibroker] Re: Tips for reducing CPU load
> >> >>
> >> >>
> >> >> > TJ,
> >> >> >
> >> >> > Sorry my programming terminology is not as good as yours...
> >> >> > What do you mean by 'replacing repeated function calls with invariant parameters'...??
> >> >> >
> >> >> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> wrote:
> >> >> >>
> >> >> >> First and foremost: use AFL Editor, Tools->Code Check And Profile
> >> >> >> to reduce complexity of your code, by removing repeated function calls (with invariant parameters),
> >> >> >> using array operators wherever possible instead of loops,
> >> >> >> re-thinking code to get simpler formulation,
> >> >> >> avoiding any JScript/VBScript / COM objects in charts, etc.
> >> >> >>
> >> >> >> Best regards,
> >> >> >> Tomasz Janeczko
> >> >> >> amibroker.com
> >> >> >> ----- Original Message ----- 
> >> >> >> From: "Ara Kaloustian" <ara1@>
> >> >> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> >> >> Sent: Tuesday, October 06, 2009 12:23 AM
> >> >> >> Subject: Re: [amibroker] Tips for reducing CPU load
> >> >> >>
> >> >> >>
> >> >> >> >- review your memory settings in preferences... make sure you are not
> >> >> >> > allocating memory that you are not using
> >> >> >> >
> >> >> >> > - reduce number of symbols you monitor if you don't need them all
> >> >> >> >
> >> >> >> >
> >> >> >> > ----- Original Message ----- 
> >> >> >> > From: "Rob" <sidhartha70@>
> >> >> >> > To: <amibroker@xxxxxxxxxxxxxxx>
> >> >> >> > Sent: Monday, October 05, 2009 2:33 PM
> >> >> >> > Subject: [amibroker] Tips for reducing CPU load
> >> >> >> >
> >> >> >> >
> >> >> >> >> Hi All,
> >> >> >> >>
> >> >> >> >> I seem to be maxing out the core I'm using on AB... starting to cause
> >> >> >> >> problems operationally. I'm mainly doing charting and real time AFL.
> >> >> >> >>
> >> >> >> >> Any tips for reducing CPU load so I can perhaps give myself a little more
> >> >> >> >> breathing space....??
> >> >> >> >>
> >> >> >> >> TIA
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> ------------------------------------
> >> >> >> >>
> >> >> >> >> **** IMPORTANT PLEASE READ ****
> >> >> >> >> This group is for the discussion between users only.
> >> >> >> >> This is *NOT* technical support channel.
> >> >> >> >>
> >> >> >> >> TO GET TECHNICAL SUPPORT send an e-mail directly to
> >> >> >> >> SUPPORT {at} amibroker.com
> >> >> >> >>
> >> >> >> >> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> >> >> >> >> http://www.amibroker.com/feedback/
> >> >> >> >> (submissions sent via other channels won't be considered)
> >> >> >> >>
> >> >> >> >> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >> >> >> >> http://www.amibroker.com/devlog/
> >> >> >> >>
> >> >> >> >> Yahoo! Groups Links
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > ------------------------------------
> >> >> >> >
> >> >> >> > **** IMPORTANT PLEASE READ ****
> >> >> >> > This group is for the discussion between users only.
> >> >> >> > This is *NOT* technical support channel.
> >> >> >> >
> >> >> >> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> >> >> >> > SUPPORT {at} amibroker.com
> >> >> >> >
> >> >> >> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> >> >> >> > http://www.amibroker.com/feedback/
> >> >> >> > (submissions sent via other channels won't be considered)
> >> >> >> >
> >> >> >> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >> >> >> > http://www.amibroker.com/devlog/
> >> >> >> >
> >> >> >> > Yahoo! Groups Links
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > ------------------------------------
> >> >> >
> >> >> > **** IMPORTANT PLEASE READ ****
> >> >> > This group is for the discussion between users only.
> >> >> > This is *NOT* technical support channel.
> >> >> >
> >> >> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> >> >> > SUPPORT {at} amibroker.com
> >> >> >
> >> >> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> >> >> > http://www.amibroker.com/feedback/
> >> >> > (submissions sent via other channels won't be considered)
> >> >> >
> >> >> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >> >> > http://www.amibroker.com/devlog/
> >> >> >
> >> >> > Yahoo! Groups Links
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > **** IMPORTANT PLEASE READ ****
> >> > This group is for the discussion between users only.
> >> > This is *NOT* technical support channel.
> >> >
> >> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> >> > SUPPORT {at} amibroker.com
> >> >
> >> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> >> > http://www.amibroker.com/feedback/
> >> > (submissions sent via other channels won't be considered)
> >> >
> >> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >> > http://www.amibroker.com/devlog/
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > **** IMPORTANT PLEASE READ ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> >
> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> > http://www.amibroker.com/feedback/
> > (submissions sent via other channels won't be considered)
> >
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > Yahoo! Groups Links
> >
> >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/