Skip to content

Commit

Permalink
How about some PSR12 formatting?
Browse files Browse the repository at this point in the history
Except for that Pattern Recognition file. That thing... it's cursed.
  • Loading branch information
jb-lopez committed Aug 29, 2023
1 parent 6e54669 commit cdfecdb
Show file tree
Hide file tree
Showing 18 changed files with 793 additions and 347 deletions.
90 changes: 36 additions & 54 deletions source/LupeTrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LupeCode\phpTraderNative;

use LupeCode\phpTraderNative\TALib\Enum\MovingAverageType;
use LupeCode\phpTraderNative\TALib\Enum\ReturnCode;

class LupeTrader extends Trader
{
Expand Down Expand Up @@ -44,14 +43,14 @@ public static function acos(array $real): array
*/
public static function chaikinAccumulationDistributionLine(array $high, array $low, array $close, array $volume): array
{
$count = self::verifyArrayCounts([$high, $low, $close, $volume]);
$result = new \SplFixedArray($count + 1);
$count = self::verifyArrayCounts([$high, $low, $close, $volume]);
$result = new \SplFixedArray($count + 1);
$moneyFlowVolume = 0.0;
for ($i = 0; $i <= $count; $i++) {
$denominator = $high[$i] - $low[$i];
if ($denominator > 0) {
$moneyFlowMultiplier = (($close[$i] - $low[$i]) - ($high[$i] - $close[$i])) / $denominator;
$moneyFlowVolume += ($moneyFlowMultiplier * $volume[$i]);
$moneyFlowVolume += ($moneyFlowMultiplier * $volume[$i]);
}
$result[$i] = $moneyFlowVolume;
}
Expand Down Expand Up @@ -102,19 +101,19 @@ public static function add(array $real0, array $real1): array
*/
public static function chaikinOscillator(array $high, array $low, array $close, array $volume, int $fastPeriod = 3, int $slowPeriod = 10): array
{
$count = self::verifyArrayCounts([$high, $low, $close, $volume]);
$fastK = 2 / ($fastPeriod + 1);
$slowK = 2 / ($slowPeriod + 1);
$count = self::verifyArrayCounts([$high, $low, $close, $volume]);
$fastK = 2 / ($fastPeriod + 1);
$slowK = 2 / ($slowPeriod + 1);
$oneMinusFastK = 1 - $fastK;
$oneMinusSlowK = 1 - $slowK;

$ad = self::ad($high, $low, $close, $volume);
$ad = self::ad($high, $low, $close, $volume);
$fastEma = $slowEma = $ad[0];
$output = [];
$output = [];

for ($i = 1; $i <= $count; $i++) {
$fastEma = ($fastK * $ad[$i]) + ($oneMinusFastK * $fastEma);
$slowEma = ($slowK * $ad[$i]) + ($oneMinusSlowK * $slowEma);
$fastEma = ($fastK * $ad[$i]) + ($oneMinusFastK * $fastEma);
$slowEma = ($slowK * $ad[$i]) + ($oneMinusSlowK * $slowEma);
$output[$i] = $fastEma - $slowEma;
}

Expand Down Expand Up @@ -150,10 +149,10 @@ public static function adosc(array $high, array $low, array $close, array $volum
*/
public static function averageDirectionalMovementIndex(array $high, array $low, array $close, int $timePeriod = 14): array
{
$count = self::verifyArrayCounts([$high, $low, $close]);
$plus = self::plusDI($high, $low, $close, $timePeriod);
$minus = self::minusDI($high, $low, $close, $timePeriod);
$sum = self::add($plus, $minus);
$count = self::verifyArrayCounts([$high, $low, $close]);
$plus = self::plusDI($high, $low, $close, $timePeriod);
$minus = self::minusDI($high, $low, $close, $timePeriod);
$sum = self::add($plus, $minus);
$result = new \SplFixedArray($count + 1);
for ($i = 0; $i <= $count; $i++) {
$result[$i] = $sum[$i] > 0 ? 100 * abs($plus[$i] - $minus[$i]) / $sum[$i] : 0;
Expand Down Expand Up @@ -194,40 +193,6 @@ public static function minusDI(array $high, array $low, array $close, int $timeP
return self::minus_di($high, $low, $close, $timePeriod);
}

/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/

/**
* Slow Stochastic Relative Strength Index
*
Expand All @@ -251,15 +216,32 @@ public static function slowstochrsi(
int $slowD_Period = 3,
int $slowD_MAType = MovingAverageType::SMA
): array {
$real = \array_values($real);
$real = \array_values($real);
$endIdx = count($real) - 1;
$rsi = [];
$rsi = [];
self::checkForError(self::getMomentumIndicators()::rsi(0, $endIdx, $real, $rsi_period, self::$outBegIdx, self::$outNBElement, $rsi));
$rsi = array_values($rsi);
$endIdx = self::verifyArrayCounts([&$rsi]);
$rsi = array_values($rsi);
$endIdx = self::verifyArrayCounts([&$rsi]);
$outSlowK = [];
$outSlowD = [];
self::checkForError(self::getMomentumIndicators()::stoch(0, $endIdx, $rsi, $rsi, $rsi, $fastK_Period, $slowK_Period, $slowK_MAType, $slowD_Period, $slowD_MAType, self::$outBegIdx, self::$outNBElement, $outSlowK, $outSlowD));
self::checkForError(
self::getMomentumIndicators()::stoch(
0,
$endIdx,
$rsi,
$rsi,
$rsi,
$fastK_Period,
$slowK_Period,
$slowK_MAType,
$slowD_Period,
$slowD_MAType,
self::$outBegIdx,
self::$outNBElement,
$outSlowK,
$outSlowD
)
);

return [
'SlowK' => self::adjustIndexes($outSlowK, self::$outBegIdx),
Expand Down
11 changes: 9 additions & 2 deletions source/LupeTraderFriendly.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ class LupeTraderFriendly extends TraderFriendly
* @return array Returns an array with calculated data. [SlowK => [...], SlowD => [...]]
* @throws \Exception
*/
public static function slowStochasticRelativeStrengthIndex(array $real, int $rsi_period = 14, int $fastK_Period = 5, int $slowK_Period = 3, int $slowK_MAType = MovingAverageType::SMA, int $slowD_Period = 3, int $slowD_MAType = MovingAverageType::SMA)
{
public static function slowStochasticRelativeStrengthIndex(
array $real,
int $rsi_period = 14,
int $fastK_Period = 5,
int $slowK_Period = 3,
int $slowK_MAType = MovingAverageType::SMA,
int $slowD_Period = 3,
int $slowD_MAType = MovingAverageType::SMA
): array {
return LupeTrader::slowstochrsi($real, $rsi_period, $fastK_Period, $slowK_Period, $slowK_MAType, $slowD_Period, $slowD_MAType);
}
}
30 changes: 26 additions & 4 deletions source/TALib/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,19 @@ protected static function validateStartEndIndexes(int $startIdx, int $endIdx): i
return ReturnCode::Success;
}

protected static function TA_INT_PO(int $startIdx, int $endIdx, array $inReal, int $optInFastPeriod, int $optInSlowPeriod, int $optInMethod_2, int &$outBegIdx, int &$outNBElement, array &$outReal, array &$tempBuffer, bool $doPercentageOutput): int
{
protected static function TA_INT_PO(
int $startIdx,
int $endIdx,
array $inReal,
int $optInFastPeriod,
int $optInSlowPeriod,
int $optInMethod_2,
int &$outBegIdx,
int &$outNBElement,
array &$outReal,
array &$tempBuffer,
bool $doPercentageOutput
): int {
$outBegIdx1 = 0;
$outNbElement1 = 0;
$outBegIdx2 = 0;
Expand Down Expand Up @@ -178,8 +189,19 @@ protected static function TA_INT_PO(int $startIdx, int $endIdx, array $inReal, i
return $ReturnCode;
}

protected static function TA_INT_MACD(int $startIdx, int $endIdx, array $inReal, int $optInFastPeriod, int $optInSlowPeriod, int $optInSignalPeriod_2, int &$outBegIdx, int &$outNBElement, array &$outMACD, array &$outMACDSignal, array &$outMACDHist): int
{
protected static function TA_INT_MACD(
int $startIdx,
int $endIdx,
array $inReal,
int $optInFastPeriod,
int $optInSlowPeriod,
int $optInSignalPeriod_2,
int &$outBegIdx,
int &$outNBElement,
array &$outMACD,
array &$outMACDSignal,
array &$outMACDHist
): int {
//double[] $slowEMABuffer;
//double[] $fastEMABuffer;
//double $k1, $k2;
Expand Down
12 changes: 10 additions & 2 deletions source/TALib/Core/Lookback.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,16 @@ public static function sarLookback(float $optInAcceleration, float $optInMaximum
return 1;
}

public static function sarExtLookback(float $optInStartValue, float $optInOffsetOnReverse, float $optInAccelerationInitLong, float $optInAccelerationLong, float $optInAccelerationMaxLong, float $optInAccelerationInitShort, float $optInAccelerationShort, float $optInAccelerationMaxShort): int
{
public static function sarExtLookback(
float $optInStartValue,
float $optInOffsetOnReverse,
float $optInAccelerationInitLong,
float $optInAccelerationLong,
float $optInAccelerationMaxLong,
float $optInAccelerationInitShort,
float $optInAccelerationShort,
float $optInAccelerationMaxShort
): int {
if ($optInStartValue == (-4e+37)) {
$optInStartValue = 0.000000e+0;
} elseif (($optInStartValue < -3.000000e+37) || ($optInStartValue > 3.000000e+37)) {
Expand Down
Loading

0 comments on commit cdfecdb

Please sign in to comment.