Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
TALIB_C_VER: 0.7.1
TALIB_C_VER: 0.8.1
PIP_NO_VERIFY: 0
PIP_VERBOSE: 1
CIBW_BEFORE_BUILD: pip install -U setuptools Cython wheel meson-python ninja && pip install -U numpy
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
0.8.0
=====

- [NEW]: Support TA-Lib C 0.8.1, which is now the minimum required version.

- [NEW]: New functions from TA-Lib C 0.8.1: CMF, CMOU, HMA, NVI, PVI, PVO, VWMA.

- [NEW]: New moving averages ``MA_Type.HMA`` and ``MA_Type.DISABLED``.

- [FIX]: ``abstract`` raised ``KeyError`` on function and output flags added
after this wrapper was written; unknown flag bits are now ignored.

- [CHANGE]: ``APO`` and ``PPO`` now default ``matype`` to EMA, and ``BBANDS``
defaults ``timeperiod`` to 20, following TA-Lib C 0.8.1.

0.7.1
=====

Expand Down
41 changes: 32 additions & 9 deletions talib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,30 @@ def wrapper(*args, **kwds):
_wrapper = lambda x: x


from ._ta_lib import (
_ta_initialize, _ta_shutdown, MA_Type, __ta_version__,
_ta_set_unstable_period as set_unstable_period,
_ta_get_unstable_period as get_unstable_period,
_ta_set_compatibility as set_compatibility,
_ta_get_compatibility as get_compatibility,
__TA_FUNCTION_NAMES__
)
# The TA-Lib C library this wrapper is built against
TA_LIB_C_REQUIRED = '0.8.1'

try:
from ._ta_lib import (
_ta_initialize, _ta_shutdown, MA_Type, __ta_version__,
_ta_set_unstable_period as set_unstable_period,
_ta_get_unstable_period as get_unstable_period,
_ta_set_compatibility as set_compatibility,
_ta_get_compatibility as get_compatibility,
__TA_FUNCTION_NAMES__
)
except ImportError as error:
# Loading the extension resolves its symbols against whatever TA-Lib C is
# installed. Linking never catches a too-old library -- a shared object may
# keep undefined symbols -- so a missing function shows up here instead, as
# "undefined symbol: TA_CMF_Lookback" or the macOS/Windows equivalent.
raise ImportError(
'%s\n\n'
'talib could not load its extension module. This build requires the '
'TA-Lib C library %s or later; an older one is missing functions this '
'wrapper calls. See https://ta-lib.org/install/'
% (error, TA_LIB_C_REQUIRED)
) from error

# import all the func and stream functions
from ._ta_lib import *
Expand Down Expand Up @@ -191,6 +207,7 @@ def wrapper(*args, **kwds):
'BOP',
'CCI',
'CMO',
'CMOU',
'DX',
'IMI',
'MACD',
Expand Down Expand Up @@ -220,6 +237,7 @@ def wrapper(*args, **kwds):
'BBANDS',
'DEMA',
'EMA',
'HMA',
'HT_TRENDLINE',
'KAMA',
'MA',
Expand All @@ -233,6 +251,7 @@ def wrapper(*args, **kwds):
'T3',
'TEMA',
'TRIMA',
'VWMA',
'WMA',
],
'Pattern Recognition': [
Expand Down Expand Up @@ -324,7 +343,11 @@ def wrapper(*args, **kwds):
'Volume Indicators': [
'AD',
'ADOSC',
'OBV'
'CMF',
'NVI',
'OBV',
'PVI',
'PVO',
],
}

Expand Down
17 changes: 12 additions & 5 deletions talib/_abstract.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -599,23 +599,29 @@ def __get_flags(int flag, dict flags_lookup_dict):
max_int = int(math.log(max(value_range), 2))

# if the flag we got is out-of-range, it just means no extra info provided
if flag < 1 or flag > 2**max_int:
if flag < 1:
return None

# In this loop, i is essentially the bit-position, which represents an
# input from flags_lookup_dict. We loop through as many flags_lookup_dict
# bit-positions as we need to check, bitwise-ANDing each with flag for a hit.
# A bit we have no description for means the installed ta-lib is newer than
# this build knows about; skip it rather than raising.
ret = []
for i in xrange(min_int, max_int+1):
for i in xrange(min_int, max(max_int, int(math.log(flag, 2))) + 1):
if 2**i & flag:
ret.append(flags_lookup_dict[2**i])
description = flags_lookup_dict.get(2**i)
if description is not None:
ret.append(description)
return ret

TA_FUNC_FLAGS = {
16777216: 'Output scale same as input',
33554432: 'Function has a streaming API',
67108864: 'Output is over volume',
134217728: 'Function has an unstable period',
268435456: 'Output is a candlestick'
268435456: 'Output is a candlestick',
536870912: 'Output is path-dependent',
}

# when flag is 0, the function (should) work on any reasonable input ndarray
Expand All @@ -642,7 +648,8 @@ TA_OUTPUT_FLAGS = {
512: 'Output can be negative',
1024: 'Output can be zero',
2048: 'Values represent an upper limit',
4096: 'Values represent a lower limit'
4096: 'Values represent a lower limit',
8192: 'Output is optional (nullable)',
}

def _ta_getFuncInfo(char *function_name):
Expand Down
4 changes: 3 additions & 1 deletion talib/_common.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _ta_shutdown():
_ta_check_success('TA_Shutdown', ret_code)

class MA_Type(object):
SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, MAMA, T3 = range(9)
SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, MAMA, T3, HMA, DISABLED = range(11)

def __init__(self):
self._lookup = {
Expand All @@ -73,6 +73,8 @@ class MA_Type(object):
MA_Type.KAMA: 'Kaufman Adaptive Moving Average',
MA_Type.MAMA: 'MESA Adaptive Moving Average',
MA_Type.T3: 'Triple Generalized Double Exponential Moving Average',
MA_Type.HMA: 'Hull Moving Average',
MA_Type.DISABLED: 'No Moving Average (identity)',
}

def __getitem__(self, type_):
Expand Down
Loading