diff --git a/finta/finta.py b/finta/finta.py index 15f153e..bc8c242 100644 --- a/finta/finta.py +++ b/finta/finta.py @@ -847,23 +847,27 @@ def PIVOT(cls, ohlc: DataFrame) -> Series: pivot = pd.Series(cls.TP(df), name="pivot") # pivot is basically a lagging TP - support_1 = (pivot * 2) - df["high"] - support_2 = pivot - (df["high"] - df["low"]) - support_3 = df["low"] - (2 * (df["high"] - pivot)) + s1 = (pivot * 2) - df["high"] + s2 = pivot - (df["high"] - df["low"]) + s3 = df["low"] - (2 * (df["high"] - pivot)) + s4 = df["low"] - (3 * (df["high"] - pivot)) - res_1 = (pivot * 2) - df["low"] - res_2 = pivot + (df["high"] - df["low"]) - res_3 = df["high"] + (2 * (pivot - df["low"])) + r1 = (pivot * 2) - df["low"] + r2 = pivot + (df["high"] - df["low"]) + r3 = df["high"] + (2 * (pivot - df["low"])) + r4 = df["high"] + (3 * (pivot - df["low"])) return pd.concat( [ pivot, - pd.Series(support_1, name="support_1"), - pd.Series(support_2, name="support_2"), - pd.Series(support_3, name="support_3"), - pd.Series(res_1, name="res_1"), - pd.Series(res_2, name="res_2"), - pd.Series(res_3, name="res_3"), + pd.Series(s1, name="s1"), + pd.Series(s2, name="s2"), + pd.Series(s3, name="s3"), + pd.Series(s4, name="s4"), + pd.Series(r1, name="r1"), + pd.Series(r2, name="r2"), + pd.Series(r3, name="r3"), + pd.Series(r4, name="r4"), ], axis=1, ) @@ -879,6 +883,7 @@ def PIVOT_FIB(cls, ohlc: DataFrame) -> Series: df = ohlc.shift() pp = pd.Series(cls.TP(df), name="pivot") # classic pivot + r4 = pp + ((df["high"] - df["low"]) * 1.382) r3 = pp + ((df["high"] - df["low"]) * 1) r2 = pp + ((df["high"] - df["low"]) * 0.618) r1 = pp + ((df["high"] - df["low"]) * 0.382) @@ -886,16 +891,19 @@ def PIVOT_FIB(cls, ohlc: DataFrame) -> Series: s1 = pp - ((df["high"] - df["low"]) * 0.382) s2 = pp - ((df["high"] - df["low"]) * 0.618) s3 = pp - ((df["high"] - df["low"]) * 1) + s4 = pp - ((df["high"] - df["low"]) * 1.382) return pd.concat( [ pp, - pd.Series(s1, name="support_1"), - pd.Series(s2, name="support_2"), - pd.Series(s3, name="support_3"), - pd.Series(r1, name="res_1"), - pd.Series(r2, name="res_2"), - pd.Series(r3, name="res_3"), + pd.Series(s1, name="s1"), + pd.Series(s2, name="s2"), + pd.Series(s3, name="s3"), + pd.Series(s4, name="s4"), + pd.Series(r1, name="r1"), + pd.Series(r2, name="r2"), + pd.Series(r3, name="r3"), + pd.Series(r4, name="r4") ], axis=1, ) diff --git a/tests/test_unit.py b/tests/test_unit.py index d8aa429..a4678b7 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -732,20 +732,24 @@ def test_pivot(): pivot = TA.PIVOT(ohlc) assert isinstance(pivot["pivot"], series.Series) - assert isinstance(pivot["support_1"], series.Series) - assert isinstance(pivot["support_2"], series.Series) - assert isinstance(pivot["support_3"], series.Series) - assert isinstance(pivot["res_1"], series.Series) - assert isinstance(pivot["res_2"], series.Series) - assert isinstance(pivot["res_3"], series.Series) + assert isinstance(pivot["s1"], series.Series) + assert isinstance(pivot["s2"], series.Series) + assert isinstance(pivot["s3"], series.Series) + assert isinstance(pivot["r1"], series.Series) + assert isinstance(pivot["r2"], series.Series) + assert isinstance(pivot["r3"], series.Series) assert pivot["pivot"].values[-1] == 6467.4062976066671 - assert pivot["support_1"].values[-1] == 6364.0047023933339 - assert pivot["support_2"].values[-1] == 6311.0094047866669 - assert pivot["support_3"].values[-1] == 6207.6078095733337 - assert pivot["res_1"].values[-1] == 6520.4015952133341 - assert pivot["res_2"].values[-1] == 6623.8031904266672 - assert pivot["res_3"].values[-1] == 6676.7984880333343 + + assert pivot["s1"].values[-1] == 6364.0047023933339 + assert pivot["s2"].values[-1] == 6311.0094047866669 + assert pivot["s3"].values[-1] == 6207.6078095733337 + assert pivot["s4"].values[-1] == 6104.2062143600006 + + assert pivot["r1"].values[-1] == 6520.4015952133341 + assert pivot["r2"].values[-1] == 6623.8031904266672 + assert pivot["r3"].values[-1] == 6676.7984880333343 + assert pivot["r4"].values[-1] == 6729.7937856400013 def test_pivot_fib(): @@ -753,20 +757,24 @@ def test_pivot_fib(): pivot = TA.PIVOT_FIB(ohlc) assert isinstance(pivot["pivot"], series.Series) - assert isinstance(pivot["support_1"], series.Series) - assert isinstance(pivot["support_2"], series.Series) - assert isinstance(pivot["support_3"], series.Series) - assert isinstance(pivot["res_1"], series.Series) - assert isinstance(pivot["res_2"], series.Series) - assert isinstance(pivot["res_3"], series.Series) + assert isinstance(pivot["s1"], series.Series) + assert isinstance(pivot["s2"], series.Series) + assert isinstance(pivot["s3"], series.Series) + assert isinstance(pivot["r1"], series.Series) + assert isinstance(pivot["r2"], series.Series) + assert isinstance(pivot["r3"], series.Series) assert pivot["pivot"].values[-1] == 6467.4062976066671 - assert pivot["support_1"].values[-1] == 6407.6626845494266 - assert pivot["support_2"].values[-1] == 6370.7530178439074 - assert pivot["support_3"].values[-1] == 6311.0094047866669 - assert pivot["res_1"].values[-1] == 6527.1499106639076 - assert pivot["res_2"].values[-1] == 6564.0595773694267 - assert pivot["res_3"].values[-1] == 6623.8031904266672 + + assert pivot["s1"].values[-1] == 6407.6626845494266 + assert pivot["s2"].values[-1] == 6370.7530178439074 + assert pivot["s3"].values[-1] == 6311.0094047866669 + assert pivot["s4"].values[-1] == 6251.2657917294273 + + assert pivot["r1"].values[-1] == 6527.1499106639076 + assert pivot["r2"].values[-1] == 6564.0595773694267 + assert pivot["r3"].values[-1] == 6623.8031904266672 + assert pivot["r4"].values[-1] == 6683.5468034839068 def test_msd():