Back to Community
Contest Backtest Results is different from Research Backtest Results

Below is my initialize definition:

def initialize(context):

set_slippage(slippage.FixedSlippage(spread=0.00))  
set_commission(commission.PerShare(cost=0.001, min_trade_cost=0))  

# parameters  
# --------------------------  
context.n_stocks = 1000 # universe size, top market cap  
context.N = 4 # trailing window size, days  
# --------------------------  
schedule_function(  
    do_portfolio_construction,  
    date_rule=algo.date_rules.every_day(),  
    time_rule=algo.time_rules.market_open(minutes=1),  
    half_days=False,  
  )  

schedule_function(  
    close_all,  
    date_rule=date_rules.every_day(),  
    time_rule=time_rules.market_close(minutes=5)  
)  

attach_pipeline(make_pipeline(context), 'my_pipe')  

context.output = pd.DataFrame()  

Basically I place my long/short orders at 9:31am and close all open positions 5 minutes beforeclosing time, therefore I should not have any overnight postions unless there are some stocks /orders not filled by end of day. In research platform, my algo works properly but in contest backtest, it doesn't! It seem to be placing orders every minute. Does this have something to do with the auto detection of estimate_intraday and is my setup considered intraday? How do I rectify this?

1 response

No replies yet! Anyway after reading the post "Optimize API Required For Allocations", I was somewhat enlightened as to how this could happen and quote:

"The Optimize API allows Quantopian to intelligently adjust an algorithm's orders when external circumstances prevent us from achieving exactly the algorithm's desired portfolio. For example: There may not be enough short inventory for a stock
The prime broker may restrict Quantopian from trading in certain stocks on a given day
Situations like these mean that an algorithm can't always get exactly what it wants. Optimize handles these kinds of situations by getting you to an achievable portfolio that's as close as possible to the originally desired portfolio, but also respects both the external constraints placed upon the algorithm and the constraints provided by the author."

And this is my reply to that post, FYI:

I used the new Optimize API in two of my contest entries, however the 2 year contest backtest results are significantly different from the research backtest results (7% vs. 58%). The set up is to place all orders at 9:32am and close all at 3:56pm. In research mode, this implementation is done correctly. I understand that this could change in contest/live trading environment depending on many factors such as whether orders are filled accordingly as intended by the code, short order inventory, etc. As mentioned... "Optimize handles these kinds of situations by getting you to an achievable portfolio that's as close as possible to the originally desired portfolio, but also respects both the external constraints placed upon the algorithm and the constraints provided by the author." In my example, close as possible, is not achieved by optimize api. Short order inventory is probably why my short orders at filled partially at one minute intervals, this I understand. However, buy market orders are also partially filled at minute intervals, this baffles me because these buy orders are not large and these are very liquid stocks. What would cause these buy market orders to not be filled instantaneously as there are in the research environment? These are what's causing the huge discrepancies in my results and very misleading in my choices of algorithms to field in the contest. I need more guidance on how to avoid these pitfalls.