Beispiel #1
0
function stat_correlp($data1, $data2)
{
    //calculates the population correlation
    //arrays must be same size
    $covarp = stat_covarp($data1, $data2);
    $stdevp1 = stat_stdevp($data1);
    $stdevp2 = stat_stdevp($data2);
    return $covarp / ($stdevp1 * $stdevp2);
}
Beispiel #2
0
                         //only calculate when 156 weeks of data exist
                         $s[$key][$t][$date] = stat_stdevp($sSlice) * sqrt(52);
                         $i++;
                     }
                 }
             }
             break;
         default:
             $t = 'beta';
             foreach ($s as $key => $stock) {
                 $i = 0;
                 foreach ($stock['changes'] as $date => $change) {
                     $sSlice = array_slice($s[$key]['changes'], $i, 156);
                     if (count($sSlice) >= 156) {
                         //only calculate when 156 weeks of data exist
                         $s[$key][$t][$date] = stat_covarp($sSlice, array_slice($m[0]['changes'], $i, 156)) / stat_varp(array_slice($m[0]['changes'], $i, 156));
                         $i++;
                     }
                 }
             }
     }
     if (count($s) == 1) {
         //if only one stock being analyzed calc percentiles
         $percentiles = true;
         $lowPercentile = stat_percentile($s[0][$t], 0.1);
         $midPercentile = stat_percentile($s[0][$t], 0.5);
         $highPercentile = stat_percentile($s[0][$t], 0.9);
     } else {
         $percentiles = false;
     }
 }