Beispiel #1
0
 def __init__(self, df, params):
     self.condList = (params["condList"] if "condList" in params.keys() else
                      ("maBelow", "isWhiteBlack"))
     self.numPeriods = params["numPeriods"] if "numPeriods" in params.keys(
     ) else 2
     self.maLong = params["maLong"] if "maLong" in params.keys() else 50
     self.maShort = params["maShort"] if "maShort" in params.keys() else 10
     self.df = Attr(
         Attr(
             Attr(
                 Attr(df).add("IsWhiteBlack",
                              params={
                                  "whiteList": [0, 1],
                                  "blackList": [2]
                              })).add("Hammer", params={"delay": 1})).add(
                                  "MA",
                                  params={
                                      "numPeriods": self.maLong,
                                      "attrName": "maLong"
                                  })).add("MA",
                                          params={
                                              "numPeriods": self.maShort,
                                              "attrName": "maShort"
                                          })
     self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]
Beispiel #2
0
 def __init__(self, df, params):
     self.numPeriods = params["numPeriods"] if "numPeriods" in params.keys() else 100
     self.maxPeriod = params["maxPeriod"] if "maxPeriod" in params.keys() else 32
     isHalves = params["isHalves"] if "isHalves" in params.keys() else True
     self.df = Attr(
         Attr(df).add(
             "MA", params={"col": "volume", "numPeriods": 100, "attrName": "volMA"}
         )
     ).add("PivotLines", params={"numPeriods": self.numPeriods})
     self.pivots = (
         [
             "s3",
             "s2.5",
             "s2",
             "s1.5",
             "s1",
             "s0.5",
             "p",
             "r0.5",
             "r1",
             "r1.5",
             "r2",
             "r2.5",
             "r3",
         ]
         if isHalves
         else ["s3", "s2", "s1", "p", "r1", "r2", "r3"]
     )
Beispiel #3
0
 def __init__(self, df, params):
     self.condList = (
         params["condList"] if "condList" in params.keys() else ("maBelow", "conf")
     )
     self.numPeriods = params["numPeriods"] if "numPeriods" in params.keys() else 2
     self.maLong = params["maLong"] if "maLong" in params.keys() else 50
     self.maShort = params["maShort"] if "maShort" in params.keys() else 10
     self.df = Attr(
         Attr(
             Attr(df).add("BullSqueeze", params={"numPeriods": self.numPeriods})
         ).add("MA", params={"numPeriods": self.maLong, "attrName": "maLong"})
     ).add("MA", params={"numPeriods": self.maShort, "attrName": "maShort"})
     self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]
     self.df["conf"] = self.df["close"] > self.df["bullConf"]
Beispiel #4
0
 def __init__(self, df, params):
     self.delay = params["delay"] if "delay" in params.keys() else 0
     self.volMALongPeriods = (params["numPeriodsVolLong"] if
                              "numPeriodsVolLong" in params.keys() else 100)
     self.volMAShortPeriods = (params["numPeriodsVolShort"] if
                               "numPeriodsVolShort" in params.keys() else 5)
     self.volCoef = params["volCoef"] if "volCoef" in params.keys() else 1
     self.volDir = params["volDir"] if "volDir" in params.keys() else "high"
     self.maPeriods = (params["numPeriodsMA"]
                       if "numPeriodsMA" in params.keys() else 30)
     self.numStd = params["numStd"] if "numStd" in params.keys() else 2
     self.bolCoef = params["bolCoef"] if "bolCoef" in params.keys() else 1
     self.volCol = (params["volCol"]
                    if "volCol" in params.keys() else "takerBaseAssetVol")
     if len(df) > self.volMALongPeriods:
         self.df = (Attr(
             Attr(
                 Attr(
                     Attr(df).add(
                         "MA",
                         params={
                             "numPeriods": self.maPeriods,
                             "attrName": "ma"
                         },
                     )).add(
                         "Bollinger",
                         params={
                             "numPeriods": self.maPeriods,
                             "numStd": self.numStd,
                             "maField": "ma",
                             "attrName": "bollinger",
                         },
                     )).add(
                         "MA",
                         params={
                             "col": self.volCol,
                             "numPeriods": self.volMALongPeriods,
                             "attrName": "volMALong",
                         },
                     )).add(
                         "MA",
                         params={
                             "col": self.volCol,
                             "numPeriods": self.volMAShortPeriods,
                             "attrName": "volMAShort",
                         },
                     ).iloc[max(self.volMALongPeriods, self.maPeriods):])
     else:
         self.df = df
Beispiel #5
0
 def __init__(self, df, params, enterList, isDebug=False):
     self.numMAPeriods = (
         params["numMAPeriods"] if "numMAPeriods" in params.keys() else 5
     )
     self.numRPeriods = (
         params["numRPeriods"] if "numRPeriods" in params.keys() else 10
     )
     self.coef = params["coef"] if "coef" in params.keys() else 0.99
     self.df = Attr(
         Attr(df).add(
             "MA", params={"attrName": "exitMA", "numPeriods": self.numMAPeriods}
         )
     ).add("Support", params={"numPeriods": self.numRPeriods})
     self.enterList = enterList
     self.isDebug = isDebug
Beispiel #6
0
class InsideUp:

    """
        Pairs a Bull Squeeze candlestick formation with a confirming white session
        numPeriods > 2 then -> squeeze

        12h/1d effective
    """

    def __init__(self, df, params):
        self.condList = (
            params["condList"] if "condList" in params.keys() else ("maBelow", "conf")
        )
        self.numPeriods = params["numPeriods"] if "numPeriods" in params.keys() else 2
        self.maLong = params["maLong"] if "maLong" in params.keys() else 50
        self.maShort = params["maShort"] if "maShort" in params.keys() else 10
        self.df = Attr(
            Attr(
                Attr(df).add("BullSqueeze", params={"numPeriods": self.numPeriods})
            ).add("MA", params={"numPeriods": self.maLong, "attrName": "maLong"})
        ).add("MA", params={"numPeriods": self.maShort, "attrName": "maShort"})
        self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]
        self.df["conf"] = self.df["close"] > self.df["bullConf"]

    def run(self):
        self.df["bullSqueezeConf"] = self.df.apply(self.conditions, axis=1)
        return list(self.df[self.df["bullSqueezeConf"]]["TS"].values)

    def conditions(self, row):
        return False not in [row[val] for val in self.condList] + [row["bullSqueeze"]]
Beispiel #7
0
class LadderBottom:
    """
        Three consecutive down periods followed by a gap white

        ** Not promising
    """
    def __init__(self, df, params):
        self.gapCoef = params["gapCoef"] if "gapCoef" in params.keys(
        ) else 1.005
        self.gapPeriods = params["gapPeriods"] if "gapPeriods" in params.keys(
        ) else 2
        self.numBSPeriods = (params["numBSPeriods"]
                             if "numBSPeriods" in params.keys() else 3)
        self.df = Attr(
            Attr(df).add("UpGap",
                         params={
                             "numPeriods": self.gapPeriods,
                             "coef": self.gapCoef
                         })).add("BlackSoldiers",
                                 params={
                                     "numPeriods": self.numBSPeriods,
                                     "delay": 1
                                 })

    def run(self):
        self.df["ladderBottom"] = self.df.apply(self.conditions, axis=1)
        return list(self.df[self.df["ladderBottom"]]["TS"].values)

    def conditions(self, row):
        return False not in [row["blackSoldiers"], row["upGap"]]
Beispiel #8
0
 def __init__(self, df, params):
     self.gapCoef = params["gapCoef"] if "gapCoef" in params.keys(
     ) else 1.005
     self.gapPeriods = params["gapPeriods"] if "gapPeriods" in params.keys(
     ) else 2
     self.numBSPeriods = (params["numBSPeriods"]
                          if "numBSPeriods" in params.keys() else 3)
     self.df = Attr(
         Attr(df).add("UpGap",
                      params={
                          "numPeriods": self.gapPeriods,
                          "coef": self.gapCoef
                      })).add("BlackSoldiers",
                              params={
                                  "numPeriods": self.numBSPeriods,
                                  "delay": 1
                              })
Beispiel #9
0
def test_Bollinger():
    numPeriods = 5
    df = Attr(testingLoad()).add("MA", params={"numPeriods": numPeriods})
    maCol = df["ma%s" % numPeriods]
    bol = Bollinger(df=df, params={
        "numPeriods": numPeriods,
        "numStd": 10
    }).run()
    p = 8
    assert bol[0][1][p] == round(
        float(df["ma%s" % numPeriods].iloc[p] +
              10 * np.std(df["close"].iloc[p - numPeriods:p])),
        6,
    )
    p = 5
    assert bol[1][1][p] == round(
        float(df["ma%s" % numPeriods].iloc[p] -
              10 * np.std(df["close"].iloc[p - numPeriods:p])),
        6,
    )
Beispiel #10
0
class BullHammer:
    """
        Could make cleaner

        * Not promising
    """
    def __init__(self, df, params):
        self.condList = (params["condList"] if "condList" in params.keys() else
                         ("maBelow", "isWhiteBlack"))
        self.numPeriods = params["numPeriods"] if "numPeriods" in params.keys(
        ) else 2
        self.maLong = params["maLong"] if "maLong" in params.keys() else 50
        self.maShort = params["maShort"] if "maShort" in params.keys() else 10
        self.df = Attr(
            Attr(
                Attr(
                    Attr(df).add("IsWhiteBlack",
                                 params={
                                     "whiteList": [0, 1],
                                     "blackList": [2]
                                 })).add("Hammer", params={"delay": 1})).add(
                                     "MA",
                                     params={
                                         "numPeriods": self.maLong,
                                         "attrName": "maLong"
                                     })).add("MA",
                                             params={
                                                 "numPeriods": self.maShort,
                                                 "attrName": "maShort"
                                             })
        self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]

    def run(self):
        self.df["hammerConf"] = self.df.apply(self.conditions, axis=1)
        return list(self.df[self.df["hammerConf"]]["TS"].values)

    def conditions(self, row):
        return False not in [row[val]
                             for val in self.condList] + [row["hammer"]]
Beispiel #11
0
 def __init__(self, df, params):
     self.numBSPeriods = (params["numBSPeriods"]
                          if "numBSPeriods" in params.keys() else 3)
     self.maLong = params["maLong"] if "maLong" in params.keys() else 50
     self.maShort = params["maShort"] if "maShort" in params.keys() else 10
     self.volPeriods = params["volPeriods"] if "volPeriods" in params.keys(
     ) else 40
     self.condList = (params["condList"] if "condList" in params.keys() else
                      ("isWhite", "maBelow", "volCond"))
     self.df = Attr(
         Attr(
             Attr(
                 Attr(
                     Attr(df).add(
                         "MA",
                         params={
                             "numPeriods": self.volPeriods,
                             "col": "takerBaseAssetVol",
                             "attrName": "meanVol",
                         },
                     )).add(
                         "Bollinger",
                         params={
                             "maField": "meanVol",
                             "numStd": 0.5,
                             "attrName": "bolVol",
                         },
                     )).add("MA",
                            params={
                                "numPeriods": self.maLong,
                                "attrName": "maLong"
                            })).add("MA",
                                    params={
                                        "numPeriods": self.maShort,
                                        "attrName": "maShort"
                                    })).add("BullSqueeze",
                                            params={
                                                "numPeriods":
                                                self.numBSPeriods,
                                                "delay": 1
                                            })
     self.df["isWhite"] = self.df["close"] > self.df["open"]
     self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]
     self.runStats = {}
Beispiel #12
0
class BullSqueezeVol:
    """
        MA50 > MA10
        Bull squeeze pattern
        Vol for init > Mean(Vol_20) + std
        Vol for last squeeze period + 1 < Mean(Vol_20)
        Squeeze +1 white
    """
    def __init__(self, df, params):
        self.numBSPeriods = (params["numBSPeriods"]
                             if "numBSPeriods" in params.keys() else 3)
        self.maLong = params["maLong"] if "maLong" in params.keys() else 50
        self.maShort = params["maShort"] if "maShort" in params.keys() else 10
        self.volPeriods = params["volPeriods"] if "volPeriods" in params.keys(
        ) else 40
        self.condList = (params["condList"] if "condList" in params.keys() else
                         ("isWhite", "maBelow", "volCond"))
        self.df = Attr(
            Attr(
                Attr(
                    Attr(
                        Attr(df).add(
                            "MA",
                            params={
                                "numPeriods": self.volPeriods,
                                "col": "takerBaseAssetVol",
                                "attrName": "meanVol",
                            },
                        )).add(
                            "Bollinger",
                            params={
                                "maField": "meanVol",
                                "numStd": 0.5,
                                "attrName": "bolVol",
                            },
                        )).add("MA",
                               params={
                                   "numPeriods": self.maLong,
                                   "attrName": "maLong"
                               })).add("MA",
                                       params={
                                           "numPeriods": self.maShort,
                                           "attrName": "maShort"
                                       })).add("BullSqueeze",
                                               params={
                                                   "numPeriods":
                                                   self.numBSPeriods,
                                                   "delay": 1
                                               })
        self.df["isWhite"] = self.df["close"] > self.df["open"]
        self.df["maBelow"] = self.df["maLong"] > self.df["maShort"]
        self.runStats = {}

    def run(self):
        self.df["volCond"] = self.volCond()
        self.df["bullSqueezeVol"] = self.df.apply(self.conditions, axis=1)
        for cond in ["bullSqueeze", "isWhite", "maBelow", "volCond"]:
            self.runStats[cond] = round(sum(self.df[cond]) / len(self.df), 4)
        print(self.runStats)
        return list(self.df[self.df["bullSqueezeVol"]]["TS"].values)

    def conditions(self, row):
        return False not in [row[val]
                             for val in self.condList] + [row["bullSqueeze"]]

    def volCond(self):
        volList = [False for _ in range(len(self.df))]
        for i in range(self.numBSPeriods, len(self.df)):
            row = self.df.iloc[i]
            if (self.df.iloc[i - self.numBSPeriods - 1]["takerBaseAssetVol"] >
                    row["bolVolUp"] and row["takerBaseAssetVol"] <
                (row["meanVol"] + row["bolVolUp"]) / 2):
                volList[i] = True
        return volList
Beispiel #13
0
def test_add(loc=None):
    df = testingLoad(loc=loc)
    A = Attr(df)
    df_ = A.add("TestAttr", params={"attrName": "attrName"})
    assert df.iloc[-1]["open"] + df.iloc[-1]["close"] == df_.iloc[-1]["attrName1"]
    assert df.iloc[0]["high"] + df.iloc[0]["low"] == df_.iloc[0]["attrName2"]