Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
extend the pivots to s4,r4
Browse files Browse the repository at this point in the history
  • Loading branch information
peerchemist committed May 8, 2019
1 parent c31fd7d commit 210bb9d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
44 changes: 26 additions & 18 deletions finta/finta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -879,23 +883,27 @@ 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)

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,
)
Expand Down
56 changes: 32 additions & 24 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,41 +732,49 @@ 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():
"""test TA.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():
Expand Down

0 comments on commit 210bb9d

Please sign in to comment.