Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
function stat_stdevp($data)
{
    // calculates population standard deviation
    return sqrt(stat_varp($data));
}