-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
367 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: SSL | ||
name: MFI | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Romulodl; | ||
|
||
class Mfi | ||
{ | ||
/** | ||
* Calculate the Money Flow Index | ||
* | ||
*/ | ||
public function calculate(array $hlcv_values) : float | ||
{ | ||
if (empty($hlcv_values)) { | ||
throw new \Exception('[' . __METHOD__ . '] values parameters is invalid'); | ||
} | ||
|
||
$pos_money_flow = 0; | ||
$neg_money_flow = 0; | ||
$prev_typical_price = 0; | ||
foreach ($hlcv_values as $val) { | ||
if (!$this->isValidValue($val)) { | ||
throw new \Exception('[' . __METHOD__ . '] invalid HLC value'); | ||
} | ||
|
||
$typical_price = $this->getTypicalPrice($val[0], $val[1], $val[2]); | ||
|
||
if ($typical_price > $prev_typical_price) { | ||
$pos_money_flow += $typical_price * $val[3]; | ||
} elseif ($typical_price < $prev_typical_price) { | ||
$neg_money_flow += $typical_price * $val[3]; | ||
} | ||
|
||
$prev_typical_price = $typical_price; | ||
} | ||
|
||
return 100 - 100/(1 + $pos_money_flow / $neg_money_flow); | ||
} | ||
|
||
private function getTypicalPrice($high, $low, $close) { | ||
return ($high + $low + $close) / 3; | ||
} | ||
|
||
private function isValidValue($values) : bool | ||
{ | ||
return is_array($values) && | ||
count($values) === 4 && | ||
is_numeric($values[0]) && | ||
is_numeric($values[1]) && | ||
is_numeric($values[2]) && | ||
is_numeric($values[3]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.