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

Re: [amibroker] Correlation clusters



PureBytes Links

Trading Reference Links

orionsturtle wrote:
>
> I am running the following code (which I did not write) to create a
> correlation matrix with an exploration. It works great.
>
> What I want AB to do next though is to sift out all the symbols that
> that meet a certian correlation criteria and put them in a new
> watchlist.
>
> ie. Sift or pool all symbols that have a correlation < 1.00 and
> > .75. and "catagoryaddsymbol function" them into a new watchlist.
>
> Can anybody add a few lines of code to pull the correlated symbols
> and put them in a new watchlist?
>
> I will post the results in the AFL library giving you full credit. I
> think a lot of users would benifit from this.
>
> Thanks for your consideration!!!
>
> Here's the Matrix code...
>
> /*This is the formula to create a correlation matrix in AB.
> It is set up to run the correlation of the symbols in Watchlist 2
> with the "define" filter catagory in the auto-analyser. In this
> default case
> this code will correlate the symbols in watchlist 2 with the symbols
> in watchlist 2.
> - Tools -> Send to Analysis
> - press FILTER button and select Watchlist 2 in INCLUDE tab
> - press EXPLORE button in AA window.*/
>
> symlist = CategoryGetSymbols( categoryWatchlist, 2 );
> Filter = Status("lastbarinrange");
> for( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
> {
> Corr = Correlation( C, Foreign( sym, "C" ), 252 );
> Clr = 32 + SelectedValue( Corr ) * 32;
> AddColumn( Corr, sym, 1.2, ColorHSB( 128+Clr, 255, 255 ) , ColorHSB(
> Clr, 255, 255 ) );
> }
>
>  
Hi!
Correlated symbols in a new watchlist:
WList_NO_In = Param("WatchList In # ",2,0,100,1);
WList_NO_Out = Param("WatchList Out # ",60,0,100,1);
CorrParam1 =  Param("Corr 1  ",0,-1,1,0.1);
CorrParam2 =  Param("Corr 2  ",0,-1,1,0.1);
symlist = CategoryGetSymbols( categoryWatchlist, WList_NO_In );

/*"Filter"controls which quotes are accepted,
if 1/true is assigned to that variable for a given symbol/quote
it will be displayed in the report.
"Status" returns run-time status of the analysis engine.
"Lastbarinrange" returns a 1(or true) on the last bar of the analysis
range*/
Filter = Status("lastbarinrange");
LastBar = LastValue( BarIndex() );
/*"StrExtract" exracts a given item (substring from a comma-seperated 
list of items.
This "for" statement says to pull the first symbol in the "symlist" that 
is not =
to a blank space.*/

for( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
  /*"Run a 252 day correlation of the current symbol's close " */
  Corr = Correlation( C, Foreign( sym, "C" ), 252 );
  if ( Corr[LastBar] <= CorrParam1 AND Corr[LastBar] >= CorrParam2 )
      
       CategoryAddSymbol(Sym, categoryWatchlist, WList_NO_Out);
  /*Color things real pretty like.*/
  Clr = 32 + SelectedValue( Corr ) * 32;
  AddColumn( Corr, sym, 1.2, ColorHSB( 128+Clr, 255, 255 ) , 
ColorHSB(Clr, 255, 255 ) );
}


------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/