PureBytes Links
Trading Reference Links
|
Hello
The following AFL code computes the autocorrelation function from lag 1 to
40 and normalises it with the variance.
Histogram is plotted on the 40 last bars (last bar is lag1, last bar-1 is
lag 2,...).
Autocorrelations are significant when absolute value is bigger than
confidence bands.
Hope you like it
Waz
/* AUTOCORRELATION FUNCTION */
// Logarithmic return
X = log(C/Ref(C,-1));
// Mean
MX = LastValue(Cum(X)/Cum(1));
// Variance
ACF0 = LastValue(Cum((X-MX)*(X-MX))/Cum(1));
// Autocorrelation from lag 1 to 40, normalised to variance
ACF1 = LastValue(Cum((X-MX)*(Ref(X,-1)-MX))/(ACF0*Cum(1)));
ACF2 = LastValue(Cum((X-MX)*(Ref(X,-2)-MX))/(ACF0*Cum(1)));
ACF3 = LastValue(Cum((X-MX)*(Ref(X,-3)-MX))/(ACF0*Cum(1)));
ACF4 = LastValue(Cum((X-MX)*(Ref(X,-4)-MX))/(ACF0*Cum(1)));
ACF5 = LastValue(Cum((X-MX)*(Ref(X,-5)-MX))/(ACF0*Cum(1)));
ACF6 = LastValue(Cum((X-MX)*(Ref(X,-6)-MX))/(ACF0*Cum(1)));
ACF7 = LastValue(Cum((X-MX)*(Ref(X,-7)-MX))/(ACF0*Cum(1)));
ACF8 = LastValue(Cum((X-MX)*(Ref(X,-8)-MX))/(ACF0*Cum(1)));
ACF9 = LastValue(Cum((X-MX)*(Ref(X,-9)-MX))/(ACF0*Cum(1)));
ACF10 = LastValue(Cum((X-MX)*(Ref(X,-10)-MX))/(ACF0*Cum(1)));
ACF11 = LastValue(Cum((X-MX)*(Ref(X,-11)-MX))/(ACF0*Cum(1)));
ACF12 = LastValue(Cum((X-MX)*(Ref(X,-12)-MX))/(ACF0*Cum(1)));
ACF13 = LastValue(Cum((X-MX)*(Ref(X,-13)-MX))/(ACF0*Cum(1)));
ACF14 = LastValue(Cum((X-MX)*(Ref(X,-14)-MX))/(ACF0*Cum(1)));
ACF15 = LastValue(Cum((X-MX)*(Ref(X,-15)-MX))/(ACF0*Cum(1)));
ACF16 = LastValue(Cum((X-MX)*(Ref(X,-16)-MX))/(ACF0*Cum(1)));
ACF17 = LastValue(Cum((X-MX)*(Ref(X,-17)-MX))/(ACF0*Cum(1)));
ACF18 = LastValue(Cum((X-MX)*(Ref(X,-18)-MX))/(ACF0*Cum(1)));
ACF19 = LastValue(Cum((X-MX)*(Ref(X,-19)-MX))/(ACF0*Cum(1)));
ACF20 = LastValue(Cum((X-MX)*(Ref(X,-20)-MX))/(ACF0*Cum(1)));
ACF21 = LastValue(Cum((X-MX)*(Ref(X,-21)-MX))/(ACF0*Cum(1)));
ACF22 = LastValue(Cum((X-MX)*(Ref(X,-22)-MX))/(ACF0*Cum(1)));
ACF23 = LastValue(Cum((X-MX)*(Ref(X,-23)-MX))/(ACF0*Cum(1)));
ACF24 = LastValue(Cum((X-MX)*(Ref(X,-24)-MX))/(ACF0*Cum(1)));
ACF25 = LastValue(Cum((X-MX)*(Ref(X,-25)-MX))/(ACF0*Cum(1)));
ACF26 = LastValue(Cum((X-MX)*(Ref(X,-26)-MX))/(ACF0*Cum(1)));
ACF27 = LastValue(Cum((X-MX)*(Ref(X,-27)-MX))/(ACF0*Cum(1)));
ACF28 = LastValue(Cum((X-MX)*(Ref(X,-28)-MX))/(ACF0*Cum(1)));
ACF29 = LastValue(Cum((X-MX)*(Ref(X,-29)-MX))/(ACF0*Cum(1)));
ACF30 = LastValue(Cum((X-MX)*(Ref(X,-30)-MX))/(ACF0*Cum(1)));
ACF31 = LastValue(Cum((X-MX)*(Ref(X,-31)-MX))/(ACF0*Cum(1)));
ACF32 = LastValue(Cum((X-MX)*(Ref(X,-32)-MX))/(ACF0*Cum(1)));
ACF33 = LastValue(Cum((X-MX)*(Ref(X,-33)-MX))/(ACF0*Cum(1)));
ACF34 = LastValue(Cum((X-MX)*(Ref(X,-34)-MX))/(ACF0*Cum(1)));
ACF35 = LastValue(Cum((X-MX)*(Ref(X,-35)-MX))/(ACF0*Cum(1)));
ACF36 = LastValue(Cum((X-MX)*(Ref(X,-36)-MX))/(ACF0*Cum(1)));
ACF37 = LastValue(Cum((X-MX)*(Ref(X,-37)-MX))/(ACF0*Cum(1)));
ACF38 = LastValue(Cum((X-MX)*(Ref(X,-38)-MX))/(ACF0*Cum(1)));
ACF39 = LastValue(Cum((X-MX)*(Ref(X,-39)-MX))/(ACF0*Cum(1)));
ACF40 = LastValue(Cum((X-MX)*(Ref(X,-40)-MX))/(ACF0*Cum(1)));
// Store autocorrelation function in the last 40 bars
ACF = 0;
ACF = IIf(Cum(1)==LastValue(Cum(1)),ACF1,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-1,ACF2,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-2,ACF3,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-3,ACF4,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-4,ACF5,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-5,ACF6,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-6,ACF7,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-7,ACF8,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-8,ACF9,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-9,ACF10,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-10,ACF11,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-11,ACF12,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-12,ACF13,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-13,ACF14,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-14,ACF15,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-15,ACF16,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-16,ACF17,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-17,ACF18,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-18,ACF19,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-19,ACF20,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-20,ACF21,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-21,ACF22,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-22,ACF23,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-23,ACF24,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-24,ACF25,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-25,ACF26,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-26,ACF27,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-27,ACF28,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-28,ACF29,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-29,ACF30,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-30,ACF31,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-31,ACF32,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-32,ACF33,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-33,ACF34,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-34,ACF35,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-35,ACF36,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-36,ACF37,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-37,ACF38,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-38,ACF39,ACF);
ACF = IIf(Cum(1)==LastValue(Cum(1))-39,ACF40,ACF);
ACF = 100*ACF;
// Significance bands
Sigma = 100*LastValue(Cum(1))^(-0.5);
GraphXSpace=5;
Graph0=ACF;Graph0Style=2+4;Graph0Color=3;
Graph1=2*Sigma; Graph1Style=1; Graph1Color=2;
Graph2=-2*Sigma; Graph2Style=1; Graph2Color=2;
-----Original Message-----
From: Tomasz Janeczko [mailto:amibroker@x...]
Sent: samedi 13 juillet 2002 11:01
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Corrolation function?
Hello,
Look at the Correlation() function
CORRELATION (AFL 1.4)
SYNTAX correlation( ARRAY1, ARRAY2, periods )
RETURNS ARRAY
FUNCTION Calculates correlation between ARRAY1 and ARRAY2 using periods
range
EXAMPLE correlation( close, ref( close, -5 ), 5 ); - this calculates
correlation between close price and and close price 5 days back
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "John Nelson" <trader@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Saturday, July 13, 2002 2:52 AM
Subject: [amibroker] Corrolation function?
>
> All,
>
> Is there a Matlab-like corrolation function in AFL (or available to
> AFL)? An auto-corrolator would be cool to combined multiple signals to
> yield an aggregate signal (or so the thinking goes). Anyone looked into
> this sort of thing?
>
> -- John
>
> --
> _____________________________________________________
>
> John T. Nelson
> Trader | Dreams Of Empire
> mail: | trader@xxxx
> web: | http://www.dreamsofempire.com/
> _____________________________________________________
> "Prediction is sexy... but strategy makes money"
>
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|