OnBalanceVolumeIndicator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 33
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 21 5
1
<?php
2
3
namespace Laratrade\Indicators;
4
5
use Illuminate\Support\Collection;
6
use Laratrade\Indicators\Contracts\Indicator;
7
use Laratrade\Indicators\Exceptions\NotEnoughDataException;
8
use Throwable;
9
10
class OnBalanceVolumeIndicator implements Indicator
11
{
12
    /**
13
     * Invoke the indicator.
14
     *
15
     * @param Collection $ohlcv
16
     *
17
     * @return int
18
     *
19
     * @throws Throwable
20
     */
21
    public function __invoke(Collection $ohlcv): int
22
    {
23
        $obv = trader_obv(
24
            $ohlcv->get('close'),
25
            $ohlcv->get('volume')
26
        );
27
28
        throw_unless($obv, NotEnoughDataException::class);
29
30
        $currentValue = array_pop($obv);
31
        $priorValue   = array_pop($obv);
32
        $earlierValue = array_pop($obv);
33
34
        if (($currentValue > $priorValue) && ($priorValue > $earlierValue)) {
35
            return static::BUY;
36
        } elseif (($currentValue < $priorValue) && ($priorValue < $earlierValue)) {
37
            return static::SELL;
38
        }
39
40
        return static::HOLD;
41
    }
42
}
43