Not to bug you guys but I am curious if this chart looks alright and makes sense:
Index Fund Correlation
Here is part of the code used to generate the correlation data:
Index Fund Correlation
Here is part of the code used to generate the correlation data:
PHP:
// Correlation Calculation
public function correlation($x, $y) {
//Correlation = NSXY - (SX)(SY) / Sqrt([NSX2 - (SX)2][NSY2 - (SY)2])
$Ex;
$Ey;
$Exy;
$Exx;
$Eyy;
$xy = array();
$xx = array();
$yy = array();
$num = count($x);
for ($i = 0; $i < count($x); $i++) {
array_push($xy, $x[$i]*$y[$i]);
array_push($xx, $x[$i]*$x[$i]);
array_push($yy, $y[$i]*$y[$i]);
}
$Ex = array_sum($x);
$Ey = array_sum($y);
$Exy = array_sum($xy);
$Exx = array_sum($xx);
$Eyy = array_sum($yy);
if ($Ex != 0) { // Make sure we are not dividing by 0
$corr = (($num * $Exy) - ($Ex * $Ey)) / sqrt( (($num * $Exx) - pow($Ex,2)) * (($num * $Eyy) - pow($Ey,2)) );
}
$corr = round($corr, 4);
return $corr;
}