Git Product home page Git Product logo

jhtalib's Introduction

title author date
jhTAlib
Joost Hoeks
2023-10-08

jhTAlib

Technical Analysis Library Time-Series

You can use and import it for your:

  • Technical Analysis Software

  • Charting Software

  • Backtest Software

  • Trading Robot Software

  • Trading Software in general

Work in progress...


Depends only on


Install

From source - source mirror 1 - source mirror 2:

$ git clone https://github.com/joosthoeks/jhTAlib.git
$ cd jhTAlib
$ [sudo] pip3 install -e .

Update

From source - source mirror 1 - source mirror 2:

$ cd jhTAlib
$ git pull [upstream master]

In Docker

From DockerHub:

$ docker pull joosthoeks/jhtalib
$ docker run -it joosthoeks/jhtalib /bin/bash
/usr/src/app# python3
>>> import jhtalib as jhta

From source - source mirror 1 - source mirror 2:

$ git clone https://github.com/joosthoeks/jhTAlib.git
$ cd jhTAlib
$ docker build -f Dockerfile -t jhtalib .
$ docker run -it jhtalib /bin/bash
/usr/src/app# python3
>>> import jhtalib as jhta

In Jupyter

From source - source mirror 1 - source mirror 2:

!git clone [-b branch-name] https://github.com/joosthoeks/jhTAlib.git
%cd 'jhTAlib/'
import jhtalib as jhta
%cd '../'
!rm -rf ./jhTAlib/

Basic Usage

""""""
# Import Built-Ins:
from pprint import pprint as pp

# Import Third-Party:

# Import Homebrew:
import jhtalib as jhta


# df is DataFeed:
df = {
    'datetime': ('20151217', '20151218', '20151221', '20151222', '20151223', '20151224', '20151228', '20151229', '20151230', '20151231'),
    'Open': (235.8, 232.3, 234.1, 232.2, 232.7, 235.4, 236.9, 234.85, 236.45, 235.0),
    'High': (238.05, 236.9, 237.3, 232.4, 235.2, 236.15, 236.9, 237.6, 238.3, 237.25),
    'Low': (234.55, 230.6, 230.2, 226.8, 231.5, 233.85, 233.05, 234.6, 234.55, 234.4),
    'Close': (234.6, 233.6, 230.2, 230.05, 234.15, 236.15, 233.25, 237.6, 235.75, 234.4),
    'Volume': (448294, 629039, 292528, 214170, 215545, 23548, 97574, 192908, 176839, 69347)
     }

# basic usage:
#pp (df)
pp (jhta.SMA(df, 10))
#pp (jhta.BBANDS(df, 10))

Help

$ python3
>>> import jhtalib as jhta
>>> dir(jhta)
>>> help(jhta)
>>> help(jhta.behavioral_techniques)
>>> help(jhta.candlestick)
>>> help(jhta.cycle_indicators)
>>> help(jhta.data)
>>> help(jhta.event_driven)
>>> help(jhta.experimental)
>>> help(jhta.general)
>>> help(jhta.information)
>>> help(jhta.math_functions)
>>> help(jhta.momentum_indicators)
>>> help(jhta.money_management)
>>> help(jhta.overlap_studies)
>>> help(jhta.pattern_recognition)
>>> help(jhta.price_transform)
>>> help(jhta.statistic_functions)
>>> help(jhta.uncategorised)
>>> help(jhta.volatility_indicators)
>>> help(jhta.volume_indicators)
>>> quit()

Check Installation

$ python3
>>> import jhtalib as jhta
>>> jhta.example()

If not errors then installation is correct.

>>> quit()

Examples


Notebooks


References

Books

  • An Introduction to Algorithmic Trading

  • Computer Analysis of the Futures Markets

  • New Concepts in Technical Trading Systems

  • The New Technical Trader

  • Trading Systems and Methods

Urls


Donation and Funding


jhtalib's People

Contributors

joosthoeks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jhtalib's Issues

Invalid syntax in decorators.py

Describe the bug
See 8b434ec#commitcomment-38003743

It seems like this commit is bringing a new file decorators.py which doesn't run on Python3.5 :
File "/root/venv/lib/python3.5/site-packages/jhtalib/decorators.py", line 20
print(f"Finished {func.name!r} in {run_time:.4f} secs")
^
SyntaxError: invalid syntax

To Reproduce
Steps to reproduce the behavior:

  1. Update jhTAlib to latest version
  2. With Python3.5 : import jhtalib as jhta
  3. Get the error

Expected behavior
No SyntaxError on import jhtalib as jhta

Additional context
Before upgrading jhTAlib, and without any change to my own code, all was working fine

ASI / SI

Tried using ASI, it has a couple of issues where R is not set which can happen so I made a tweak:

def SI(df, L):
    """
    Swing Index (J. Welles Wilder)
    """
    si_list = []
    i = 0
    R = 0
    while i < len(df['Close']):
        if i < 1 or df['High'][i] - df['Low'][i] == 0:
            si = float('NaN')
        else:
            N = (df['Close'][i] - df['Close'][i - 1]) + (.5 * (df['Close'][i] - df['Open'][i])) + (.25 *(df['Close'][i - 1] - df['Open'][i - 1]))
            R1 = df['High'][i] - df['Close'][i - 1]
            R2 = df['Low'][i] - df['Close'][i - 1]
            R3 = df['High'][i] - df['Low'][i]
            if R1 > R2 and R1 > R3:
                R = (df['High'][i] - df['Close'][i - 1]) - (.5 * (df['Low'][i] - df['Close'][i - 1])) + (.25 * (df['Close'][i - 1] - df['Open'][i - 1]))
            if R2 > R1 and R2 > R3:
                R = (df['Low'][i] - df['Close'][i - 1]) - (.5 * (df['High'][i] - df['Close'][i - 1])) + (.25 * (df['Close'][i - 1] - df['Open'][i - 1]))
            if R3 > R1 and R3 > R2:
                R = (df['High'][i] - df['Low'][i]) + (.25 * (df['Close'][i - 1] - df['Open'][i - 1]))
            K1 = df['High'][i] - df['Close'][i - 1]
            K2 = df['Low'][i] - df['Close'][i - 1]
            if K1 > K2:
                K = K1
            else:
                K = K2
            if R==0:
            	si = float('NaN')
            else:
            	si = 50 * (N / R) * (K / L)
        si_list.append(si)
        i += 1
    return si_list

The issue I see is the value returned should: The Accumulative Swing Index uses a scale from 0 to 100 for an up trend and 0 to -100 for a down trend.

However, if you look here you will see the ASI image shows -50000, very odd.

http://forex-indicators.net/accumulative-swing-index

Missing some examples

Hi you did a great work but could you give an example on how to use
SMA (DF,N,Price='close') for example

thanks

Implementation for time series data

If I wish to implement say bbands for time series data - do I keep updating a dataframe per time tick and making the call the bbands function to get the outputs?

VWAP issue

I have a data frame with all the requirements (Open, High, Low, Close) but end up getting this error and am stuck.

`Traceback (most recent call last):
File "C:/Users/XXXX", line 55, in
f['VWAP'] = jhtalib.VWAP(f,open='Open', high='High', low='Low', close='Close', volume='Volume')
File "C:\Users\Marc\tickles\venv\lib\site-packages\jhtalib\volume_indicators\volume_indicators.py", line 133, in VWAP
o = df[open][i]
File "C:\Users\Marc\tickles\venv\lib\site-packages\pandas\core\series.py", line 1071, in getitem
result = self.index.get_value(self, key)
File "C:\Users\Marc\tickles\venv\lib\site-packages\pandas\core\indexes\base.py", line 4730, in get_value
return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
File "pandas/_libs/index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 88, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 992, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

Process finished with exit code 1
`

Was just wondering if you have any insights into what I'm doing wrong.

Thank you

JHTALIB for python competitions, opensignals like solution, pure python panda-less

Is your feature request related to a problem? Please describe.
For equity prediction I would like to use jhtalib to make indicators/ input signals

Describe the solution you'd like
https://github.com/councilofelders/opensignals/blob/master/src/opensignals/features.py
But then panda-less and more dynamic to select the jhtalib indicators

Describe alternatives you've considered
Considered using PySpark to calculate such but it does not have talib like formulas, so than it defaults to pandas

Additional context
Is used for Kaggle Jane Street, numer.ai Signals and Datacrunch competition

Add column names as default arguments for all methods

Is your feature request related to a problem? Please describe.
Often I need to apply indicators on other columns then the usual. Since all columns a re hard coded I simply can not which is a pity. Here is an example

def AVGPRICE(df):
    """
    Average Price
    """
    avgprice_list = []
    i = 0
    while i < len(df['Close']):
        avgprice = (df['Open'][i] + df['High'][i] + df['Low'][i] + df['Close'][i]) / 4
        avgprice_list.append(avgprice)
        i += 1
    return avgprice_list

Describe the solution you'd like
Simply adding the column names as parameters with defaults would not change the current behavior but I would have the ability to use different columns:

def AVGPRICE(df, open='open', high='high', low='low', close='close'):

Describe alternatives you've considered
Currently I am forced to use plain talib functions which depend on the C library but I would prefer yours.

Stupid question - why return many values in indicators?

I see this in nearly all tech analysis libs and I've never understood it.

If I want SMA 20 - I'm likely to already be cycling through data tick by tick and on each tick I want the latest SMA 20. I will have a generic array of ohlcv data that may have a depth of say 200 (to cover all eventualities). So I pass in my data as you specified:

jhta.SMA(df, 20)

DF has a length of 200 just because...so I would like the SMA value where the SMA length is 20, of the last tick. What I receive is 200 SMAs, why?

The return value should always be a single number....shouldn't it?

For an easier explanation of my confusion...

df length is 201
pp (jhta.SMA(df, 200))
that returns 199 NaNs and 1 number

There must be a use case I'm too stupid to get, but everyone implements such things as you have, and I don't know why !

Really really loving your lib so dont think this is negative!

Harami Pattern detection is not working

Describe the bug
harami detection is failing for the following dataframe

To Reproduce

import pandas as pd
import jhtalib

def test_harami():
    date_format = "%Y-%m-%d %H:%M:%S"
    df = pd.DataFrame(
        {
            EnumStandardCandleColumn.datetime.name: [
                "2015-01-27 13:22:03",
                "2015-01-28 13:23:03",
                "2015-01-29 13:24:03",
                "2015-01-30 13:25:03",
                "2015-01-31 13:26:03",
            ],
            "Open": [28.0, 38.0, 35.0, 68.0, 66.0],
            "High": [45.0, 66.0, 150.0, 60.0, 15.0],
            "Low": [20.0, 31.0, 20.0, 72.0, 68.0],
            "Close": [38.0, 55.0, 127.0, 66.0, 22.0],
            "Volume": [38.0, 55.0, 127.0, 66.0, 22.0]
        }
    )
    df["datetime"] = pd.to_datetime(df["datetime"], format=date_format)
    result = jhtalib.CDLHARAMI(h)
    assert result is not None

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
The fourth candle from the left should be detected as harami
image

Desktop (please complete the following information):

  • OS:macos
  • Browser n/a
  • Version jhtalib-20190328.0

Additional context
Add any other context about the problem here.

rename your repo

hyphenated jh-TAlib would allow users to search for "talib" and find you; as it stands jhTAlib is not among the many talib clones listed in a github search

HI

What do you think is the difference between jhTAlib and TA-Lib?

jhta.HT_TRENDMODE returning None Value

When trying to get calculate the Hilbert Transformation Indicators I'm failing to get a usable return value.

I built a dataframe like in the examples, but only returning a None Value:

  | datetime | Close | HP_Trend_Cycle
2020-01-01 | 91.90 | None
2020-01-02 | 91.90 | None
2020-01-03 | 92.28 | None
2020-01-06 | 92.09 | None
2020-01-07 | 92.34 | None
... | ... | ...
2022-09-01 | 78.56 | None
2022-09-02 | 79.45 | None
2022-09-05 | 79.82 | None
2022-09-06 | 79.17 | None
2022-09-07 | 79.54 | None

for jhta.CRSI, could you please give a sample case.

i use binance kline data to build the crsi list, but can't work on it. don't know howto use the CRSI function.

    # Get Binance Data into dataframe
    candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)
    df = pd.DataFrame(candles)
    df.columns=['timestart','open','high','low','close','?','timeend','?','?','?','?','?']
    df.timestart = [datetime.datetime.fromtimestamp(i/1000) for i in df.timestart.values]
    df.timeend = [datetime.datetime.fromtimestamp(i/1000) for i in df.timeend.values]

    # Compute RSI after fixing data
    float_data = [float(x) for x in df.close.values]
    np_float_data = np.array(float_data)
    rsi = talib.RSI(np_float_data, 14)
    df['rsi'] = rsi

     pp (jhta.CRSI(df.rsi, df.rsi, 3))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.