PureBytes Links
Trading Reference Links
|
thanks graham, but sorry i'm too
dumb. i have been trying for the last 2 hours to combine my correlation code
with your code, but could not work it out.
i see how with your code i can show
various rows for one stock referencing a different time for one calculation
(like the short-term correlation for today, yesterday and so forth). what i
would like to achieve though is to have a different calculation for the same
time in every row (for example: show today's short-term correlation and in the
next row show today's mid-term correlation and so forth).
is there a way to do this and where
in the loop would i have to put this code?
thanks,
dirk
<FONT face=Verdana
color=#000080 size=2>
// Correlation Analysis for Single Stock
Buy<FONT face=Verdana
size=2>=Sell=Short=Cover=0;
LastBarInTest = <FONT
color=#0000ff>LastValue(ValueWhen(<FONT
color=#0000ff>Status("LastBarInTest"),<FONT
color=#0000ff>BarIndex()));
Filter = <FONT
color=#0000ff>Status("LastBarInTest");
list = <FONT
color=#0000ff>GetCategorySymbols( categoryWatchlist, <FONT
color=#ff00ff>3 );
timeshort=8;
timemed=63;
timelong=<FONT
color=#ff00ff>252;
for(
NumTickers=0; NumTickers < <FONT
color=#ff00ff>100 AND StrExtract( list,
NumTickers ) != ""; NumTickers++ ); <FONT
color=#0000ff>
AddTextColumn<FONT face=Verdana
size=2>("Corr. short",<FONT
color=#ff00ff>"Filter",<FONT
color=#ff00ff>1.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");
Corrshort = Correlation(
Var1, Var2, timeshort );
Color = IIf(Corrshort
==1,colorBlack,<FONT
color=#0000ff>IIf(Corrshort <-<FONT
color=#ff00ff>0.8,colorRed,<FONT
color=#0000ff>IIf(Corrshort <-<FONT
color=#ff00ff>0.5,colorOrange,<FONT
color=#0000ff>IIf(Corrshort <-<FONT
color=#ff00ff>0.2,colorLightOrange,<FONT
color=#0000ff>IIf(Corrshort <<FONT
color=#ff00ff>0.2,colorCustom9,<FONT
color=#0000ff>IIf(Corrshort <<FONT
color=#ff00ff>0.5,colorAqua,<FONT
color=#0000ff>IIf(Corrshort <<FONT
color=#ff00ff>0.8,colorBrightGreen,colorGreen)))))));
AddColumn(
Corrshort , Ticker2, 1.3, <FONT
color=#ff00ff>1, Color);
}
for(
NumTickers=0; NumTickers < <FONT
color=#ff00ff>100 AND StrExtract( list,
NumTickers ) != ""; NumTickers++ ); <FONT
color=#0000ff>
AddTextColumn<FONT face=Verdana
size=2>("Corr. med",<FONT
color=#ff00ff>"Filter",<FONT
color=#ff00ff>1.0);
for(
Col=0; Col<NumTickers; Col++)
{
Ticker1 = <FONT
color=#000080>Name();
Ticker2 = StrExtract(
list, Col);
Var1 = <FONT
color=#0000ff>Foreign(Ticker1,"C");
Var2 = <FONT
color=#0000ff>Foreign(Ticker2,"C");
Corrmed = Correlation(
Var1, Var2, timemed );
Color = IIf(Corrmed
==1,colorBlack,<FONT
color=#0000ff>IIf(Corrmed <-<FONT
color=#ff00ff>0.8,colorRed,IIf(Corrmed
<-0.5,colorOrange,<FONT
color=#0000ff>IIf(Corrmed <-<FONT
color=#ff00ff>0.2,colorLightOrange,<FONT
color=#0000ff>IIf(Corrmed <<FONT
color=#ff00ff>0.2,colorCustom9,<FONT
color=#0000ff>IIf(Corrmed <<FONT
color=#ff00ff>0.5,colorAqua,IIf(Corrmed
<<FONT
color=#ff00ff>0.8,colorBrightGreen,colorGreen)))))));
AddColumn(
Corrmed , Ticker2, 1.3, 1,
Color);
} <FONT face=Verdana
size=2>----- Original Message -----
<BLOCKQUOTE
>
<FONT
face=Verdana>From: <A title=gkavanagh@xxxxxxxxxxxxx
href=""><FONT
face=Verdana>Graham
To: <A
title=amibroker@xxxxxxxxxxxxxxx href=""><FONT
face=Verdana>amibroker@xxxxxxxxxxxxxxx
Sent: Thursday,
December 11, 2003 12:34 AM
Subject: RE:
[amibroker] one-stock exploration with various rows
Yes, I did email
out an example of how to do this last week
set the filter
in aa window to n=2 last quotations
This is an
example for 3 sets of data, just put your results variables in place of
mine
<FONT face=Verdana
size=2>
<FONT face=Verdana
size=2>
bar = BarCount - 1 - BarIndex();
x[BarCount-3] = LastValue(
AvMinorRFMovePercentAll );y[BarCount-3] = LastValue(
AvMinorRFPullbackPercentAll );x[BarCount-2] = LastValue(
AvMinorFRMovePercentAll );y[BarCount-2] = LastValue(
AvMinorFRPullbackPercentAll );x[BarCount-1] = LastValue(
AvMinorFFMovePercentAll );y[BarCount-1] = LastValue(
AvMinorFFPullbackPercentAll );
A1 = ValueWhen( bar, BarCount-1 );A2 =
ValueWhen( bar, BarCount-2 );A3 = ValueWhen( bar, BarCount-3
);
Filter = BarIndex()==A1 OR BarIndex()==A2
OR BarIndex()==A3;
<SPAN
class=994282923-10122003>
AddColumn( x,
"M("+Price[LowLevel]+"-"+Price[HighLevel]+")", 1.1 );
AddColumn( y,
"P("+Price[LowLevel]+"-"+Price[HighLevel]+")", 1.1 );
Cheers,Graham<A
href=""><FONT face=Verdana
size=2>http://groups.msn.com/asxsharetrading<A
href=""><FONT face=Verdana
size=2>http://groups.msn.com/fmsaustralia
<FONT
face=Verdana size=2>-----Original Message-----From: dirk
schreiber [mailto:tianatrading@xxxxxxxxx] Sent: Thursday, 11
December 2003 7:06 AMTo:
amibroker@xxxxxxxxxxxxxxxSubject: [amibroker] one-stock
exploration with various rows
still trying to find a better
way to code my pair trading approach:
would it be possible to do an
explore with various loops against one ticker and then visualize this in aa
with various rows? the following code calculates both short- and mid-term
correlation of one stock against a watchlist. the way it is written, it
gives the result in one row, first short-term then mid-term. -- is there a
way to code so that those two rows would show one beneath the other ??
any help appreciated, thanks so
far,
dirk
<BLOCKQUOTE
>
----- Original Message
-----
<DIV
><FONT
face=Verdana>From: <A title=tianatrading@xxxxxxxxx
href="">dirk
schreiber
To: <A
title=amibroker@xxxxxxxxxxxxxxx
href=""><FONT
face=Verdana>amibroker@xxxxxxxxxxxxxxx
Sent: Wednesday,
December 10, 2003 11:12 AM
Subject: Re:
[amibroker] CORRELATION MATRIX: filter within loop ?
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
><FONT
face=Verdana>From: <A title=psytek@xxxxxxxx
href="">Herman
vandenBergen
To: <A
title=amibroker@xxxxxxxxxxxxxxx
href=""><FONT
face=Verdana>amibroker@xxxxxxxxxxxxxxx
Sent: Tuesday,
December 09, 2003 1:01 PM
Subject: RE:
[amibroker] CORRELATION MATRIX: filter within loop ?
<FONT face=Verdana color=#0000ff
size=2>Forgot Yahoo doesn't
attach files anymore, here is the
code:
<FONT face=Verdana color=#0000ff
size=2><SPAN
class=570355911-09122003>
<SPAN
class=570355911-09122003><FONT face=Verdana color=#000000
size=2>// THIS WILL ONLY WORK CORRECTLY EXPLORING THE CURRENT
STOCK AGAINST THE<FONT
color=#000000> // WATCHLIST
SELECTED IN THE GetCategorySymbols()
!!!!!<FONT
color=#000000> // Exploration to
create Correlation matrix<FONT
size=2> <FONT
color=#ff0000>Buy<FONT
color=#000000>=<FONT
color=#ff0000>Sell<FONT
color=#000000>=<FONT
color=#ff0000>Short<FONT
color=#000000>=<FONT
color=#ff0000>Cover<FONT
color=#000000>=0<FONT
size=2>; LastBarInTest =
LastValue<FONT
color=#000000>(ValueWhen<FONT
color=#000000>(Status<FONT
color=#000000>("LastBarInTest"<FONT
color=#000000>),<FONT
color=#0000ff>BarIndex<FONT
face=Verdana>())); <FONT
color=#ff0000>Filter =
Status<FONT
color=#000000>(<FONT
color=#ff00ff>"LastBarInTest"<FONT
face=Verdana>); list = <FONT
color=#0000ff>GetCategorySymbols(
<FONT
color=#ff0000>categoryWatchlist<FONT
color=#000000>, 0<FONT
size=2> ); <FONT
color=#ff0000>for(
NumTickers=0;
NumTickers < 100<FONT
color=#000000> <FONT
color=#ff0000>AND
StrExtract( list,
NumTickers ) != ""<FONT
size=2>; NumTickers++ );
IIf<FONT
color=#000000>(C<FONT
color=#000000>>50<FONT
color=#000000>,AddTextColumn<FONT
color=#000000>(Name<FONT
color=#000000>(),"Ticker"<FONT
color=#000000>,1.0<FONT
color=#000000>),0<FONT
size=2>); <FONT
color=#ff0000>for(
Col=0<FONT
face=Verdana>; Col<NumTickers; Col++) {
Ticker1 = <FONT
color=#0000ff>Name<FONT
face=Verdana>(); Ticker2 = <FONT
color=#0000ff>StrExtract<FONT
face=Verdana>( list, Col); Var1 =
Foreign<FONT
color=#000000>(Ticker1,<FONT
color=#ff00ff>"C"<FONT
face=Verdana>); Var2 = <FONT
color=#0000ff>Foreign(Ticker2,<FONT
color=#ff00ff>"C"<FONT
face=Verdana>); Corr = <FONT
color=#0000ff>Correlation( Var1, Var2,
8<FONT
face=Verdana> ); Color = <FONT
color=#0000ff>IIf(Corr==<FONT
color=#ff00ff>1,<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>)))))));
if<FONT
color=#000000>( Corr[LastBarInTest] > <FONT
color=#ff00ff>0.75 ) <FONT
color=#0000ff>AddColumn( Corr, Ticker2,
1.3, <FONT
color=#ff00ff>1<FONT
face=Verdana size=2>, Color); }
<FONT face=Verdana color=#0000ff
size=2>
<FONT face=Verdana color=#0000ff
size=2>
<FONT face=Verdana 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=Verdana
color=#0000ff size=2>
<FONT face=Verdana
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=Verdana
color=#0000ff size=2>
<FONT face=Verdana
size=2>LastBarInTest = LastValue<FONT
color=#000000>(ValueWhen<FONT
color=#000000>(Status<FONT
color=#000000>("LastBarInTest"<FONT
color=#000000>),BarIndex<FONT
color=#000000>()));
<FONT face=Verdana
size=2>....
<FONT
face=Verdana>if(
Corr[LastBarInTest] > 0.75<FONT
color=#000000> ) AddColumn<FONT
color=#000000>( Corr, Ticker2, <FONT
color=#ff00ff>1.3, <FONT
color=#ff00ff>1, Color);
<FONT face=Verdana
size=2>
<FONT face=Verdana
size=2>herman.
<FONT face=Verdana
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=Verdana
size=2>=Sell=Short=Cover=<FONT
color=#ff00ff>0;
Filter<FONT face=Verdana
size=2> = Status(<FONT
color=#ff00ff>"LastBarInTest");
list = <FONT
color=#0000ff>GetCategorySymbols( categoryWatchlist,
3 );
for<FONT face=Verdana
size=2>( NumTickers=0; NumTickers
< 100 AND StrExtract( list,
NumTickers ) != ""; NumTickers++ );
IIf<FONT face=Verdana
size=2>(C>50,<FONT
color=#0000ff>AddTextColumn(<FONT
color=#0000ff>Name(),"Ticker",<FONT
color=#ff00ff>1.0),0);
for<FONT face=Verdana
size=2>( Col=0; Col<NumTickers; Col++)
{
Ticker1 = <FONT
color=#0000ff>Name();
Ticker2 = <FONT
color=#0000ff>StrExtract( list, Col);
Var1 = <FONT
color=#0000ff>Foreign(Ticker1,"C");
Var2 = <FONT
color=#0000ff>Foreign(Ticker2,"C");
Corr = <FONT
color=#0000ff>Correlation( Var1, Var2, <FONT
color=#ff00ff>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)))))));
<FONT
color=#0000ff>AddColumn( Corr, Ticker2, <FONT
color=#ff00ff>1.3, 1, Color);
} <FONT
face=Verdana size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend
SUGGESTIONS to
suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web
page: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana
size=2>--------------------------------------------Check group FAQ
at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject
to the Yahoo! Terms of
Service.
Do you Yahoo!?<A
href=""><FONT face=Verdana
size=2>Protect your identity with Yahoo! Mail
AddressGuard<FONT face=Verdana
size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to
suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web
page: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana
size=2>--------------------------------------------Check group FAQ
at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject to
the 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=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana
size=2>--------------------------------------------Check group FAQ
at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject to
the Yahoo! Terms of
Service. <FONT face=Verdana
size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to
suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page:
<FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana size=2>--------------------------------------------Check
group FAQ at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject to
the Yahoo! Terms of
Service.
Do you Yahoo!?<A
href=""><FONT face=Verdana
size=2>Protect your identity with Yahoo! Mail
AddressGuard<FONT face=Verdana
size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to
suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page:
<FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana size=2>--------------------------------------------Check
group FAQ at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject to the
Yahoo! Terms of
Service.
Do you Yahoo!?<A
href=""><FONT face=Verdana
size=2>Protect your identity with Yahoo! Mail
AddressGuard<FONT
face=Verdana size=2>Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS
to suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page:
<FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amiquote/messages/)<FONT
face=Verdana size=2>--------------------------------------------Check
group FAQ at: <A
href=""><FONT
face=Verdana
size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT
face=Verdana size=2> Your use of Yahoo! Groups is subject to the
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
|