Skip to content

Commit

Permalink
Version 2.0.1
Browse files Browse the repository at this point in the history
Fixed #16
Added many missed type changes
  • Loading branch information
jb-lopez committed Oct 9, 2023
1 parent f6d8387 commit b26ed50
Show file tree
Hide file tree
Showing 26 changed files with 1,381 additions and 1,108 deletions.
4 changes: 2 additions & 2 deletions source/LupeTrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public static function slowstochrsi(
int $rsi_period = 14,
int $fastK_Period = 5,
int $slowK_Period = 3,
int $slowK_MAType = MovingAverageType::SMA,
MovingAverageType $slowK_MAType = MovingAverageType::SMA,
int $slowD_Period = 3,
int $slowD_MAType = MovingAverageType::SMA
MovingAverageType $slowD_MAType = MovingAverageType::SMA
): array {
$real = \array_values($real);
$endIdx = count($real) - 1;
Expand Down
4 changes: 2 additions & 2 deletions source/LupeTraderFriendly.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static function slowStochasticRelativeStrengthIndex(
int $rsi_period = 14,
int $fastK_Period = 5,
int $slowK_Period = 3,
int $slowK_MAType = MovingAverageType::SMA,
MovingAverageType $slowK_MAType = MovingAverageType::SMA,
int $slowD_Period = 3,
int $slowD_MAType = MovingAverageType::SMA
MovingAverageType $slowD_MAType = MovingAverageType::SMA
): array {
return LupeTrader::slowstochrsi($real, $rsi_period, $fastK_Period, $slowK_Period, $slowK_MAType, $slowD_Period, $slowD_MAType);
}
Expand Down
37 changes: 22 additions & 15 deletions source/TALib/Classes/CandleSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,42 @@

namespace LupeCode\phpTraderNative\TALib\Classes;

use LupeCode\phpTraderNative\TALib\Enum\CandleSettingType;
use LupeCode\phpTraderNative\TALib\Enum\RangeType;

class CandleSetting
{

/** @var int */
public $settingType;
/** @var int */
public $rangeType;
/** @var int */
public $avgPeriod;
/** @var float */
public $factor;
public int $settingType;
public ?int $rangeType;
public ?int $avgPeriod;
public ?float $factor;

public function __construct(int $settingType, int $rangeType = null, int $avgPeriod = null, float $factor = null)
public function __construct(int|CandleSettingType $settingType, int|RangeType|null $rangeType = null, int $avgPeriod = null, float $factor = null)
{
$this->settingType = $settingType;
$this->rangeType = $rangeType;
$this->avgPeriod = $avgPeriod;
$this->factor = $factor;
if (is_int($settingType)) {
$this->settingType = $settingType;
} else {
$this->settingType = $settingType->value;
}
if (is_int($rangeType) || is_null($rangeType)) {
$this->rangeType = $rangeType;
} else {
$this->rangeType = $rangeType->value;
}
$this->avgPeriod = $avgPeriod;
$this->factor = $factor;
}

public function CopyFrom(CandleSetting $source)
public function CopyFrom(CandleSetting $source): void
{
$this->settingType = $source->settingType;
$this->rangeType = $source->rangeType;
$this->avgPeriod = $source->avgPeriod;
$this->factor = $source->factor;
}

public function CandleSetting(CandleSetting $that)
public function CandleSetting(CandleSetting $that): void
{
$this->settingType = $that->settingType;
$this->rangeType = $that->rangeType;
Expand Down
20 changes: 10 additions & 10 deletions source/TALib/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Core
protected static array $unstablePeriod;
/** @var CandleSetting[] */
protected static array $candleSettings;
public static int $compatibility = Compatibility::Default;
public static Compatibility $compatibility = Compatibility::Default;

/**
* Core constructor.
Expand Down Expand Up @@ -109,12 +109,12 @@ public static function getUnstablePeriod(int $functionID): int
return static::$unstablePeriod[$functionID];
}

public static function setCompatibility(int $compatibility): void
public static function setCompatibility(Compatibility $compatibility): void
{
static::$compatibility = $compatibility;
}

public static function getCompatibility(): int
public static function getCompatibility(): Compatibility
{
return static::$compatibility;
}
Expand All @@ -124,7 +124,7 @@ protected static function double(int $size): array
return \array_pad([], $size, 0.);
}

protected static function validateStartEndIndexes(int $startIdx, int $endIdx): int
protected static function validateStartEndIndexes(int $startIdx, int $endIdx): ReturnCode
{
if ($startIdx < 0) {
return ReturnCode::OutOfRangeStartIndex;
Expand All @@ -148,7 +148,7 @@ protected static function TA_INT_PO(
array &$outReal,
array &$tempBuffer,
bool $doPercentageOutput
): int {
): ReturnCode {
$outBegIdx1 = 0;
$outNbElement1 = 0;
$outBegIdx2 = 0;
Expand Down Expand Up @@ -201,7 +201,7 @@ protected static function TA_INT_MACD(
array &$outMACD,
array &$outMACDSignal,
array &$outMACDHist
): int {
): ReturnCode {
//double[] $slowEMABuffer;
//double[] $fastEMABuffer;
//double $k1, $k2;
Expand Down Expand Up @@ -290,7 +290,7 @@ protected static function TA_INT_MACD(
return ReturnCode::Success;
}

protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $optInTimePeriod, float $optInK_1, int &$outBegIdx, int &$outNBElement, array &$outReal): int
protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $optInTimePeriod, float $optInK_1, int &$outBegIdx, int &$outNBElement, array &$outReal): ReturnCode
{
//double $tempReal, $prevMA;
//int $i, $today, $outIdx, $lookbackTotal;
Expand Down Expand Up @@ -331,7 +331,7 @@ protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $o
return ReturnCode::Success;
}

protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): int
protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): ReturnCode
{
//double $periodTotal, $tempReal;
//int $i, $outIdx, $trailingIdx, $lookbackTotal;
Expand Down Expand Up @@ -366,7 +366,7 @@ protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal,
return ReturnCode::Success;
}

protected static function TA_INT_stddev_using_precalc_ma(array $inReal, array $inMovAvg, int $inMovAvgBegIdx, int $inMovAvgNbElement, int $timePeriod, array &$output): int
protected static function TA_INT_stddev_using_precalc_ma(array $inReal, array $inMovAvg, int $inMovAvgBegIdx, int $inMovAvgNbElement, int $timePeriod, array &$output): ReturnCode
{
//double $tempReal, $periodTotal2, $meanValue2;
//int $outIdx;
Expand Down Expand Up @@ -400,7 +400,7 @@ protected static function TA_INT_stddev_using_precalc_ma(array $inReal, array $i
return ReturnCode::Success;
}

protected static function TA_INT_VAR(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): int
protected static function TA_INT_VAR(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): ReturnCode
{
//double $tempReal, $periodTotal1, $periodTotal2, $meanValue1, $meanValue2;
//int $i, $outIdx, $trailingIdx, $nbInitialElementNeeded;
Expand Down
20 changes: 10 additions & 10 deletions source/TALib/Core/CycleIndicators.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CycleIndicators extends Core
*
* @return int
*/
public static function htDcPeriod(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outReal): int
public static function htDcPeriod(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outReal): ReturnCode
{
if ($RetCode = static::validateStartEndIndexes($startIdx, $endIdx)) {
return $RetCode;
Expand All @@ -69,7 +69,7 @@ public static function htDcPeriod(int $startIdx, int $endIdx, array $inReal, int
$b = 0.5769;
$detrender_Odd = $detrender_Even = $Q1_Odd = $Q1_Even = $jI_Odd = $jI_Even = $jQ_Odd = $jQ_Even = static::double(3);
$rad2Deg = 180.0 / (4.0 * atan(1));
$lookbackTotal = 32 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtDcPeriod]);
$lookbackTotal = 32 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtDcPeriod->value]);
if ($startIdx < $lookbackTotal) {
$startIdx = $lookbackTotal;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public static function htDcPeriod(int $startIdx, int $endIdx, array $inReal, int
*
* @return int
*/
public static function htDcPhase(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outReal): int
public static function htDcPhase(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outReal): ReturnCode
{
if ($RetCode = static::validateStartEndIndexes($startIdx, $endIdx)) {
return $RetCode;
Expand All @@ -257,7 +257,7 @@ public static function htDcPhase(int $startIdx, int $endIdx, array $inReal, int
$tempReal = atan(1);
$rad2Deg = 45.0 / $tempReal;
$constDeg2RadBy360 = $tempReal * 8.0;
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtDcPhase]);
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtDcPhase->value]);
if ($startIdx < $lookbackTotal) {
$startIdx = $lookbackTotal;
}
Expand Down Expand Up @@ -554,7 +554,7 @@ public static function htDcPhase(int $startIdx, int $endIdx, array $inReal, int
*
* @return int
*/
public static function htPhasor(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outInPhase, array &$outQuadrature): int
public static function htPhasor(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outInPhase, array &$outQuadrature): ReturnCode
{
if ($RetCode = static::validateStartEndIndexes($startIdx, $endIdx)) {
return $RetCode;
Expand All @@ -569,7 +569,7 @@ public static function htPhasor(int $startIdx, int $endIdx, array $inReal, int &
$jI_Even = static::double(3);
$jQ_Odd = static::double(3);
$rad2Deg = 180.0 / (4.0 * atan(1));
$lookbackTotal = 32 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtPhasor]);
$lookbackTotal = 32 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtPhasor->value]);
if ($startIdx < $lookbackTotal) {
$startIdx = $lookbackTotal;
}
Expand Down Expand Up @@ -824,7 +824,7 @@ public static function htPhasor(int $startIdx, int $endIdx, array $inReal, int &
*
* @return int
*/
public static function htSine(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outSine, array &$outLeadSine): int
public static function htSine(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outSine, array &$outLeadSine): ReturnCode
{
if ($RetCode = static::validateStartEndIndexes($startIdx, $endIdx)) {
return $RetCode;
Expand All @@ -848,7 +848,7 @@ public static function htSine(int $startIdx, int $endIdx, array $inReal, int &$o
$rad2Deg = 45.0 / $tempReal;
$deg2Rad = 1.0 / $rad2Deg;
$constDeg2RadBy360 = $tempReal * 8.0;
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtSine]);
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtSine->value]);
if ($startIdx < $lookbackTotal) {
$startIdx = $lookbackTotal;
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ public static function htSine(int $startIdx, int $endIdx, array $inReal, int &$o
*
* @return int
*/
public static function htTrendMode(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outInteger): int
public static function htTrendMode(int $startIdx, int $endIdx, array $inReal, int &$outBegIdx, int &$outNBElement, array &$outInteger): ReturnCode
{
if ($RetCode = static::validateStartEndIndexes($startIdx, $endIdx)) {
return $RetCode;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ public static function htTrendMode(int $startIdx, int $endIdx, array $inReal, in
$rad2Deg = 45.0 / $tempReal;
$deg2Rad = 1.0 / $rad2Deg;
$constDeg2RadBy360 = $tempReal * 8.0;
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtTrendMode]);
$lookbackTotal = 63 + (static::$unstablePeriod[UnstablePeriodFunctionID::HtTrendMode->value]);
if ($startIdx < $lookbackTotal) {
$startIdx = $lookbackTotal;
}
Expand Down
Loading

0 comments on commit b26ed50

Please sign in to comment.