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

I am trying to see the stocks that I am getting buy and sell signals using a simple VWAP comparison. However, when I try to build my algorithm, it says "There was a runtime error. See the more detailed error below", then gives no details. Does anyone know what's going on?

def initialize(context):  
    set_universe(universe.DollarVolumeUniverse(floor_percentile=97.0, ceiling_percentile=99.0))  
    context.stocks = []  
    context.max_notional = 1000000.0  
    context.min_notional = -1000000.0  
    context.index_position = 0

def handle_data(context, data):  
    # Implement your algorithm logic here.  
    context.stocks = [sid for sid in data]  
    #buys = set()  
    #sells = set()  
    for stock in context.stocks:  
        # S&P 500 ETF is sid(8554) - ticker is 'SPY'  
        if vwap_buy(stock, data) == 1:  
            # Buy stock, Sell S&P 500  
            #buys.add(stock)  
            log.info("Found BUY signal for " + str(stock))  
        elif vwap_buy(stock, data) == -1:  
            # Sell stock, Buy S$P 500  
            #sells.add(stock)  
            log.info("Found SELL signal for " + str(stock))  
        elif vwap_buy(stock, data) == 0:  
            # No Position  
            log.info("No signal for " + str(stock))  
def vwap_buy(stock, data):  
    if stock in data:  
        if data[stock].returns() > data[stock].vwap(5):  
            if data[stock].returns() > data[stock].vwap(10):  
                # Sell Signal  
                return -1  
        elif data[stock].returns() < data[stock].vwap(5):  
            if data[stock].returns() < data[stock].vwap(10):  
                # Buy Signal  
                return 1  
        else:  
            # No Position Signal  
            return 0  
5 responses

Hi Todd,

Thanks for reporting the problem. You've hit a bug that crept into our latest release. When you run a backtest, there are events for trades, but there are also events for dividends, orders, transactions, and so forth. The transforms are supposed to filter down to just the trade events, so they can assume that the events have the fields they need, such as price and volume. The returns transform is not handling the filter properly, and is raising an unexpected exception when a non-trade event comes through the pipeline.

We'll get this patched up and let you know when it is released.

thanks,
fawce

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.

Todd,
I also noticed you are comparing the returns to the vwap - just wanted to let you know that returns will be a percentage and vwap is dollars.
thanks,
fawce

Thanks Fawce!

And yeah, I should have noticed the VWAP thing but I'll change that now.

In the meantime, how might I be able to eliminate this bug?

I'd replace your calls to returns() with just the price property. That way you'll be comparing price to vwap, and you'll avoid the returns bug for now.