Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: trader_linearreg_slope - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: trader_linearreg_slope

2025-06-03

trader_linearreg_slope

(PECL trader >= 0.2.0)

trader_linearreg_slopeLinear Regression Slope

说明

trader_linearreg_slope(array $real, int $timePeriod = ?): array

参数

real

浮点数数组。

timePeriod

Number of period. Valid range from 2 to 100000.

返回值

Returns an array with calculated data or false on failure.

添加备注

用户贡献的备注 2 notes

up
11
Angel J. Salinas
9 years ago
// 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;
}
up
3
Angel J. Salinas
5 years ago
Default value of precision in trader library is 3, but can be increased easily with something like this:

ini_set( 'trader.real_precision', '6' );

官方地址:https://www.php.net/manual/en/function.trader-linearreg-slope.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3