0

我正在尝试获取 aapl 股票图表的累积摆动指数。我正在使用这个计算作为参考。

http://www.barchart.com/education/std_studies.php?what=int_swing&hideheader=true#study

这是我到目前为止所写的。这应该返回 252.09 但我无法让它工作。

$asi[0] = -78.75
$ht = 584; // High today
$lt = 574.25; // low
$ct = 584.00; // close
$ot = 578; // open

$hy = 574; // High yesterday
$ly = 565.61;
$cy = 569.05;
$oy = 571.67;


$k = max(($hy-$ct),($ly-$ct));

$abc = array(($ht-$cy), ($lt-$cy), ($ht-$lt));
$max = max($abc);
$r = 0;
if($max == $abc[0]){
    $r = ($ht-$cy)-.5*($lt-$cy)+.25*($cy-$oy);
}elseif($max == $abc[1]){
    $r = ($lt-$cy)-.5*($ht-$cy)+.25*($cy-$oy);
}elseif($max == $abc[2]){
    $r = ($ht-$lt)+.25*($cy-$oy);
}else{
    echo "Error in welles accumulative swing index";
    exit;
}

$l = 3 //period;

$val = 50 * (($cy - $ct) + .5 *($cy - $oy) + .25*($ct-$ot)) / $r * $k / $l;

$asi[] = $asi[$i-1] + $val;

任何帮助将不胜感激。

4

2 回答 2

2

我试图逐个符号地新实现这个索引并得到不同的结果(swing:-248.7032967033)。可能是您的控制值错误?

那是我的代码:

class Swing
{
    public function calculate($high_price, $low_price, $close_price, $open_price, $t)
    {
        // (Ct-1 - Ct)
        $summand0 = ($close_price[$t-1] - $close_price[$t]);
        // 0.5(Ct-1 - Ot-1)
        $summand1 = 0.5 * ($close_price[$t-1] - $open_price[$t-1]);
        // 0.25(Ct - Ot)
        $summand2 = 0.25 * ($close_price[$t] - $open_price[$t]);

        $limit_move_default = 3.0;

        $r = $this->get_r_value($high_price, $low_price, $close_price, $open_price, $t);
        $k = $this->get_k_value($high_price, $low_price, $close_price, $t);

        $factor0 = 50.0 * ($summand0 + $summand1 + $summand2) / $r;
        $factor1 = $k / $limit_move_default;

        // SWING = 50 * ((Ct-1 - Ct)+ 0.5(Ct-1 - Ot-1)+ 0.25(Ct - Ot))/ R * K / M
        return $factor0 * $factor1;
    }

    public function get_k_value($high_price, $low_price, $close_price, $t)
    {
        // K= MAX(| Ht-Ct-1|, | Lt-Ct-1|)
        return max(
            abs($high_price[$t] - $close_price[$t-1]),
            abs($low_price[$t] - $close_price[$t-1]));
    }

    public function get_r_value($high_price, $low_price, $close_price, $open_price, $t)
    {
        // A. |Ht-Ct-1|
        $a = abs($high_price[$t] - $close_price[$t-1]);
        // B. |Lt-Ct-1|
        $b = abs($low_price[$t] - $close_price[$t-1]);
        // C. |Ht-Lt|
        $c = abs($high_price[$t] - $low_price[$t]);

        $max_value = max($a, $b, $c);

        $d = abs($high_price[$t] - $low_price[$t]);

        if($a == $max_value)
            // R= (| Ht-Ct-1|)-.5(| Lt-Ct-1|)+.25(| Ct-1-Ot-1|)
            return $a - 0.5 *  $b + 0.25 *  $d;

        if($b == $max_value)
            // R= (| Lt-Ct-1|)-.5(| Ht-Ct-1|)+.25(| Ct-1-Ot-1|)
            return  $b - 0.5 * $a + 0.25 *  $d;

        if($c == $max_value)
            // R= (| Ht-Lt|)+.25(| Ct-1-Ot-1|)
            return $c + 0.25 *  $d;
    }
};

$swing = new Swing();

$high_price = array(574.0, 584.0);
$low_price = array(565.61, 574.25);
$close_price = array(569.05, 584.0);
$open_price = array(571.67, 578.0);

$value = $swing->calculate($high_price, $low_price, $close_price, $open_price, 1);
echo("swing: $value \n");
于 2012-10-11T20:13:43.760 回答
0

$d 看起来不对。

应该是 abs($close_price[$t-1] - $open_price[$t-1]);

于 2014-09-03T20:42:17.337 回答