Title: Re: [amibroker] Re: finding pairs
I started to play but don't have time to finish this. THIS CODE IS NOT FULLY FUNCTIONAL but may give you enough to work with. The idea is to scan the watchlist and compare tickers starting at both ends, stop when they meet. Output the corr when when it exceeds your limit. I wanted to save the values in staticvariables named with the corr value. That allows you to, after the scan, read the to n ticker combos and display/chart them on you chart. The staticvariable go messed up :-) that is you challenge to solve, please post when you fix it. be sure to open the AB log window to see the raw output. It takes a few seconds to scan the N100. You can add price, volume, ROC(), etc. restraints to speed up the program.
I am sure that when users see this approach they will be able to do this much more efficiently, if so please post you solution! That is how we learn around here ;-)
good luck,
herman
// this code is NOT fully functional and needs to be debugged //
WLName = ParamStr( "Selection WL Name", "Nasdaq 100" );
WLNum = CategoryFind( WLName, categoryWatchlist );
Tickerlist = CategoryGetSymbols( categoryWatchlist, WLNum );
Periods = Param( "Correlation Periods", 100, 3, 1000, 1 );
MinCorr = Param( "Minimum Corr", 0.97, -1, 1, 0.01 );
if ( ParamTrigger( "Scan Watchlist", "SCAN" ) )
{
_TRACE( "!CLEAR!" );
_TRACE( "MinCorr: " + NumToStr( MinCorr, 1.2 ) );
TF = 0;
for ( T1 = 0; ( Ticker1 = StrExtract( TickerList , T1 ) ) != ""; T1++ )
{
for ( T2 = 1; ( Ticker2 = StrExtract( TickerList , -T2 ) ) != ""; T2++ )
{
if ( Ticker1 == Ticker2 ) break;
Close1 = Foreign( Ticker1, "C" );
Close2 = Foreign( Ticker2, "C" );
Corr = Correlation( Close1, Close2, Periods );
LastCorr = LastValue( Corr );
Lastcorr = int(100*LastCorr)/100;
if ( LastCorr > MinCorr )
{
TF++;
StaticVarSetText( NumToStr( LastCorr, 1.2,False), Ticker1 + "," +Ticker2 );
_TRACE( NumToStr( TF, 4.0,False ) + ", " + Ticker1 + ", " + Ticker2 + ", Corr: " + NumToStr( LastCorr, 1.2,False ) );
}
}
}
}
BestTickers = "";
for ( Corr = 1, n = 0; Corr >= -1; Corr = Corr - 0.01 )
{
if ( ( Tickercombo = StaticVarGetText( NumToStr( Corr, 1.2, False ) ) != "" ) )
{
if ( n++ >= 2 ) break;
BestTickers = BestTickers + Tickercombo + NumToStr( Corr, 1.2, False ) + "\n";
_TRACE( NumToStr( Corr, 1.2 ) + ", " + Tickercombo );
}
}
Title = "BestTickers: \n"+BestTickers;
Saturday, August 22, 2009, 11:27:49 PM, you wrote:
> I also thought that it may not be possible, as Mike suggested.
> Herman, can you elaborate on how you would use nested loops to save the
> output? I am not exactly clear what you mean by that.
> Thanks,
> ------------------------------------
> **** IMPORTANT PLEASE READ ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
> TO GET TECHNICAL SUPPORT send an e-mail directly to
> SUPPORT {at} amibroker.com
> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> http://www.amibroker.com/feedback/
> (submissions sent via other channels won't be considered)
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
> 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/
__._,_.___
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
__,_._,___
|