TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.69k stars 1.76k forks source link

Exception: input_arrays parameter missing required data key: close #453

Closed tesla-cat closed 3 years ago

tesla-cat commented 3 years ago

I am trying to make my own DataFrame class since I find pandas too slow

class Indexer:
    def __init__(s, df): s.df = df
    def __getitem__(s, k): return s.df[k[1]][k[0]] 
    def __setitem__(s, k, v): s.df[k[1]][k[0]] = v
class MyDataFrame(dict):
    def __init__(s, arr, columns):
        s.d = {} 
        for i,c in enumerate(columns): s.d[c] = arr[:,i]
    def __getitem__(s, k): return s.d[k]
    def __setitem__(s, k, v): s.d[k] = v
    @property
    def loc(s): return Indexer(s)

import talib.abstract as ta
candles = np.random.rand(100,6)
df = MyDataFrame(candles, columns=['date','open','high','low','close','volume'])
print(type(df['close']))
df['ma'] = ta.SMA(df, 30)

but this gives error:

<class 'numpy.ndarray'>
Traceback (most recent call last):
  File "c:\Users\rick\Desktop\simpleTrade\test.py", line 91, in <module>
    df['ma'] = ta.SMA(df, 30)
  File "talib/_abstract.pxi", line 398, in talib._ta_lib.Function.__call__
  File "talib/_abstract.pxi", line 270, in talib._ta_lib.Function.set_function_args
  File "talib/_abstract.pxi", line 221, in talib._ta_lib.Function.set_input_arrays 
Exception: input_arrays parameter missing required data key: close

how to fix this?

mrjbq7 commented 3 years ago

By default it expects columns named “close” containing numeric inputs for whatever function you are calling.

On Sep 2, 2021, at 8:23 AM, 丁瑞奇 @.***> wrote:

 I am trying to make my own DataFrame class since I find pandas too slow

class Indexer: def init(s, df): s.df = df def getitem(s, k): return s.df[k[1]][k[0]] def setitem(s, k, v): s.df[k[1]][k[0]] = v class MyDataFrame(dict): def init(s, arr, columns): s.d = {} for i,c in enumerate(columns): s.d[c] = arr[:,i] def getitem(s, k): return s.d[k] def setitem(s, k, v): s.d[k] = v @property def loc(s): return Indexer(s) but this gives error:

Exception: input_arrays parameter missing required data key: close how to fix this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.