note 118790 added to function.trader-linearreg-slope
| From: | AngelJ.Salinas | Date: | Sat, 06 Feb 2016 11:26:37 +0000 |
| Subject: | note 118790 added to function.trader-linearreg-slope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204886@lists.php.net to get a copy of this message | ||
// If you don't have the php_trader library or needs more than 3 precision digits,
// you can use this function:
public static function linearreg_slope( $valuesIn, $period )
{
$valuesOut = array();
$startIdx = 0;
$endIdx = count($valuesIn) - 1;
$sumX = $period * ( $period - 1 ) * 0.5;
$sumXSqr = $period * ( $period - 1 ) * ( 2 * $period - 1 ) / 6;
$divisor = $sumX * $sumX - $period * $sumXSqr;
for ( $today = $startIdx, $outIdx = 0; $today <= $endIdx; $today++, $outIdx++ )
{
$sumXY = 0;
$sumY = 0;
if ( $today >= $period - 1 ) {
for( $aux = $period; $aux-- != 0; )
{
$sumY += $tempValue = $valuesIn[$today - $aux];
$sumXY += (double)$aux * $tempValue;
}
$valuesOut[$outIdx] = ( $period * $sumXY - $sumX * $sumY) / $divisor;
}
}
return $valuesOut;
}
----
Server IP: 72.52.91.14
Probable Submitter: 85.251.188.122
----
Manual Page -- http://php.net/manual/en/function.trader-linearreg-slope.php
Edit -- https://master.php.net/note/edit/118790
Del: integrated -- https://master.php.net/note/delete/118790/integrated
Del: useless -- https://master.php.net/note/delete/118790/useless
Del: bad code -- https://master.php.net/note/delete/118790/bad+code
Del: spam -- https://master.php.net/note/delete/118790/spam
Del: non-english -- https://master.php.net/note/delete/118790/non-english
Del: in docs -- https://master.php.net/note/delete/118790/in+docs
Del: other reasons-- https://master.php.net/note/delete/118790
Reject -- https://master.php.net/note/reject/118790
Search -- https://master.php.net/manage/user-notes.php