Exemplo n.º 1
0
Arquivo: kvo.py Projeto: Deanzou/jesse
def kvo(candles: np.ndarray,
        short_period=2,
        long_period=5,
        sequential=False) -> Union[float, np.ndarray]:
    """
    KVO - Klinger Volume Oscillator

    :param candles: np.ndarray
    :param short_period: int - default: 2
    :param long_period: int - default: 5
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    res = ti.kvo(np.ascontiguousarray(candles[:, 3]),
                 np.ascontiguousarray(candles[:, 4]),
                 np.ascontiguousarray(candles[:, 2]),
                 np.ascontiguousarray(candles[:, 5]),
                 short_period=short_period,
                 long_period=long_period)

    return np.concatenate(
        (np.full((candles.shape[0] - res.shape[0]), np.nan),
         res), axis=0) if sequential else res[-1]
Exemplo n.º 2
0
 def get_indicators(self):
     short_window = int(self.strategy_value['short_window'])
     long_window = int(self.strategy_value['long_window'])
     signal_window = int(self.strategy_value['signal_window'])
     kvo = ti.kvo(self.high, self.low, self.close, self.volume,
                  short_window, long_window)
     return kvo, ti.ema(kvo, signal_window)
Exemplo n.º 3
0
    async def evaluate(self, cryptocurrency, symbol, time_frame, high_candles, low_candles,
                       close_candles, volume_candles, candle):
        if len(high_candles) >= self.short_period:
            kvo = tulipy.kvo(high_candles,
                             low_candles,
                             close_candles,
                             volume_candles,
                             self.short_period,
                             self.long_period)
            kvo = data_util.drop_nan(kvo)
            if len(kvo) >= self.ema_signal_period:

                kvo_ema = tulipy.ema(kvo, self.ema_signal_period)
                ema_difference = kvo - kvo_ema

                if len(ema_difference) > 1:
                    zero_crossing_indexes = EvaluatorUtil.TrendAnalysis.get_threshold_change_indexes(ema_difference, 0)
                    max_elements = 7
                    to_consider_kvo = min(max_elements, len(ema_difference) - zero_crossing_indexes[-1])
                    self.eval_note = EvaluatorUtil.TrendAnalysis.min_has_just_been_reached(
                        ema_difference[-to_consider_kvo:],
                        acceptance_window=0.9, delay=1)
        await self.evaluation_completed(cryptocurrency, symbol, time_frame,
                                        eval_time=evaluators_util.get_eval_time(full_candle=candle,
                                                                                time_frame=time_frame))
def klinger_kama(h, l, c, v):
	cslow = 55
	cfast = 34
	
	kvo = ti.kvo(np.array(h), np.array(l), np.array(c), np.array(v), cfast, cslow)		  
	signal = kama(kvo)
	return (kvo, signal)
    async def eval_impl(self):
        self.eval_note = False
        short_period = 35  # standard with klinger
        long_period = 55  # standard with klinger
        ema_signal_period = 13  # standard ema signal for klinger
        kvo = tulipy.kvo(self.data[PriceIndexes.IND_PRICE_HIGH.value],
                         self.data[PriceIndexes.IND_PRICE_LOW.value],
                         self.data[PriceIndexes.IND_PRICE_CLOSE.value],
                         self.data[PriceIndexes.IND_PRICE_VOL.value],
                         short_period, long_period)
        kvo = DataUtil.drop_nan(kvo)
        if len(kvo) >= ema_signal_period:

            kvo_ema = tulipy.ema(kvo, ema_signal_period)
            ema_difference = kvo - kvo_ema

            if len(ema_difference) > 1:
                zero_crossing_indexes = TrendAnalysis.get_threshold_change_indexes(
                    ema_difference, 0)
                max_elements = 7
                to_consider_kvo = min(
                    max_elements,
                    len(ema_difference) - zero_crossing_indexes[-1])
                self.eval_note = TrendAnalysis.min_has_just_been_reached(
                    ema_difference[-to_consider_kvo:],
                    acceptance_window=0.9,
                    delay=1)
Exemplo n.º 6
0
    def compute(self, data_dict):
        high = data_dict.get('high')
        low = data_dict.get('low')
        close = data_dict.get('close')
        volume = data_dict.get('volume')

        return ti.kvo(high, low, close, volume, self.short_period,
                      self.long_period)
Exemplo n.º 7
0
def klinger_kama(h, l, c, v):
    cslow = 55
    cfast = 34
    h2 = [float(i) for i in h]
    l2 = [float(i) for i in l]
    c2 = [float(i) for i in c]
    v2 = [float(i) for i in v]
    kvo = ti.kvo(np.array(h2), np.array(l2), np.array(c2), np.array(v2), 34.0,
                 55.0)
    signal = kama(kvo)
    return kvo, signal
Exemplo n.º 8
0
    async def evaluate(self, cryptocurrency, symbol, time_frame, high_candles, low_candles,
                       close_candles, volume_candles, candle):
        eval_proposition = commons_constants.START_PENDING_EVAL_NOTE
        kvo = tulipy.kvo(high_candles,
                         low_candles,
                         close_candles,
                         volume_candles,
                         self.short_period,
                         self.long_period)
        kvo = data_util.drop_nan(kvo)
        if len(kvo) >= self.ema_signal_period:
            kvo_ema = tulipy.ema(kvo, self.ema_signal_period)

            ema_difference = kvo - kvo_ema

            if len(ema_difference) > 1:
                zero_crossing_indexes = EvaluatorUtil.TrendAnalysis.get_threshold_change_indexes(ema_difference, 0)

                current_difference = ema_difference[-1]
                significant_move_threshold = numpy.std(ema_difference)

                factor = 0.2

                if EvaluatorUtil.TrendAnalysis.peak_has_been_reached_already(
                        ema_difference[zero_crossing_indexes[-1]:]):
                    if abs(current_difference) > significant_move_threshold:
                        factor = 1
                    else:
                        factor = 0.5

                eval_proposition = current_difference * factor / significant_move_threshold

                if abs(eval_proposition) > 1:
                    eval_proposition = 1 if eval_proposition > 0 else -1
        self.eval_note = eval_proposition
        await self.evaluation_completed(cryptocurrency, symbol, time_frame,
                                        eval_time=evaluators_util.get_eval_time(full_candle=candle,
                                                                                time_frame=time_frame))
    def eval_impl(self):
        eval_proposition = START_PENDING_EVAL_NOTE
        short_period = 35  # standard with klinger
        long_period = 55  # standard with klinger
        ema_signal_period = 13  # standard ema signal for klinger
        kvo = tulipy.kvo(self.data[PriceIndexes.IND_PRICE_HIGH.value],
                         self.data[PriceIndexes.IND_PRICE_LOW.value],
                         self.data[PriceIndexes.IND_PRICE_CLOSE.value],
                         self.data[PriceIndexes.IND_PRICE_VOL.value],
                         short_period, long_period)
        kvo = DataUtil.drop_nan(kvo)
        if len(kvo) >= ema_signal_period:
            kvo_ema = tulipy.ema(kvo, ema_signal_period)

            ema_difference = kvo - kvo_ema

            if len(ema_difference) > 1:
                zero_crossing_indexes = TrendAnalysis.get_threshold_change_indexes(
                    ema_difference, 0)

                current_difference = ema_difference[-1]
                significant_move_threshold = numpy.std(ema_difference)

                factor = 0.2

                if TrendAnalysis.peak_has_been_reached_already(
                        ema_difference[zero_crossing_indexes[-1]:]):
                    if abs(current_difference) > significant_move_threshold:
                        factor = 1
                    else:
                        factor = 0.5

                eval_proposition = current_difference * factor / significant_move_threshold

                if abs(eval_proposition) > 1:
                    eval_proposition = 1 if eval_proposition > 0 else -1

        self.eval_note = eval_proposition
Exemplo n.º 10
0
def kvo(candles: np.ndarray,
        short_period: int = 2,
        long_period: int = 5,
        sequential: bool = False) -> Union[float, np.ndarray]:
    """
    KVO - Klinger Volume Oscillator

    :param candles: np.ndarray
    :param short_period: int - default: 2
    :param long_period: int - default: 5
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    candles = slice_candles(candles, sequential)

    res = ti.kvo(np.ascontiguousarray(candles[:, 3]),
                 np.ascontiguousarray(candles[:, 4]),
                 np.ascontiguousarray(candles[:, 2]),
                 np.ascontiguousarray(candles[:, 5]),
                 short_period=short_period,
                 long_period=long_period)

    return same_length(candles, res) if sequential else res[-1]
def get_KVI(high, low, close, volume, slow_signal, fast_signal):
    kvo = np.zeros(len(high))
    kvo[1:] = ti.kvo(high, low, close,volume, slow_signal, fast_signal)
    kvo_signal = pd.Series(kvo).rolling(9).mean().values
    return [kvo, kvo_signal]