Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Global function - talib.SMA

Hi,

I'm using this code, code which I've seen used in other examples:

import talib as ta

globsma = ta.SMA(timeperiod = 30)

def initialize(context):  
    context.stocks = sid(24)


def handle_data(context, data):  
    sma = globsma( data )  

but I'm getting this error:

Error Runtime exception: TypeError: SMA() takes at least 1 positional argument (0 given)

Any ideas how I can get this code to work please?

Thanks.

3 responses

My point is if you look at this algo (at the end of the post):

https://www.quantopian.com/posts/help-needed-daily-indicators-in-a-minutely-backtest

In the code (cutting it down to it basics) we have:

ma = ta.MA(timeperiod=5)

def initialize(context):  
    context.stock = [sid(2), sid(24)]  
def handle_data(context, data):  
    ma_data = ma(data)  

which is essentially what I have in my code.

I'd like to understand what the error message means and why it's happening!

I'm perfectly aware that I could use this format of the call:

sma20 = ta.SMA(data[sid(24)], timeperiod=20)  

as I've been using this format. I now want to tidy up my code and do it differently.

Any help, appreciated.

Bingo!

It seems that the line import talb as ta generates the problems. Remove it and all is well. Strange, don't understand why! Any one?

ta was a wrapper that we initially built for the talib library to be easily compatible with Quantopian functions. As we grew, this built-in wrapper showed holes and we did not work to support it. It was deprecated a couple months ago. That's probably why you saw different (and incorrect) results, because your call was referencing the old wrapper.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.