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

RE: [amibroker] CORRELATION MATRIX: filter within loop ?



PureBytes Links

Trading Reference Links




<FONT face=Arial color=#0000ff 
size=2>I think you have a problem doing this when correlating one 
watchlist against another watchlist because the table would have to be completed 
to know which column would have to be displayed. However you can do this 
using the OSAKA table DLL but that is beyond my programming capability 
:-)
<FONT face=Arial color=#0000ff 
size=2> 
<FONT face=Arial color=#0000ff 
size=2>When testing only the current stock against a watchlist you can 
use the code attached. Note two lines were 
added/modified:
<FONT face=Arial color=#0000ff 
size=2> 
LastBarInTest = 
LastValue(<FONT 
color=#0000ff>ValueWhen(<FONT 
color=#0000ff>Status(<FONT 
color=#ff00ff>"LastBarInTest"),<FONT 
color=#0000ff>BarIndex())); 

<FONT 
face="Courier New">....
<FONT 
color=#ff0000>if( Corr[LastBarInTest] > 
0.75 ) <FONT 
color=#0000ff>AddColumn( Corr, Ticker2, <FONT 
color=#ff00ff>1.3, <FONT 
color=#ff00ff>1, Color); 
<FONT 
face="Courier New"> 
<FONT face=Arial 
size=2>herman.

  <FONT face=Tahoma 
  size=2>-----Original Message-----From: dirk schreiber 
  [mailto:tianatrading@xxxxxxxxx]Sent: December 9, 2003 7:01 
  PMTo: amibrokerSubject: [amibroker] CORRELATION MATRIX: 
  filter within loop ?
  does anybody know how to filter 
  within loops?
   
  i'm still playing around with the 
  very nice CORRELATION MATRIX that came out of a group effort last 
  month.
  while visually it's nice to look 
  at, i am having trouble trying to expand upon its functionality. 
  
  i would like to be able to set a 
  filter within the loop so that the matrix only shows those pairs with a 
  correlation of higher than 0.75 for example. i have tried using "addcolumn(iif 
  ...." and "iif( ... addcolumn" but that did not work. i understand that the 
  for-loop overrides any filter within the loop? 
  a question closely related is, i 
  think, if it is possible to modify the code so that the correlation of any 
  ticker would not be calculated against itself, because filtering within 
  the matrix (if possible) for high correlation would not work, as every 
  row has one incident of a perfect correlation of 1 (its own 
  correlation).
  below is a modified version 
  of the code.
   
  hope i made myself 
  clear,
   
  any help 
appreciated,
   
  dirk
   
  
  // Exploration to create Correlation matrix
  Buy<FONT 
  size=2>=Sell=Short=Cover=0; 
  
  Filter = <FONT 
  color=#0000ff>Status("LastBarInTest"); 
  
  list = GetCategorySymbols( 
  categoryWatchlist, 3 );<FONT 
  color=#800000>
  for( NumTickers=<FONT 
  color=#ff00ff>0; NumTickers < 100 AND <FONT 
  color=#0000ff>StrExtract( list, NumTickers ) != <FONT 
  color=#ff00ff>""; NumTickers++ ); <FONT face=Verdana 
  color=#0000ff>
  IIf<FONT 
  face=Verdana>(C><FONT face=Verdana 
  color=#ff00ff>50,<FONT 
  color=#0000ff>AddTextColumn(Name(),<FONT 
  color=#ff00ff>"Ticker",1.0)<FONT 
  face=Verdana>,0<FONT 
  face=Verdana>); 
  for( Col=<FONT 
  color=#ff00ff>0; Col<NumTickers; Col++) 
  { 
  Ticker1 = Name(); 
  Ticker2 = StrExtract( list, Col); 
  
  Var1 = Foreign(Ticker1,<FONT 
  color=#ff00ff>"C"); 
  Var2 = Foreign(Ticker2,<FONT 
  color=#ff00ff>"C"); 
  Corr = Correlation( Var1, Var2, 
  8 ); 
  Color = IIf(Corr==<FONT 
  color=#ff00ff>1,colorBlack,<FONT 
  color=#0000ff>IIf(Corr<-<FONT 
  color=#ff00ff>0.8,colorRed,<FONT 
  color=#0000ff>IIf(Corr<-<FONT 
  color=#ff00ff>0.5,colorOrange,<FONT 
  color=#0000ff>IIf(Corr<-<FONT 
  color=#ff00ff>0.2,colorLightOrange,<FONT 
  color=#0000ff>IIf(Corr<<FONT 
  color=#ff00ff>0.2,colorCustom9,<FONT 
  color=#0000ff>IIf(Corr<<FONT 
  color=#ff00ff>0.5,colorAqua,<FONT 
  color=#0000ff>IIf(Corr<<FONT 
  color=#ff00ff>0.8,colorBrightGreen,colorGreen))))))); 
  
  AddColumn( Corr, Ticker2, <FONT 
  color=#ff00ff>1.3, 1, Color); 
  } Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 

  
  
  Do you Yahoo!?Protect 
  your identity with Yahoo! Mail AddressGuard






Yahoo! Groups Sponsor


  ADVERTISEMENT 









Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



Attachment:
CorrPost.afl

Attachment: Description: "Description: Binary data"