Indicator divergence library for python

Overview

Indicator divergence library

This module aims to help to find bullish/bearish divergences (regular or hidden) between two indicators using argrelextrema from scipy.signal.

Code based on higher-highs-lower-lows-and-calculating-price-trends-in-python article on medium.

This package is mean to use in conjunction with jesse ai but is generic enough to be used on its own.

Install

poetry build
pip install dist/jesse_extra_indicators-0.1.0-py3-none-any.whl

Example usage

import jesse_extra_indicators as xta

# Loopback window
w = 2

# this indicators has lower highs
ind1 = np.array([0, 10, 0, 9, 0]) # ex df.close
ind1_hl = xta.hl.HighLow(ind1, order=1)

# this indicators has higher highs
ind2 = np.array([0, 10, 0, 11, 0]) # ex ta.rsi(df.close)
ind2_hl = xta.hl.HighLow(ind2, order=1)

# build indicator divergence object
ind_div = xta.hl.IndicatorDivergence(ind1_hl, ind2_hl)

# Check regular or hidden bearish divergence
assert ind_div.regular_divergence(w, "bearish")
assert ind_div.hidden_divergence(w, "bearish")

# Check bearish confirmation 
assert ind_div.confirmation(w, "bearish")


# Check regular or hidden bullish divergence
assert ind_div.regular_divergence(w, "bullish")
assert ind_div.hidden_divergence(w, "bullish")

# Check bearish confirmation 
assert ind_div.confirmation(w, "bullish")

Example jesse strategy

from jesse.strategies import Strategy, cached
import jesse.indicators as ta
import jesse_extra_indicators as xta

class Example(Strategy):

    @property
    @cached
    def close_rsi_div(self):
        # no need to have the full data, this will speed up processing
        w = 100 

        close_hl = xta.hl.HighLow(self.candles[-w:, 2])
        rsi_hl = xta.hl.HighLow(self.rsi)

        # build indicator divergence object
        return xta.hl.IndicatorDivergence(close_hl, close_hl)


    def should_long(self) -> bool:
        w = 2 # you may wan to tweak the loopback window
        return (
            self.close_rsi_div.regular_divergence(w, "bullish")
            or self.close_rsi_div.hidden_divergence(w, "bullish")
        )


    def should_short(self) -> bool:
        w = 2 # you may wan to tweak the loopback window
        return (
            self.close_rsi_div.regular_divergence(w, "bearish")
            or self.close_rsi_div.hidden_divergence(w, "bearish")
        )

    def should_cancel(self) -> bool:
        ...

    def go_long(self):
        ...

    def go_short(self):
        ...

Find this usefull and want to buy me a coffee ?

send tips to

33w68oGuotfpJy59fPP5fUDk2fT3EzGkmS (btc)

D8zxqb2Fzm7Kqkn7QcKrcQjBPwbEBmMbRE (dogecoin)

You might also like...
Portfolio and risk analytics in Python
Portfolio and risk analytics in Python

pyfolio pyfolio is a Python library for performance and risk analysis of financial portfolios developed by Quantopian Inc. It works well with the Zipl

Python sync/async framework for Interactive Brokers API

Introduction The goal of the IB-insync library is to make working with the Trader Workstation API from Interactive Brokers as easy as possible. The ma

bt - flexible backtesting for Python

bt - Flexible Backtesting for Python bt is currently in alpha stage - if you find a bug, please submit an issue. Read the docs here: http://pmorissett

ARCH models in Python
ARCH models in Python

arch Autoregressive Conditional Heteroskedasticity (ARCH) and other tools for financial econometrics, written in Python (with Cython and/or Numba used

:mag_right: :chart_with_upwards_trend: :snake: :moneybag:  Backtest trading strategies in Python.
:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.

Backtesting.py Backtest trading strategies with Python. Project website Documentation the project if you use it. Installation $ pip install backtestin

personal finance tracker, written in python 3 and using the wxPython GUI toolkit.
personal finance tracker, written in python 3 and using the wxPython GUI toolkit.

personal finance tracker, written in python 3 and using the wxPython GUI toolkit.

Sparse Beta-Divergence Tensor Factorization Library
Sparse Beta-Divergence Tensor Factorization Library

NTFLib Sparse Beta-Divergence Tensor Factorization Library Based off of this beta-NTF project this library is specially-built to handle tensors where

DL & CV-based indicator toolset for the vehicle drivers via live dash-cam footage.
DL & CV-based indicator toolset for the vehicle drivers via live dash-cam footage.

Vehicle Indicator Toolset Deep Learning and Computer Vision based indicator toolset for vehicle drivers using live dash-cam footages. Tracking of vehi

AlphaNet Improved Training of Supernet with Alpha-Divergence

AlphaNet: Improved Training of Supernet with Alpha-Divergence This repository contains our PyTorch training code, evaluation code and pretrained model

Generalized Jensen-Shannon Divergence Loss for Learning with Noisy Labels

The official code for the NeurIPS 2021 paper Generalized Jensen-Shannon Divergence Loss for Learning with Noisy Labels

Webcam Indicator is an application to recieve and send messages from your own Webcam Server.
Webcam Indicator is an application to recieve and send messages from your own Webcam Server.

Welcome to Webcam Indicator 👋 Webcam Indicator is an application to recieve and send messages from your own Webcam Server. 🏠 Homepage Prerequisites

Predict profitability of trades based on indicator buy / sell signals

Predict profitability of trades based on indicator buy / sell signals Trade profitability analysis for trades based on various indicators signals: MAC

PyTorch implementations of the beta divergence loss.

Beta Divergence Loss - PyTorch Implementation This repository contains code for a PyTorch implementation of the beta divergence loss. Dependencies Thi

A visual indicator of what environment/system you're using in django

A visual indicator of what environment/system you're using in django

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

Visual Automata is a Python 3 library built as a wrapper for Caleb Evans' Automata library to add more visualization features.
Visual Automata is a Python 3 library built as a wrapper for Caleb Evans' Automata library to add more visualization features.

Visual Automata Copyright 2021 Lewi Lie Uberg Released under the MIT license Visual Automata is a Python 3 library built as a wrapper for Caleb Evans'

A simple in-process python scheduler library, designed to be integrated seamlessly with the `datetime` standard library.

scheduler A simple in-process python scheduler library, designed to be integrated seamlessly with the datetime standard library. Due to the support of

A python library for face detection and features extraction based on mediapipe library

FaceAnalyzer A python library for face detection and features extraction based on mediapipe library Introduction FaceAnalyzer is a library based on me

JLC2KICAD_lib is a python script that generate a component library for KiCad from the JLCPCB/easyEDA library.

JLC2KiCad_lib is a python script that generate a component library (schematic, footprint and 3D model) for KiCad from the JLCPCB/easyEDA library. This script requires Python 3.6 or higher.

Comments
  • Error in Example Strategy

    Error in Example Strategy

    return xta.hl.IndicatorDivergence(close_hl, close_hl)

    close_hl is passed twice.

    I think it should be: return xta.hl.IndicatorDivergence(close_hl, rsi_hl)

    opened by ImproveMint 0
Owner
null
An Algorithmic Trading Library for Crypto-Assets in Python

Service Master Develop CI Badge Catalyst is an algorithmic trading library for crypto-assets written in Python. It allows trading strategies to be eas

Enigma 2.4k Jan 5, 2023
Python library for backtesting trading strategies & analyzing financial markets (formerly pythalesians)

finmarketpy (formerly pythalesians) finmarketpy is a Python based library that enables you to analyze market data and also to backtest trading strateg

Cuemacro 3k Dec 30, 2022
Python Backtesting library for trading strategies

backtrader Yahoo API Note: [2018-11-16] After some testing it would seem that data downloads can be again relied upon over the web interface (or API v

DRo 9.8k Dec 30, 2022
Python Algorithmic Trading Library

PyAlgoTrade PyAlgoTrade is an event driven algorithmic trading Python library. Although the initial focus was on backtesting, paper trading is now pos

Gabriel Becedillas 3.9k Jan 1, 2023
Q-Fin: A Python library for mathematical finance.

Q-Fin A Python library for mathematical finance. Installation https://pypi.org/project/QFin/ pip install qfin Bond Pricing Option Pricing Black-Schol

Roman Paolucci 247 Jan 1, 2023
Beibo is a Python library that uses several AI prediction models to predict stocks returns over a defined period of time.

Beibo is a Python library that uses several AI prediction models to predict stocks returns over a defined period of time.

Santosh 54 Dec 10, 2022
Zipline, a Pythonic Algorithmic Trading Library

Zipline is a Pythonic algorithmic trading library. It is an event-driven system for backtesting. Zipline is currently used in production as the backte

Quantopian, Inc. 15.7k Jan 2, 2023
Technical Analysis Library using Pandas and Numpy

Technical Analysis Library in Python It is a Technical Analysis library useful to do feature engineering from financial time series datasets (Open, Cl

DarĂ­o LĂłpez Padial 3.4k Jan 2, 2023
High-performance TensorFlow library for quantitative finance.

TF Quant Finance: TensorFlow based Quant Finance Library Table of contents Introduction Installation TensorFlow training Development roadmap Examples

Google 3.5k Jan 1, 2023
A python wrapper for Alpha Vantage API for financial data.

alpha_vantage Python module to get stock data/cryptocurrencies from the Alpha Vantage API Alpha Vantage delivers a free API for real time financial da

Romel Torres 3.8k Jan 7, 2023