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

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



PureBytes Links

Trading Reference Links




thank you herman for the 
code.
i have the feeling that we are 
getting closer, although i realize why you say that this solution only works for 
a single stock. it is obvious since we cannot have different columns for every 
row. but at least your variation of the code can show how many correlations with 
other stocks above/beneath a certain level every stock has.
 
i will try to see if i can enhance 
your code of the single stock correlation exploration.
 
thanks,
 
dirk
 
 
 
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Herman vandenBergen 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Tuesday, December 09, 2003 1:01 
  PM
  Subject: RE: [amibroker] CORRELATION 
  MATRIX: filter within loop ?
  
  <FONT face=Arial color=#0000ff 
  size=2>Forgot Yahoo doesn't attach 
  files anymore, here is the code:
  <FONT face=Arial color=#0000ff 
  size=2><SPAN 
  class=570355911-09122003> 
  <SPAN 
  class=570355911-09122003>// THIS 
  WILL ONLY WORK CORRECTLY EXPLORING THE CURRENT STOCK AGAINST 
  THE 
  // WATCHLIST SELECTED IN THE 
  GetCategorySymbols() !!!!!<FONT 
  face=Arial> // 
  Exploration to create Correlation matrix<FONT 
  size=2> <FONT 
  color=#ff0000>Buy=<FONT 
  color=#ff0000>Sell=<FONT 
  color=#ff0000>Short=<FONT 
  color=#ff0000>Cover=<FONT 
  color=#ff00ff>0<FONT 
  color=#000000>; LastBarInTest = <FONT 
  color=#0000ff>LastValue(<FONT 
  color=#0000ff>ValueWhen(<FONT 
  color=#0000ff>Status(<FONT 
  color=#ff00ff>"LastBarInTest"),<FONT 
  color=#0000ff>BarIndex<FONT 
  color=#000000>())); <FONT 
  color=#ff0000>Filter = 
  Status(<FONT 
  color=#ff00ff>"LastBarInTest"<FONT 
  face=Arial>); list = <FONT 
  color=#0000ff>GetCategorySymbols( <FONT 
  color=#ff0000>categoryWatchlist, 
  0<FONT 
  face=Arial> ); <FONT 
  color=#ff0000>for( 
  NumTickers=0; NumTickers 
  < 100 <FONT 
  color=#ff0000>AND <FONT 
  color=#0000ff>StrExtract( list, NumTickers ) != 
  ""<FONT 
  face=Arial>; NumTickers++ ); <FONT 
  color=#0000ff>IIf(<FONT 
  color=#ff0000>C><FONT 
  color=#ff00ff>50,<FONT 
  color=#0000ff>AddTextColumn(<FONT 
  color=#0000ff>Name(),<FONT 
  color=#ff00ff>"Ticker",<FONT 
  color=#ff00ff>1.0),<FONT 
  color=#ff00ff>0<FONT 
  color=#000000>); <FONT 
  color=#ff0000>for( 
  Col=0<FONT 
  face=Arial>; Col<NumTickers; Col++) { 
  Ticker1 = Name<FONT 
  size=2>(); Ticker2 = <FONT 
  color=#0000ff>StrExtract<FONT 
  face=Arial>( list, Col); Var1 = <FONT 
  color=#0000ff>Foreign(Ticker1,<FONT 
  color=#ff00ff>"C"<FONT 
  color=#000000>); Var2 = Foreign<FONT 
  color=#000000>(Ticker2,<FONT 
  color=#ff00ff>"C"<FONT 
  color=#000000>); Corr = <FONT 
  color=#0000ff>Correlation( Var1, Var2, <FONT 
  color=#ff00ff>8<FONT 
  color=#000000> ); Color = IIf<FONT 
  color=#000000>(Corr==1<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorBlack<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<-0.8<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorRed<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<-0.5<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorOrange<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<-0.2<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorLightOrange<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<0.2<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorCustom9<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<0.5<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorAqua<FONT 
  color=#000000>,IIf<FONT 
  color=#000000>(Corr<0.8<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorBrightGreen<FONT 
  color=#000000>,<FONT 
  color=#ff0000>colorGreen<FONT 
  size=2>))))))); <FONT 
  color=#ff0000>if( 
  Corr[LastBarInTest] > 0.75<FONT 
  color=#000000> ) AddColumn<FONT 
  color=#000000>( Corr, Ticker2, 1.3<FONT 
  color=#000000>, 1<FONT 
  color=#000000>, Color); } 
  
  <FONT face=Arial color=#0000ff 
  size=2> 
  <FONT face=Arial color=#0000ff 
  size=2>
  
  
  <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=Arial 
  size=2>....
  <FONT 
  color=#ff0000>if( Corr[LastBarInTest] > 
  0.75 ) <FONT 
  color=#0000ff>AddColumn( Corr, Ticker2, 
  1.3, <FONT 
  color=#ff00ff>1, Color); 
  
  <FONT face=Arial 
  size=2> 
  <FONT face=Arial 
  size=2>herman.
  
    <FONT face=Arial 
    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 face=Arial 
    size=2>=Sell=Short=Cover=0; 
    
    Filter = <FONT 
    color=#0000ff>Status("LastBarInTest"); 
    
    list = <FONT 
    color=#0000ff>GetCategorySymbols( categoryWatchlist, <FONT 
    color=#ff00ff>3 );
    for( 
    NumTickers=0; NumTickers < 100 AND 
    StrExtract( list, NumTickers ) != <FONT 
    color=#ff00ff>""; NumTickers++ ); 
    IIf<FONT face=Arial 
    size=2>(C>50,<FONT 
    color=#0000ff>AddTextColumn(Name(),<FONT 
    color=#ff00ff>"Ticker",1.0),<FONT 
    color=#ff00ff>0); 
    for( 
    Col=0; Col<NumTickers; Col++) 
    { 
    Ticker1 = Name(); 
    
    Ticker2 = StrExtract( 
    list, Col); 
    Var1 = <FONT 
    color=#0000ff>Foreign(Ticker1,"C"); 
    
    Var2 = <FONT 
    color=#0000ff>Foreign(Ticker2,"C"); 
    
    Corr = Correlation( 
    Var1, Var2, 8 ); 
    Color = <FONT 
    color=#0000ff>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, 1.3, 1, 
    Color); 
    } <FONT face=Arial 
    size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
    suggest@xxxxxxxxxxxxx-----------------------------------------Post 
    AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: 
    <FONT 
    face=Arial 
    size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT 
    face=Arial size=2>--------------------------------------------Check 
    group FAQ at: <A 
    href=""><FONT 
    face=Arial 
    size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT 
    face=Arial size=2> Your use of Yahoo! Groups is subject to the 
    Yahoo! Terms of 
    Service. 
    
    
    Do you Yahoo!?<A 
    href=""><FONT face=Arial 
    size=2>Protect your identity with Yahoo! Mail 
  AddressGuardSend 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: 
  <FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT 
  face=Arial size=2>--------------------------------------------Check group 
  FAQ at: <A 
  href=""><FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT 
  face=Arial size=2> Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 
  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. 







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.




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