Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help needed: How to apply TA-lib to fetched data?

I fetched the VIX data from yahoo and wanna apply the RSI indicator from ta-lib to that data. However, an error showed up: "Exception: input_arrays parameter missing required data key: close".

import pandas  
import math

rsi = ta.RSI(timeperiod = 5)

def rename_col(df):  
    df = df.rename(columns={'Close': 'close_price', 'Open': 'open_price', 'High': 'high', 'Low': 'low'})  
    df = df.fillna(method='ffill')  
    df = df[['close_price', 'open_price', 'high', 'low', 'sid']]  
    return df

def initialize(context):  
    fetch_csv('http://ichart.finance.yahoo.com/table.csv?s=%5EVIX&a=1&b=1&c=1902&d=07&e=4&f=2039&g=d&ignore=.csv',  
        date_column='Date',  
        date_format='%Y-%m-%d',  
        symbol='vix',  
        usecols=['Close', 'High', 'Open', 'Low'],  
        post_func=rename_col)  
    context.spy = sid(8554)  
    pass

def handle_data(context, data):  
    rsi_data = rsi(data)  
    log.info(rsi_data)

Can anyone tell me what's wrong with the code? Thx!

3 responses

Hello Al,

This is my attempt using zipline. I would like to see other solutions as I am interested in using TA-Lib.

At times I got this message:

18  Error   Runtime exception: RuntimeError: maximum recursion depth exceeded  

before and after amending your code but I don't know why.

P.

Thanks Peter. But in this way, RSI will have a cutoff period of 15, right? Can I calculate it using "exponential style" instead?

Tricky one!

Unfortunately, we don't support imported OHLCV bars that "override" the existing data. It sorta works anyway, but it's not robust. Similarly, we don't yet support arbitrary data being submitted into ta-lib.

The good news is that the new data API we're proposing would support having the arbitrary info passed into it.

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.