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

[amibroker] optimization techniques


  • To: <amibroker@xxxxxxxxxxxxxxx>
  • Subject: RE: [amibroker] Re: any ideas to reduce runtime for the price RS ranking code?
  • From: "Herman van den Bergen" <psytek@xxxxxxxx>
  • Date: Thu, 5 Aug 2004 06:47:48 -0700

PureBytes Links

Trading Reference Links




<FONT face=Arial color=#0000ff 
size=2>Charles, 
<FONT face=Arial color=#0000ff 
size=2> 
I 
performed some test and using static arrays (not available in AB yet) and 
at first glance it appears that I can compute the RS for a 3755 x 
100 stock matrix (375500 comparisons compared to your 490000) in less 
than a minute. You could probably duplicate the procedure using 
the OSAKA DLL table functions but i don't have time for that. Perhaps somebody 
else can provide afl code for the custom functions, else you may be able 
to substitute OSAKA code for the StaticArraySet functions the code goes 
something like that below, or you may email me privately <A 
href="">psytek@xxxxxxxx for the code i 
used.
<FONT face=Arial color=#0000ff 
size=2> 
Best 
regards,
<FONT face=Arial color=#0000ff 
size=2>herman



Filter 
= Status("LastBarInTest");SetOption("NoDefaultColumns",True);WL1 = 0; 
//WL2 is selected with Filter;
 
// 
Calculate the RS1 for WL1 just once, when the first stock in the filter is 
testedif(Status("StockNum") == 0 )  StaticVarSet("IsInitialized", 
0);
 
if( 
StaticVarGet("IsInitialized") == 0 ) { list1 = 
CategoryGetSymbols( categoryWatchlist , WL1); for( i = 0; ( sym = 
StrExtract( list1, i ) ) != ""; i++ 
)  {  SetForeign(sym);  MyArray = 
C;  sRelStren =    IIf((IsNull(ROC(myArray, 
260)) == False),     ROC(myArray, 260) + ROC(myArray, 
195) +    ROC(myArray, 130) + 2 * ROC(myArray, 65), 
   IIf ((IsNull(ROC(myArray, 195)) == 
False),    ROC(myArray, 195) + 2 * ROC(myArray, 130) + 2 
*     ROC(myArray, 65), 2 * ROC(myArray, 130) + 3 * 
ROC(myArray, 65) ));  VarName = 
"Sym"+NumToStr(i,1.0,False);<FONT 
color=#ff0000>//  StaticArraySet(sRelStren ,"RS-"+VarName); // Save 
the RS in a Static Array (custom 
function)  } StaticVarSet("NumTickers",i); StaticVarSet("IsInitialized", 
1); RestorePriceArrays(); }
 
Ticker 
= Name();AddTextColumn(Ticker," ",1.0);
 
// 
Calculate the RS2 for each stock in the Filter processed by the AA 
ExplorereMyArray = C;sRelStren2 =  IIf((IsNull(ROC(myArray, 
260)) == False),   ROC(myArray, 260) + ROC(myArray, 195) 
+  ROC(myArray, 130) + 2 * ROC(myArray, 65),  IIf 
((IsNull(ROC(myArray, 195)) == False),  ROC(myArray, 195) + 2 * 
ROC(myArray, 130) + 2 *   ROC(myArray, 65), 2 * ROC(myArray, 130) 
+ 3 * ROC(myArray, 65) ));
 
// Do 
whatever you want with the two RSs, I just multiply as a test.for( i = 0; 
i<StaticVarGet("NumTickers"); i++ ) { VarName = 
"Sym"+NumToStr(i,1.0,False);// sRelStren1 = 
StaticArrayGet(VarName); // Recall RS1 from the Static Array (custom 
function) AddColumn(sRelStren1 *sRelStren2 ,VarName 
,1.2); }
<FONT face=Arial color=#0000ff 
size=2> 




  <FONT face=Tahoma 
  size=2>-----Original Message-----From: firstview2000 
  [mailto:firstview2000_1999@xxxxxxxxx]Sent: Thursday, August 05, 
  2004 2:20 AMTo: amibroker@xxxxxxxxxxxxxxxSubject: 
  [amibroker] Re: any ideas to reduce runtime for the price RS ranking 
  code?Herman,Your afl code also consumed too 
  LONG time to finish: I ran it for 18 minutes, and the estimated time left 
  is 19 minutes. So, it will be in the range of 40 minutes to complete 700 
  stocks based on this speed.I also tested your AFL in a 517 stock 
  watch list, it took 22 minutes to complete.For a 53 stock watch 
  list, it took 13 seconds to complete.I thought about your 
  suggestion #1, but could not find any good way to reduce the loops. There 
  are a lot of un-necessary repeating calculations in my AFL: the RS of each 
  stock is repeated 700 times. To avoid this, I need to store RS values for 
  700 stocks. I think it is not good idea to create 700 ATC composites for 
  this purpose. what do you think?Other information:The 
  status line of the AA window stated "Running ..." all the time during the 
  exploration.In my AFL preference setting, the quickAFL for indicator 
  is checked.RegardsCharles--- In 
  amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen" <psytek@xxxx> 
  wrote:> Don't know if it can be improved but i'll think about it; I 
  like this kind> of challenges. Coding is more fun than trading, 
  ooops: i should have said> that in public :-)> > For 
  comparison you may look at the code below which performs a similar> 
  action, it calculates the correllation between each of a group of 
  stocks.> Run it on your 700 and see how long it takes. If it is 
  much shorter than the> time-consuming code is not the StrExtract() 
  and you should look at your> other lines of code. I would be 
  interested to know how that compares on your> computer. It take 
  less than 10 seconds to correlate 100x100 stocks for me.> > 
  SetOption("NoDefaultColumns",True);> Filter = 
  Status("LastBarInTest");> list = GetCategorySymbols( categoryWatchlist, 
  0);> AddTextColumn(Name(),"Correlation",1.0);> Ticker1= 
  Name();> for( Col=0; (Ticker2=StrExtract( List, Col))!= ""; 
  Col++)> {> Var2 = Foreign(Ticker2,"C");> Corr = 
  Correlation( C, Var2, 8);> Color = IIf(Corr>0, colorBrightGreen, 
  IIf(Corr<0, colorRed,colorWhite));> Color = 
  IIf(Ticker1==Ticker2, 1, Color);> AddColumn( Corr, Ticker2, 1.3, 1, 
  Color);> }> > 1) You may have calculations inside your 
  loop that are repeated for each> comparison but that need only be 
  calculated one time for each stock, outside> the loop. You could 
  use an additional loop through the watchlist to create> these 
  variables using SetVar. That way they would be calculated 700x 
  instead> of 700^2 x... that would give a 700x improvement for those 
  lines of code.> Your selfRelStrength function comes to mind 
  ...> > 2) some things that come to mind is that you are 
  retrieving 700 x 700 x 3000> (assuming 10 yrs data) bars from your 
  hard disk. You can observe this by> noting the status line at the 
  bottom of the AB screen. The AA doesn't use> QuickAFL so perhaps it 
  would work faster to run this indicator in an> indicator using two 
  loops.> > 3) Your code could also create a OSAKA-like table for 
  all stocks and work> from there, with the same objective.> 
  > interesting problem, let me know how you progress, I'll let you 
  know if> something else comes to mind.> > 
  herman> > > >   -----Original 
  Message----->   From: firstview2000 
  [mailto:firstview2000_1999@xxxx]>   Sent: Wednesday, August 
  04, 2004 1:32 AM>   To: 
  amibroker@xxxxxxxxxxxxxxx>   Subject: [amibroker] Re: any 
  ideas to reduce runtime for the price RS> ranking code?> 
  > >   Herman,> >   I need all 
  available values for the RS ranking for backtesting>   
  purpose. I could plot a chart showing the rs ranking if I need so.> 
  >   My code performs the following loops:> 
  >   the outer loop is for all 700 stocks in database to have 
  their>   rankings;>   the inner loop is for 
  comparing one stock to every other 700 stocks> >   
  So, there are 700x700=490,000 loops. I don't know if we can 
  reduce>   the number of loops here.> 
  >   In addition, if stock quotes are 1000 bars in length, 
  this ranking>   formula will have 490K x 1000 = 490 
  million calculations to complete.> >   It takes 
  over 40 minutes to complete, which suggests about 10>   
  million RS calculations per minute. I don't know if this is 
  a>   reasonable rate, but I just think 40minutes is too 
  long.> >   Thank for your help.>   
  Charles> Check AmiBroker web page 
  at:<A 
  href="">http://www.amibroker.com/Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  


Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.