Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help with converting daily mode talib.RSI to minutely mode talib.RSI...

Hello,

Been racking my brain a bit, here. I have a successful result when polling for a 7 day RSI in my attached example. I just wanted to succeed at getting current, previous, and before previous data. Good there, but I am unsuccessful when converting this to minute mode.

The values achieved here match StockCharts.com; this site uses a look back window of (at least) 250 data points. I interpreted this as days, so I tried to convert directly to minutes and I get nan values. By my math, starting a 7 day RSI calculation, 250 days earlier, would amount to at least 100230 minutes.

None-the-less, could someone help me convert this to minute mode?

Thank you, in advance.

Danny

2 responses

Daniel,

Try this in more then 1 year backtest:

import talib

def initialize(context):  
    context.sec = sid(14848)  
    context.tic = 0

def handle_data(context, data):  
    context.tic += 1

    if context.tic == 1:  
        prices = data.history(context.sec,'close', 260,'1d')  
        rsi7_curr = talib.RSI(prices[-9:-1],7)[-1]  
        rsi7_prev = talib.RSI(prices[-10:-2],7)[-1]  
        rsi7_b4prv = talib.RSI(prices[-11:-3],7)[-1]  
        rsi7_250 = talib.RSI(prices[-259:-251],7)[-1]

        print 'curr rsi7...  '+str(rsi7_curr)+'    prev rsi7...  '+str(rsi7_prev)+'    b4prv rsi7...  '+str(rsi7_b4prv)+'   250 day ago rsi7...  '+str(rsi7_250) 

        record(rsi7 = rsi7_curr ) 

    if context.tic == 390:  
        context.tic = 0  

Thank you for your response, Vladimir.

The only issue with singling out the calculations is that EMA is built off of previous EMAs. Stockcharts runs current EMA calculations cumulatively from 250 data points back. So, it has to cycle through every point in order to have the same value as theirs. If I can't get talib functions to work, I'll build a custom while loop. I was just hoping there was a solution to this, as my trading strategy utilizes days broken down into 1/3 increments (130 minutes).

Cheers.

Danny