Completed
Pull Request — master (#3)
by
unknown
01:16
created

MoneyFlowIndexIndicator::__invoke()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 15

Duplication

Lines 24
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 24
loc 24
ccs 0
cts 15
cp 0
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 15
nc 4
nop 2
crap 20
1
<?php
2
3
namespace Laratrade\Indicators;
4
5
use Illuminate\Support\Collection;
6
use Laratrade\Indicators\Contracts\Indicator;
7
use Laratrade\Indicators\Exceptions\NotEnoughDataPointsException;
8
9
10
/**
11
 * Money Flow Index
12
 *
13
 * @see https://www.investopedia.com/terms/m/mfi.asp
14
 *
15
 * What is the 'Money Flow Index - MFI'
16
 * 
17
 * The money flow index (MFI) is a momentum indicator that measures the inflow and 
18
 * outflow of money into a security over a specific period of time. The MFI uses a 
19
 * stock's price and volume to measure trading pressure. Because the MFI adds trading 
20
 * volume to the relative strength index (RSI), it's sometimes referred to as volume-weighted RSI. 
21
 * 
22
 *
23
 */
24 View Code Duplication
class MoneyFlowIndexIndicator implements Indicator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
    public function __invoke(Collection $ohlcv, int $period = 14): int
27
    {
28
        $mfi = trader_mfi(
29
            $ohlcv->get('high'),
30
            $ohlcv->get('low'),
31
            $ohlcv->get('close'),
32
            $ohlcv->get('volume'),
33
            $period
34
        );
35
36
        if (false === $mfi) {
37
            throw new NotEnoughDataPointsException('Not enough data points');
38
        }
39
40
        $mfiValue = array_pop($mfi);
41
42
        if ($mfiValue < -10) {
43
            return static::BUY;
44
        } elseif ($mfiValue > 80) {
45
            return static::SELL;
46
        }
47
48
        return static::HOLD;
49
    }
50
51
}