示例#1
0
 def __init__(self, time_series=None, inputs=None, input_keys=None, desc="Bollinger Bands", length=14, num_std=3):
     super(SMA, self).__init__(time_series=time_series, inputs=inputs, input_keys=input_keys, desc=desc,
                               length=length, num_std=num_std)
     self.length = self.get_int_config("length", 14)
     self.num_std = self.get_int_config("num_std", 3)
     self.__sma = SMA(inputs=inputs, length=self.length)
     self.__std_dev = STD(inputs=inputs, length=self.length)
示例#2
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)
示例#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)
示例#4
0
class BB(Indicator):
    UPPER = 'uppper'
    LOWER = 'lower'

    __slots__ = (
        'length',
        'num_std'
        '__sma',
        '__std_dev',
    )

    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)

    def on_update(self, data):
        result = {}
        result['timestamp'] = data['timestamp']
        sma = self.__sma.now(self.input_keys[0])
        std = self.__std_dev.now(self.input_keys[0])
        if not np.isnan(sma):
            upper = sma + std * self.num_std
            lower = sma - std * self.num_std

            result[BB.UPPER] = upper
            result[BB.LOWER] = lower
            result[Indicator.VALUE] = sma
        else:
            result[BB.UPPER] = np.nan
            result[BB.LOWER] = np.nan
            result[Indicator.VALUE] = np.nan

        self.add(result)
示例#5
0
class BB(Indicator):
    UPPER = 'uppper'
    LOWER = 'lower'

    __slots__ = (
        'length',
        'num_std'
        '__sma',
        '__std_dev',
    )

    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)

    def on_update(self, data):
        result = {}
        result['timestamp'] = data['timestamp']
        sma = self.__sma.now(self.input_keys[0])
        std = self.__std_dev.now(self.input_keys[0])
        if not np.isnan(sma):
            upper = sma + std * self.num_std
            lower = sma - std * self.num_std

            result[BB.UPPER] = upper
            result[BB.LOWER] = lower
            result[Indicator.VALUE] = sma
        else:
            result[BB.UPPER] = np.nan
            result[BB.LOWER] = np.nan
            result[Indicator.VALUE] = np.nan

        self.add(result)
示例#6
0
class BB(Indicator):
    UPPER = 'uppper'
    LOWER = 'lower'

    __slots__ = (
        'length',
        'num_std'
        '__sma',
        '__std_dev',
    )

    def __init__(self, time_series=None, inputs=None, input_keys=None, desc="Bollinger Bands", length=14, num_std=3):
        super(SMA, self).__init__(time_series=time_series, inputs=inputs, input_keys=input_keys, desc=desc,
                                  length=length, num_std=num_std)
        self.length = self.get_int_config("length", 14)
        self.num_std = self.get_int_config("num_std", 3)
        self.__sma = SMA(inputs=inputs, length=self.length)
        self.__std_dev = STD(inputs=inputs, length=self.length)

    def _process_update(self, source: str, timestamp: int, data: Dict[str, float]):
        result = {}
        sma = self.__sma.now(self.input_keys[0])
        std = self.__std_dev.now(self.input_keys[0])
        if not np.isnan(sma):
            upper = sma + std * self.num_std
            lower = sma - std * self.num_std

            result[BB.UPPER] = upper
            result[BB.LOWER] = lower
            result[Indicator.VALUE] = sma
        else:
            result[BB.UPPER] = np.nan
            result[BB.LOWER] = np.nan
            result[Indicator.VALUE] = np.nan

        self.add(timestamp=timestamp, data=result)