Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API change rationale? #3

Closed
wilki2021 opened this issue Jun 30, 2012 · 3 comments
Closed

API change rationale? #3

wilki2021 opened this issue Jun 30, 2012 · 3 comments

Comments

@wilki2021
Copy link

So not necessarily an issue, but curious why you made the recent API change to eliminate the index that talib returns by default. Is there a way to get that value - it seems like it may be useful in certain contexts.

@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jul 2, 2012

I was a little conflicted -- the old way allocated only as much space as was needed to store the results from TA-Lib, which should be fast and exact. On the other hand, the new way makes it easy to integrate TA-Lib with pandas if all arrays share a common index (i.e., are the same length and the lookback period in the beginning is padded with nan), for example:

d = {}
d['MACD'] = talib.MACD(...)
d['EMA'] = talib.EMA(...)
d['RSI'] = talib.RSI(...)

columns = d.keys()
data = np.column_stack([d[key] for key in columns])
df = pandas.DataFrame(data, columns=columns)

If you've got API suggestions, I'm all for it. I could even generate both API's easily enough if there is interest...

@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jul 2, 2012

Also, I forgot the mention:

To get the "lookback" value that was previously returned, you can just find the index of the first non-nan value.

rsi = talib.RSI(...)
lookback = np.where(~np.isnan(rsi))[0][0]

@wilki2021
Copy link
Author

Thanks. In hindsight, I was too quick too submit the question and think you
probably made the right decision. I am only doing some basic plotting with
matplotlib, but after I got the code changed for the new API I actually liked it
better. Thanks for the work to create this - it was very helpful to get ta-lib
easily integrated in Python.


From: John Benediktsson
reply@reply.github.com

To: wilki2021 bob.wilkinson@sbcglobal.net
Sent: Sun, July 1, 2012 8:07:08 PM
Subject: Re: [ta-lib] API change rationale? (#3)

I was a little conflicted -- the old way allocated only as much space as was
needed to store the results from TA-Lib, which should be fast and exact. On the
other hand, the new way makes it easy to integrate TA-Lib with pandas if all
arrays share a common index (i.e., are the same length and the lookback period
in the beginning is padded with nan), for example:

d = {}
d['MACD'] = talib.MACD(...)
d['EMA'] = talib.EMA(...)
d['RSI'] = talib.RSI(...)

columns = d.keys()
data = np.column_stack([d[key] for key in columns])
df = pandas.DataFrame(data, columns=columns)

If you've got API suggestions, I'm all for it. I could even generate both API's
easily enough if there is interest...


Reply to this email directly or view it on GitHub:
#3 (comment)

@mrjbq7 mrjbq7 closed this as completed Oct 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants