Ejemplo n.º 1
0
    def get_input_name(inputs):
        parts = []
        if isinstance(inputs, list):
            parts.extend([Indicator.get_input_name(i) for i in inputs])
        else:
            # parts.extend(Indicator.get_input_name(inputs))
            parts.append(Indicator.get_input_name(inputs))

        return ",".join(str(part) for part in parts)
Ejemplo n.º 2
0
    def __init__(self, name, inputs, input_keys, length=None, desc=None, **kwargs):
        super(PipeLine, self).__init__(name=name, keys=None, desc=desc, **kwargs)
        # f = lambda i: i \
        #     if isinstance(i, DataSeries) or isinstance(i, Indicator) \
        #     else inst_data_mgr.get_series(i)
        # if isinstance(inputs, list):
        #     self.inputs = [f(i) for i in inputs]
        # else:
        #     self.inputs = f(inputs)

        input_names = []
        self.input_names_and_series = OrderedDict()
        if isinstance(inputs, list):
            for i in inputs:
                if isinstance(i, DataSeries):
                    input_name = DataSeries.get_name(i)
                    input_names.append(input_name)
                    self.input_names_and_series[input_name] = i
                elif isinstance(i, Indicator):
                    input_name = Indicator.get_name(i)
                    input_names.append(input_name)
                    self.input_names_and_series[input_name] = i
                elif isinstance(i, PipeLine):
                    input_name = PipeLine.get_name(i)
                    input_names.append(input_name)
                    self.input_names_and_series[input_name] = i
                else:
                    input_names.append(i)
        else:
            if isinstance(inputs, DataSeries):
                input_name = DataSeries.get_name(inputs)
                input_names.append(input_name)
                self.input_names_and_series[input_name] = inputs
            elif isinstance(inputs, Indicator):
                input_name = Indicator.get_name(inputs)
                input_names.append(input_name)
                self.input_names_and_series[input_name] = inputs
            elif isinstance(inputs, PipeLine):
                input_name = PipeLine.get_name(inputs)
                input_names.append(input_name)
                self.input_names_and_series[input_name] = inputs
            else:
                input_names.append(inputs)

        self.numPipes = len(input_names)
        self.length = length if length is not None else 1
        self.input_names = input_names
        self.input_names_pos = dict(zip(input_names,
                                        range(len(input_names))))

        self.input_keys = self._get_key(input_keys, None)
        # self.calculate = True
        self.__curr_timestamp = None
        self._flush_and_create()
        self.inputs = []
Ejemplo n.º 3
0
 def __init__(self, input=None, input_key=None, length=14, num_std=3, desc="Bollinger Bands"):
     self.length = int(length)
     self.num_std = int(num_std)
     self.__sma = SMA(input, self.length)
     self.__std_dev = STD(input, self.length)
     super(BB, self).__init__(Indicator.get_name(BB.__name__, input, input_key, length, num_std), input, input_key,
                              desc)
Ejemplo n.º 4
0
 def __init__(self, input=None, length=14, desc="Average True Range"):
     self.length = int(length)
     self.__prev_close = None
     self.__value = None
     self.__average = SMA(input, self.length)
     super(ATR, self).__init__(Indicator.get_name(ATR.__name__, input, length), input, ['high', 'low', 'close'],
                               desc)
Ejemplo n.º 5
0
 def __init__(self, input=None, length=14, desc="Average True Range"):
     self.length = int(length)
     self.__prev_close = None
     self.__value = None
     self.__average = SMA(input, self.length)
     super(ATR,
           self).__init__(Indicator.get_name(ATR.__name__, input, length),
                          input, ['high', 'low', 'close'], desc)
Ejemplo n.º 6
0
 def __init__(self,
              input,
              input_key=None,
              length=0,
              desc="TALib Simple Moving Average"):
     self.length = int(length)
     super(SMA, self).__init__(
         Indicator.get_name(SMA.__name__, input, input_key, length), input,
         input_key, desc)
Ejemplo n.º 7
0
 def __init__(self,
              input=None,
              input_key=None,
              length=1,
              desc="Rate Of Change"):
     self.length = int(length)
     super(ROC, self).__init__(
         Indicator.get_name(ROC.__name__, input, input_key, length), input,
         input_key, desc)
Ejemplo n.º 8
0
 def __init__(self,
              input,
              input_key=None,
              length=0,
              desc="Standard Deviation"):
     super(STD, self).__init__(
         Indicator.get_name(STD.__class__, input, input_key, length), input,
         input_key, desc)
     self.length = int(length)
     super(STD, self).update_all()
Ejemplo n.º 9
0
 def __init__(self,
              input,
              input_key=None,
              length=0,
              desc="TALib Exponential Moving Average"):
     super(EMA, self).__init__(
         Indicator.get_name(EMA.__name__, input, input_key, length), input,
         input_key, desc)
     self.length = int(length)
     super(EMA, self).update_all()
Ejemplo n.º 10
0
 def __init__(self,
              input=None,
              input_key=None,
              length=0,
              ann_factor=252,
              desc="Historical Volatility"):
     self.length = int(length)
     self.ann_factor = ann_factor
     super(HistoricalVolatility, self).__init__(
         Indicator.get_name(HistoricalVolatility.__name__, input, input_key,
                            length), input, input_key, desc)
Ejemplo n.º 11
0
 def __init__(self,
              input=None,
              input_key=None,
              length=14,
              desc="Relative Strength Indicator"):
     super(RSI, self).__init__(
         Indicator.get_name(RSI.__name__, input, input_key, length), input,
         input_key, desc)
     self.length = int(length)
     self.__prev_gain = None
     self.__prev_loss = None
     super(RSI, self).update_all()
Ejemplo n.º 12
0
 def __init__(self,
              input,
              input_key='close',
              length=30,
              desc="Rolling Standard Deviation"):
     super(StdDev,
           self).__init__(input,
                          func=lambda x: np.std(x, axis=0),
                          name=Indicator.get_name(StdDev.__name__, input,
                                                  input_key, length),
                          length=length,
                          input_key=input_key,
                          desc=desc)
Ejemplo n.º 13
0
 def __init__(self,
              input=None,
              input_key=None,
              length=14,
              num_std=3,
              desc="Bollinger Bands"):
     self.length = int(length)
     self.num_std = int(num_std)
     self.__sma = SMA(input, self.length)
     self.__std_dev = STD(input, self.length)
     super(BB, self).__init__(
         Indicator.get_name(BB.__name__, input, input_key, length, num_std),
         input, input_key, desc)
Ejemplo n.º 14
0
 def __init__(self,
              input,
              input_key='close',
              length=30,
              desc="Rolling Kurtosis"):
     super(Kurtosis,
           self).__init__(input,
                          func=lambda x: pd_kurtosis_wrapper(x),
                          name=Indicator.get_name(Kurtosis.__name__, input,
                                                  input_key, length),
                          length=length,
                          input_key=input_key,
                          desc=desc)
Ejemplo n.º 15
0
 def __init__(self,
              input,
              input_key='close',
              length=30,
              desc="Rolling Skew"):
     super(Skew,
           self).__init__(input,
                          func=lambda x: pd_skew_wrapper(x),
                          name=Indicator.get_name(Skew.__name__, input,
                                                  input_key, length),
                          length=length,
                          input_key=input_key,
                          desc=desc)
Ejemplo n.º 16
0
 def get_name(input, length):
     return "KalmanFilteringPairRegression(%s,%s)" % (
         Indicator.get_input_name(input), length)
Ejemplo n.º 17
0
 def __init__(self, input=None, input_key=None, length=0, desc="Simple Moving Average", **kwargs):
     self.length = int(length)
     super(SMA, self).__init__(Indicator.get_name(SMA.__name__, input, input_key, length), input, input_key, desc,
                               **kwargs)
Ejemplo n.º 18
0
 def __init__(self, input, input_key=None, length=0, desc="Variance"):
     super(VAR, self).__init__(Indicator.get_name(VAR.__class__, input, input_key, length), input, input_key,
                               desc)
     self.length = int(length)
Ejemplo n.º 19
0
 def __init__(self, input, input_key='close', length=30, desc="Rolling Kurt"):
     super(Kurt, self).__init__(input,
                                  func=lambda x: pd_kurt_wrapper(x),
                                  name=Indicator.get_name(Kurt.__name__, input, input_key, length),
                                  length=length,
                                  input_key=input_key, desc=desc)
Ejemplo n.º 20
0
 def __init__(self, input, input_key=None, length=0, desc="Minimum"):
     super(MIN, self).__init__(Indicator.get_name(MIN.__class__, input, input_key, length), input, input_key,
                               desc)
     self.length = int(length)
     super(MIN, self).update_all()
Ejemplo n.º 21
0
 def __init__(self, input=None, input_key=None, length=14, desc="Relative Strength Indicator"):
     super(RSI, self).__init__(Indicator.get_name(RSI.__name__, input, input_key, length), input, input_key, desc)
     self.length = int(length)
     self.__prev_gain = None
     self.__prev_loss = None
     super(RSI, self).update_all()
Ejemplo n.º 22
0
 def __init__(self, input, input_key=None, length=0, desc="TALib Exponential Moving Average"):
     super(EMA, self).__init__(Indicator.get_name(EMA.__name__, input, input_key, length), input, input_key, desc)
     self.length = int(length)
     super(EMA, self).update_all()
Ejemplo n.º 23
0
 def __init__(self, input=None, input_key=None, length=1, desc="Rate Of Change"):
     self.length = int(length)
     super(ROC, self).__init__(Indicator.get_name(ROC.__name__, input, input_key, length), input, input_key, desc)
Ejemplo n.º 24
0
 def get_or_create_indicator(self, cls, *args, **kwargs):
     name = Indicator.get_name(cls, *args, **kwargs)
     if not self.app_context.inst_data_mgr.has_series(name):
         return globals()[cls](*args, **kwargs)
     return self.app_context.inst_data_mgr.get_series(name, create_if_missing=False)
Ejemplo n.º 25
0
 def __init__(self, input=None, input_key=None, length=0, desc="Maximum"):
     self.length = int(length)
     super(MAX, self).__init__(Indicator.get_name(MAX.__class__, input, input_key, length), input, input_key,
                               desc)
Ejemplo n.º 26
0
 def __init__(self, input, input_key='close', length=30, desc="Rolling Standard Deviation"):
     super(StdDev, self).__init__(input,
                                  func=lambda x: np.std(x, axis=0),
                                  name=Indicator.get_name(StdDev.__name__, input, input_key, length),
                                  length=length,
                                  input_key=input_key, desc=desc)
Ejemplo n.º 27
0
 def __init__(self, input, input_key=None, length=0, desc="Standard Deviation"):
     super(STD, self).__init__(Indicator.get_name(STD.__class__, input, input_key, length), input, input_key,
                               desc)
     self.length = int(length)
     super(STD, self).update_all()
 def __init__(self, input=None, input_key=None, length=0, ann_factor=252, desc="Historical Volatility"):
     self.length = int(length)
     self.ann_factor = ann_factor
     super(HistoricalVolatility, self).__init__(
         Indicator.get_name(HistoricalVolatility.__name__, input, input_key, length), input, input_key, desc)
Ejemplo n.º 29
0
 def get_name(input, length):
     return "KalmanFilteringPairRegression(%s,%s)" % (Indicator.get_input_name(input), length)
Ejemplo n.º 30
0
 def __init__(self, input, input_key='close', length=30, desc="Rolling Skew"):
     super(Skew, self).__init__(input,
                                  func=lambda x: pd_skew_wrapper(x),
                                  name=Indicator.get_name(Skew.__name__, input, input_key, length),
                                  length=length,
                                  input_key=input_key, desc=desc)