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)