Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help with MACD

Attempting to use the MACD of two inverse ETF's on minute bars as a crossover signal between two. I've tried generating MACD both directly and also by using individual EMA calculations and I can't get the results to behave the way I think they should. None of the signals match up to my charts. Can anyone tell me what's happening here or how to get the desired result?

Thanks
-Chris

3 responses

Another backtest attempting to work through this, still no luck. Anyone?

Chris,

Try this it should work

import talib  
def initialize(context):  
    context.XIV = sid(40516)  
    context.VXX = sid(38054)  
    context.hist_period=60  
def handle_data(context,data):  
    MACD_raw_xiv, signal_xiv, hist_xiv = talib.MACD(data.history(context.XIV, "price", context.hist_period, frequency="1m"), fastperiod=12, slowperiod=26, signalperiod=9)  
    MACD_XIV = MACD_raw_xiv[-1] - signal_xiv[-1]  
    MACD_raw_vxx, signal_vxx, hist_vxx = talib.MACD(data.history(context.VXX, "price", context.hist_period, frequency="1m"), fastperiod=12, slowperiod=26, signalperiod=9)  
    MACD_VXX = MACD_raw_vxx[-1] - signal_vxx[-1]

    record(MACD_XIV=MACD_XIV, MACD_VXX=MACD_VXX)  
    log.info(MACD_XIV)  
    log.info(MACD_VXX)  

Thanks Vladimir!