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

RE: [amibroker] to HERMAN: N100 Correlation table



PureBytes Links

Trading Reference Links




You are 
correct Dirk: I missed combinations, thanks for pointing that out. This was 
because I copied/modified it from some other code. You missed stock 
number 1 in your loop but bringing the start down to zero just appears to 
overload the row character count - I seem to remember having that problem 
before. You may have to drop one stock :-)
<SPAN 
class=170100611-27112003> 
I am not an 
expert on abs vs rel correlation :-) can't help you 
there.
<SPAN 
class=170100611-27112003> 
<FONT 
face=Arial>Just for fun, after the line defining color you 
can add:    Color = 
IIf(Ticker1==Ticker2,1,Color); <SPAN 
class=170100611-27112003>to color the 
position for same ticker correlation 
black. 
<SPAN 
class=170100611-27112003> 
<SPAN 
class=170100611-27112003>herman

  <FONT face=Tahoma 
  size=2>-----Original Message-----From: dirk schreiber 
  [mailto:tianatrading@xxxxxxxxx]Sent: November 27, 2003 6:06 
  PMTo: amibroker@xxxxxxxxxxxxxxxSubject: [amibroker] to 
  HERMAN: N100 Correlation table
  hello herman,
   
  after playing around with your 
  code a little bit, i realized that it is not showing a COMPLETE 
  "heat list" of the n100. by "splitting up" the 100 stocks into two groups of 
  50, one for the x-axis and the other for the y-axis, we can't get the whole 
  picture. the first stock (AAPL) has its correlation only measured against 
  stocks 50-99(JDSU-YHOO), but not for example against ADBE or ADCT. 
  
  thanks to posting your code 
  i am beginning to understand the logic of looping better, so i just changed 
  some numbers to have the loop go through ALL possible combinations. it takes 
  slightly longer (instead of 50*50=2500 it's 100*100=10000 calculations) and of 
  course it has quite a lot of duplicate results, but i think it is the only way 
  to calculate all correlations.
  also, i changed the code from 
  absolute to relative correlation, which gives different results.
   
  what do you think?
   
  dirk
   
   
  
  // Exploration N100 relative 
  Correlation table <FONT 
size=1>
  Buy=Sell=Short=Cover=<FONT color=#ff00ff 
  size=1>0; 
  StkNum = Status<FONT 
  size=1>("StockNum"); 
  
  Filter = Status<FONT 
  size=1>("LastBarInTest") 
  AND StkNum < 100<FONT 
  size=1>; 
  AddTextColumn(<FONT color=#0000ff 
  size=1>Name(),<FONT color=#ff00ff 
  size=1>"Ticker",<FONT color=#ff00ff 
  size=1>1.0); <FONT 
  color=#0000ff size=1>
  SetOption(<FONT color=#ff00ff 
  size=1>"nodefaultcolumns",<FONT 
  color=#ff00ff size=1>1);
  n = StkNum; 
  #include 
  <NtoN100Ticker.afl> 
  Ticker1 = Ticker; 
  C1 = ROC(<FONT 
  color=#0000ff size=1>Foreign(Ticker1,<FONT 
  color=#ff00ff size=1>"C"),<FONT color=#ff00ff 
  size=1>1); 
  for(m=<FONT face=Verdana 
  color=#ff00ff size=1>1;m<=<FONT 
  face=Verdana color=#ff00ff size=1>99<FONT 
  color=#000000>;m++) 
  { 
  n=m; 
  #include 
  <NtoN100Ticker.afl> 
  Ticker2 = Ticker; 
  C2 = ROC(<FONT 
  color=#0000ff size=1>Foreign(Ticker2,<FONT 
  color=#ff00ff size=1>"C"),<FONT color=#ff00ff 
  size=1>1); 
  Corr = Correlation<FONT 
  size=1>(C1, C2, 8 ); 

  Color = IIf<FONT 
  size=1>(Corr>0<FONT face=Verdana 
  color=#ff00ff size=1>.7,<FONT color=#ff00ff 
  size=1>8,4<FONT 
  size=1>); // Add colors to make a heat map 
  
  AddColumn<FONT 
  size=1>(Corr,Ticker,1.3<FONT 
  size=1>,1,Color); 
  }
   
  <BLOCKQUOTE 
  >
    ----- Original Message ----- 
    <DIV 
    >From: 
    Herman 
    vandenBergen 
    To: <A title=amibroker@xxxxxxxxxxxxxxx 
    href="">amibroker@xxxxxxxxxxxxxxx 
    Sent: Wednesday, November 26, 2003 
    11:43 PM
    Subject: RE: [amibroker] to TOMASZ: how 
    to loop through a list of tickers ?
    
    <FONT face=Arial color=#0000ff 
    size=2>A slight oversight in my previous code, you CAN list tickers 
    by name (no string array needed) in the left most column with 
    the slightly different code below. Here is a fragment of the table. 
    Include file can be found in previous post.
    <FONT face=Arial color=#0000ff 
    size=2> 
    <IMG alt="" hspace=0 
    src="" align=baseline 
    border=0>
    <FONT face=Arial color=#0000ff 
    size=2> 
    <FONT face=Arial color=#000000 
    size=2>// N100 Correlation table<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>; StkNum = Status<FONT 
    color=#000000>(<FONT 
    color=#ff00ff>"StockNum"<FONT 
    size=2>); <FONT 
    color=#ff0000>Filter = <FONT 
    color=#0000ff>Status(<FONT 
    color=#ff00ff>"LastBarInTest") <FONT 
    color=#ff0000>AND StkNum < <FONT 
    color=#ff00ff>50<FONT 
    color=#000000>; AddTextColumn<FONT 
    color=#000000>(Name<FONT 
    color=#000000>(),"Ticker"<FONT 
    color=#000000>,1.0<FONT 
    face=Arial>); n = StkNum; 
    #include<FONT 
    face=Arial> <NtoN100Ticker.afl> 
    Ticker1 = Ticker; C1 = <FONT 
    color=#0000ff>Foreign(Ticker1,<FONT 
    color=#ff00ff>"C"<FONT 
    color=#000000>);    <FONT 
    color=#ff0000>for(m=<FONT 
    color=#ff00ff>50;m<=<FONT 
    color=#ff00ff>99<FONT 
    color=#000000>;m++)    {    n=m; 
       <FONT 
    color=#ff0000>#include<FONT 
    size=2> <NtoN100Ticker.afl> 
       Ticker2 = Ticker;    C2 = 
    Foreign<FONT 
    color=#000000>(Ticker2,<FONT 
    color=#ff00ff>"C"<FONT 
    color=#000000>);       Corr = <FONT 
    color=#0000ff>Correlation(C1, C2, <FONT 
    color=#ff00ff>8<FONT 
    color=#000000> );    Color = <FONT 
    color=#0000ff>IIf(Corr><FONT 
    color=#ff00ff>0,<FONT 
    color=#ff00ff>8,<FONT 
    color=#ff00ff>4); <FONT 
    color=#000000>// Add colors to make a heat 
    map<FONT 
    color=#000000>    <FONT 
    color=#0000ff>AddColumn(Corr,Ticker,<FONT 
    color=#ff00ff>1.3,<FONT 
    color=#ff00ff>1<FONT 
    color=#000000>,Color);    <FONT 
    color=#0000ff>}
    
      <FONT face=Tahoma 
      size=2>-----Original Message-----From: dirk schreiber 
      [mailto:tianatrading@xxxxxxxxx]Sent: November 27, 2003 2:03 
      AMTo: amibroker@xxxxxxxxxxxxxxxSubject: [amibroker] 
      to TOMASZ: how to loop through a list of tickers ?
      i'm a bit surprised to see 
      that noone is answering my call.
      so may i ask you directly, 
      tomasz, if what i asked is possible and if you could indicate me the right 
      way to code this ??
       
      thank you,
       
      dirk
       
      <BLOCKQUOTE 
      >
        ----- Original Message ----- 
        <DIV 
        >From: 
        <A title=tianatrading@xxxxxxxxx 
        href="">dirk schreiber 
        To: <A 
        title=amibroker@xxxxxxxxxxxxxxx 
        href="">amibroker@xxxxxxxxxxxxxxx 
        
        Sent: Monday, November 24, 2003 
        12:14 PM
        Subject: Re: [amibroker] how to 
        loop through a list of tickers ?
        
        noone ???
        i'll try again: as an 
        example, is it possible to calculate all correlations of the stocks 
        constituting the nasdaq100 in one scan?
        my code below will explore 
        the correlations of IBM with the other 99 constituents of my 
        nasdaq100 watchlist. is there a way in afl to tell amibroker to first 
        calculate these correlations for one stock, then go to the next and do 
        the same there and so forth, so that i could find out the 10 highest 
        correlations within the nasdaq100 for example ??
        i have tried many ideas but 
        i am stuck (haven't mastered the new loop formulas very well yet) 
        ...
         
        any help would be greatly 
        appreciated, maybe this procedure would interest other amibroker users 
        as well.
         
        thanks in 
        advance,
         
        dirk
         
        
        pair="IBM";
        x=Foreign<FONT 
        size=1>(pair,"C"<FONT 
        size=1>);
        y=C;
        xpc=ROC<FONT 
        size=1>(x,1);
        ypc=ROC<FONT 
        size=1>(y,1<FONT 
        size=1>);
        Graph0=Correlation<FONT 
        size=1>(xpc,ypc,20<FONT 
        size=1>);
        Graph1=Correlation<FONT 
        size=1>(xpc,ypc,200<FONT 
        size=1>);
        Filter=Graph0<FONT 
        size=1>>0.7 
        AND Graph1<FONT 
        size=1>>0.5<FONT 
        face=Verdana size=1>;<FONT color=#0000ff 
        size=1>
        AddColumn<FONT 
        size=1>(Graph0<FONT 
        size=1>,"Cor20"<FONT 
        color=#000000 size=1>,1.2<FONT 
        size=1>);<FONT color=#0000ff 
        size=1>
        AddColumn<FONT 
        size=1>(Graph1<FONT 
        size=1>,"Cor200"<FONT 
        color=#000000 size=1>,1.2<FONT 
        size=1>);<FONT color=#0000ff 
        size=1>
        AddColumn<FONT 
        size=1>(Graph0<FONT 
        size=1>+Graph1<FONT 
        size=1>,"total"<FONT 
        color=#000000 size=1>,1.2<FONT 
        size=1>);
        Buy=0<FONT 
        size=1>;<FONT face=Verdana color=#000080 
        size=2>
         
         
        <BLOCKQUOTE 
        >
          ----- Original Message ----- 
          <DIV 
          >From: 
          <A title=tianatrading@xxxxxxxxx 
          href="">dirk schreiber 
          To: <A 
          title=amibroker@xxxxxxxxxxxxxxx 
          href="">amibroker@xxxxxxxxxxxxxxx 
          
          Sent: Thursday, November 20, 2003 
          6:56 PM
          Subject: [amibroker] how to loop 
          through a list of tickers ?
          
          
          hello,
           
          this is my first 
          post.
          i have been working my 
          way into the ideas behind pair trading, reading the interesting posts 
          by yuki a few months ago and writing some code.
          here is where i'm stuck: 
          when i calculate correlation, price ratio and other things like beta 
          ratio it is my understanding that when scanning my database i can only 
          compare one stock at a time with the rest of my universe. -- is it 
          possible to calculate all correlations between all stocks in one 
          scan?? i know that with big groups this would mean millions of 
          calculations, but for a group like the n100 this should be possible? 
          
          can this be done by some 
          sort of loop?
          i searched the mailing 
          list archive and found only one hint by DT, talking about maybe using 
          something like   Status("STOCKNUM") == 0   , but i 
          could not work that out ...
           
          any help is 
          appreciated,
          thanks in 
          advance,
           
          <FONT face=Verdana color=#000080 
          size=2>dirkSend 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!?<A 
          href="">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: <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!?<A 
        href="">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: 
      <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 AddressGuardSend 
    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. 
    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.