Comments (5)
Do you have a traceback where the TypeError
comes from?
And perhaps a reduced test case I could look at?
from ta-lib-python.
Here's an example
>>> data = {'open': np.random.random(50),
'high': np.random.random(50),
'low': np.random.random(50),
'close': np.random.random(50),
'volume': np.random.random(50),
'date' : np.random.random(50),
'adj_close': np.random.random(50)}
>>> SMA(data)
TypeError Traceback (most recent call last)
<ipython-input-20-0158c278e771> in <module>()
----> 1 function(data)
/usr/local/lib/python2.7/dist-packages/talib/abstract.so in talib.abstract.Function.__call__ (talib/abstract.c:5486)()
/usr/local/lib/python2.7/dist-packages/talib/abstract.so in talib.abstract.Function.__call_function (talib/abstract.c:5885)()
/usr/local/lib/python2.7/dist-packages/talib/func.so in talib.func.SMA (talib/func.c:69149)()
>>> SMA
{'input_names': OrderedDict([('price', 'close')]), 'display_name': 'Simple Moving Average', 'name': 'SMA',
'parameters': OrderedDict([('timeperiod',
{'volume': array([ 0.19965879, ... 0.66562178]),
'adj_close': array([ 0.18462606, ... 0.79650523]),
'high': array([ 0.14084359, ... 0.97573142]),
'low': array([ 0.96886568, ... 0.64990915]),
'date': array([ 0.17448305, ... 0.09247204]),
'close': array([ 0.10051449, ... 0.94898851]),
'open': array([ 0.85688113, ... 0.33030068])})]),
'output_flags': OrderedDict([('real', ['Line'])]),
'function_flags': ['Output scale same as input'],
'group': 'Overlap Studies', 'output_names': ['real']}
>>> SMA.set_parameters({"timeperiod": 10})
>>> data.pop('date')
>>> data.pop('adj_close')
>>> SMA(data)
array([ nan, nan, nan, nan, nan,
nan, nan, nan, nan, 0.40497346,
0.49296423, 0.54406229, 0.58375268, 0.63764305, 0.63466835,
0.6657193 , 0.64639348, 0.60670473, 0.61295131, 0.55539159,
0.51127633, 0.49951175, 0.49663316, 0.44724503, 0.49235661,
0.47239197, 0.48633259, 0.48177433, 0.43214096, 0.40667698,
0.35579172, 0.32571917, 0.31783613, 0.32140285, 0.33196072,
0.27834638, 0.31270933, 0.30925288, 0.30648999, 0.36263089,
0.38288212, 0.35386921, 0.35011754, 0.35883574, 0.35319137,
0.37672038, 0.36098139, 0.44618779, 0.51315401, 0.53659522])
I was looking at the abstract.pyx
file and have a possible suggestion. This should strip off any keys that are not valid and make sure that the keys that are required are there. Havent tested it but hope it helps.
def set_input_arrays(self, input_arrays):
if isinstance(input_arrays, dict)
count = 0
for key in input_arrays.keys():
if key in __INPUT_ARRAYS_KEYS:
count += 1
else:
input_arrays.pop(key)
if count == len(__INPUT_ARRAYS_KEYS):
self.__input_arrays = input_arrays
self.__outputs_valid = False
return True
return False
from ta-lib-python.
Ah, I see what you're saying -- @briancappello want to put together a patch and testcase?
from ta-lib-python.
Something like this? The biggest difference from what @JeffMGreg posted is that this only checks that the current indicator function's required input keys are satisfied. (In other words, if SMA only needs "close" to run, passing {'close': np.random.rand(100)} as input_arrays would suffice.)
def set_input_arrays(self, input_arrays):
if isinstance(input_arrays, dict):
reqd_keys = self._input_price_series_names()
missing_keys = []
for key in reqd_keys:
if key not in input_arrays:
missing_keys.append(key)
if not missing_keys:
self.__input_arrays = input_arrays
self.__outputs_valid = False
return True
else:
raise Exception('input_arrays parameter missing required data '\
'key%s: %s' % ('s' if len(missing_keys) > 1 \
else '',
', '.join(missing_keys)))
return False
from ta-lib-python.
I released 0.4.7 with a fix for this.
from ta-lib-python.
Related Issues (20)
- installation error on MacOS HOT 3
- problem with PVT indicator HOT 2
- TA-Lib Installation error (Windows 11 64 bit, Python 3.11 64 bit, IDE Pycharm), Visual Studio 2022 HOT 5
- Is it possible to modify the definitions of "BodyLong", "BodyShort", etc. in python? HOT 5
- can not install pybinding keep giving my this error HOT 1
- please upgrade HOT 1
- Details on talib.BBAND "mattype" parameter. HOT 1
- hello please help me HOT 2
- Help, keep looping a future warning when running all strategies on script! HOT 5
- urgently needed HOT 3
- Re: EMA indicator calculation
- Not being able to install wheel file using pip HOT 1
- Request indicator: Detrended Price Oscillator
- symbol not found in flat namespace '_TA_ACOS' on MAC M1. HOT 3
- Anaconda Installation Error HOT 4
- RSI calculation bug? HOT 3
- Installation Error HOT 7
- Instalation error Win11 system HOT 3
- Windows Installation Sources not Found HOT 2
- install problem - outdated config.guess and config.sub HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ta-lib-python.