Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why doesn't TALIB allow you to get indicators on Weekly prices as opposed to just Daily?
import pandas as pd  
import pandas.io.data  
import pandas.io.parsers  
import datetime  
import numpy as np  
import talib 

# pulling S&P 500 daily data from yahoo  
sp  =  pd.io.data.get_data_yahoo('^IXIC',start = datetime.datetime(1972, 1, 3))


# transforming previous S&P 500 daily data to Weekly on Wednesday data  
sp5 = sp.reindex( pd.date_range( start=sp.index.min( ),  
                           end=sp.index.max( ),  
                           freq='W-WED' ) )

# Getting RSI on DAILY data  
sp = sp.sort(ascending=True)  
sp['RSI'] = talib.RSI(sp['Close'], timeperiod=10)  

I get the below output (everything looks good)

http://i.imgur.com/uPrjIfQ.gif

Attempting to get RSI on WEEKLY prices


sp5['RSI'] = talib.RSI(sp5['Close'], timeperiod=10)  

I get below output ( all NaN values)

http://i.imgur.com/2R2KFqO.gif

3 responses

Michael,

When I ran your example locally I found that the values for your weekly sampled data wasn't all NaN's, however there were very few (68) non-NaN values,.

I used the following snippet to extract which date the non-NaN values.

rsi_values = talib.RSI(sp5['Close'], timeperiod=10)  
rsi = pd.Series(index=sp5.index, data=rsi)  
rsi.valid()  

I haven't fully dived into RSI, but like MACD it may have an unstable period, http://ta-lib.org/d_api/ta_setunstableperiod.html
In general, I've found it easier to work with TA-Lib when the data set passed in is close to the same size as the timeperiod specified.

Also, I cobbled together the attached example, using our new history API, which I think gets close to the weekly RSI on S&P.

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.

Thank you for your response. However, It shouldn't matter what time frame I use because RSI is just calculated from the close and the previous datapoints close (in this case 10) right? So in a time series why wouldn't TALib be able to just take in the previous 10 closes and calculate the RSI for each datapoint?

And thank you for that snippet but I cant use a small subset of data to just pass data to a small timeperiod for algos I'm using. I need RSI value for everyday/week for all historical datapoints.

Hi Eddie. I figured it out. you just have to drop NaN values/rows before you run RSI on the Historical Close.

Like this:

> sp5 = sp.reindex( pd.date_range( start=sp.index.min( ),  
>                            end=sp.index.max( ),  
>                            freq='W-WED' ) ).dropna(axis=0)