Skip to main content

Correlation Table for Amibroker (AFL)

genkumag over 14 years ago Amibroker (AFL)

  • Rating:
    4 / 5 (Votes 7)
  • Tags:
    amibroker, exploration

Using the analysis feature in Amibroker, one can compare degree of correlations between and across securities found in a filtered watch list. This Amibroker code was prepared by the Quanting Dutchman last year.

Just edit the CorrPd line in the formula and specify the period of correlation you’re trying to analyse.

Screenshots

Indicator / Formula

Copy & Paste Friendly
// eCorrelationTable.afl
WLNum = Param("WatchlistNr",0,0,255,1);
CorrPd = 21;
list = GetCategorySymbols( categoryWatchlist, WLNum);
SetOption("NoDefaultColumns",True);

Filter = DateNum()==Status("rangetodate");
//SetSortColumns( 2 );
AddTextColumn(Name(),"Corr("+NumToStr(Corrpd,1.0)+")",1.0,width=70);
Ticker1= Name();

for( Col=0; (Ticker2=StrExtract( List, Col))!= ""; Col++)
{
 Var2 = Foreign(Ticker2,"C");
 Corr = Correlation( C/Ref(C,-1), Var2/Ref(Var2,-1), CorrPd);
 Color = IIf(Corr>0.5, colorLime, IIf(Corr>0,colorBrightGreen,IIf(Corr<-0.5, colorRed,IIf(Corr<0,colorOrange,colorWhite))));
 Color = IIf(Ticker1==Ticker2, 1, color);
 AddColumn( Corr, Ticker2, 1.3, 1, Color,width=60);
}

2 comments

2. 13oct08
over 12 years ago

What type of co-relations we are talking about, metal stocks to companies using those metals? and automobile companies? Something like that?

Leave Comment

Please login here to leave a comment.