PHP中的指数移动平均线

编程入门 行业动态 更新时间:2024-10-27 02:27:53
本文介绍了PHP中的指数移动平均线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用PHP计算EMA(指数移动平均线)值.

I want to calculate the EMA (Exponential Moving Average) value in PHP.

我尝试使用以下代码,但它给了我500错误.

I've tried with following code but it's giving me 500 error.

$real = array(12,15,17,19,21,25,28,12,15,16); $timePeriod = 3; $data = trader_ema($real,$timePeriod); var_dump($data);

PHP:EMA计算功能 trader-ema

PHP: EMA calculation function trader-ema

尝试了长时间的Google搜索,但在PHP中对此没有任何帮助.因此,我不知道要计算EMA值需要做什么.

Tried with long time Googling but not getting any help on this in PHP. So, I've no clue what needs to be done to calculate the EMA value.

编辑-1:已安装的扩展程序

我已经安装了所有必需的扩展,现在我得到了输出.但这似乎没有提供适当的输出.

I've installed all the necessary extensions, Now I am getting the output. But it doesn't seems giving proper output.

我认为PHP用于计算EMA的功能无法正常工作.在这方面的任何帮助将不胜感激.

I think PHP function for calculating EMA is not working properly. Any help in this would be greatly appreciated.

推荐答案

我建议使用以下数学库:github/markrogoyski/math-php

I recommend to use the math library from: github/markrogoyski/math-php

public static function exponentialMovingAverage(array $numbers, int $n): array { $m = count($numbers); $α = 2 / ($n + 1); $EMA = []; // Start off by seeding with the first data point $EMA[] = $numbers[0]; // Each day after: EMAtoday = α⋅xtoday + (1-α)EMAyesterday for ($i = 1; $i < $m; $i++) { $EMA[] = ($α * $numbers[$i]) + ((1 - $α) * $EMA[$i - 1]); } return $EMA; }

更多推荐

PHP中的指数移动平均线

本文发布于:2023-10-15 02:27:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平均   指数   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!