Correlation
- correlation

Statistical functions
(AFL 1.4)


SYNTAX correlation( ARRAY1, ARRAY2, periods )
RETURNS ARRAY
FUNCTION Calculates correlation between ARRAY1 and ARRAY2 using periods range

For more information about correlation please check this:

http://en.wikipedia.org/wiki/Correlation

EXAMPLE // the line below calculates
// Correlation between Close price AND AND Close price 5 days back
Correlation( Close, Ref( Close, -5 ), 5 );

// Built-in correlation can be re-coded with
// basic AFL functions like MA (moving average) - which
// is equivalent for "expected value" statistic term
// and few basic arithmetic operations

function Correl( x, y, number )
{
nom=
MA( x * y, number ) - MA( x, number ) * MA( y, number );
denom =
sqrt( MA( x ^ 2, number ) - MA( x, number ) ^ 2 ) *
sqrt( MA( y ^ 2, number ) - MA( y, number ) ^ 2 );
return nom/denom;
}

Graph0=Correlation( C, Ref( H, -2 ), 10 ); // built-in

Graph1=Correl( C, Ref( H, -2 ), 10 ); // re-coded;

SEE ALSO

References:

The Correlation function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference