Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Abnormal returns! What could be a reason for it?

I'm getting abnormal returns (-20153.24%) on running a simple strategy from 2012.

What could be the issue in the code?

It usually occurs when I get this kind of warning.
2002-10-28 22:00 WARN Your order for 267654 shares of SPY has been partially filled. 246322 shares were successfully purchased. 21332 shares were not filled by the end of day and were canceled.

"""
This is a template algorithm on Quantopian for you to adapt and fill in.  
"""
import quantopian.algorithm as algo  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline.filters import QTradableStocksUS


def initialize(context):  
    """  
    Called once at the start of the algorithm.  
    """  
    context.stock = symbol('SPY')  
    context.ma = 100

def handle_data(context, data):  
    """  
    Called every minute.  
    """  
    spy_hist = data.history(context.stock, "open", context.ma, "1d")  
    stock_weight = 0  
    if spy_hist[-1] > spy_hist.mean():  
        #if stock_weight == 0:  
            #print('SPY above MA100, we go LONG')  
        stock_weight = 1.0  
    else:  
        #if stock_weight == 1:  
            #print('SPY below MA100, we go SHORT')  
        stock_weight = 0.0  
    order_target_percent(context.stock, stock_weight)  
2 responses

Set initial capital to 100000.
Try this:

def initialize(context):  
    schedule_function(trade, date_rules.every_day(), time_rules.market_open(), True)  
    context.stock = symbol('SPY')  
    context.ma = 100

def trade(context, data):  
    if get_open_orders(): return  
    stock_weight = 0  
    spy_hist = data.history(context.stock, "open", context.ma, "1d")     

    if spy_hist[-1] > spy_hist.mean():  
        stock_weight = 1.0  
    else:  
        stock_weight = 0.0  
    if data.can_trade(context.stock):  
        order_target_percent(context.stock, stock_weight)  

Thanks a lot, Vladimir. It worked.