Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
the custom factor gave wrong results

following this tutorial
https://www.quantopian.com/posts/trading-vix-quandl-data-now-in-pipeline-for-backtesting-and-live-trading

And with

class TermStructureImpact(CustomFactor):  
    # Pre-declare inputs and window_length  
    inputs = [yahoo_index_vix.close, USEquityPricing.close]  
    window_length = 20  
    def compute(self, today, assets, out, vix, close):  
        #log.info(type(vix))  
        # Get the prices series of just VXX and calculate its daily returns.  
        #log.info(pd.DataFrame(close, columns=assets))  
        vxx_returns = pd.DataFrame(close, columns=assets)[sid(38054)].pct_change()[1:]  
        # Since there isn't a ticker for the raw VIX Pipeline feeds us the value of the  
        # VIX for each day in the 'window_length' for each asset. Which kind of makes sense  
        # -- the VIX is the same value for every security.  
        # Since I have a fixed universe I'll just use VXX, one of my securities, to get a single series of  
        # VIX data. You could use any security or integer index to any column, but I'll use one of my  
        # securities just to keep things straight in my head.  
        log.info(pd.DataFrame(vix))  
        #log.info(type(pd.DataFrame(vix).pct_change()))  
        #log.info(pd.DataFrame(vix).pct_change()[0])  
        vix_returns = pd.DataFrame(vix).pct_change()[0].iloc[1:]  
        #log.info(vix_returns)  
        # Calculate the 'impact.'  
        alpha = _intercept(vix_returns, vxx_returns)  
        out[:] = alpha  

I did a backtest from 11/07/2016 to 11/11/2016 and noticed the percent_change() of VIX generates a 0 result. The logging info shows a duplicate value is added on day 2 . Any ideas ?
Duplicate value on day 2