Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline overnight

Good afternoon,
Thanks to this paper: http://www.sciencedirect.com/science/article/pii/S1059056016301563
I have been trying to develop a strategy in which I predict the direction of the "overnight returns" and of the "first 30 minutes of trading" based on the last 30 minutes of the day before.
My issue comes from the fact that when I try to use this strategy for a longer period of time for example:
01/01/2007 - today
The returns explode and the backtest stops with this error:

OverflowError: Can't order more than 100000000000 shares

Don't get me wrong, I like high returns, but is there a way to make it more realistic?
Thanks in advance,
Mattia

4 responses

Hi Mattia,

Thanks for posting and great question. The best way to make everything more realistic is to use a constrained portfolio optimizer to decide weights rather than just placing orders. We have a whole tutorial now that shows you how to do this, or you can also skip to the end and clone the algo if you prefer.

https://www.quantopian.com/tutorials/getting-started

We also have the constraints depend on our risk model, so in addition to constraints that would fix your issue (leverage), there are constraints you can adjust around things like sector and style risk exposure. I recommend keeping the defaults though as we've put a lot of work into determining those AND those are the entry requirements for our upcoming new contest.

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.

Hi Delaney,
This is a backtest in which I contain the Overflow error I mentioned in my previous post.
I really appreciated the hints that you showed me in the tutorial on how to implement a proper risk-management optimisation in my portfolio,
the problem is that when I create my boundaries:

order_optimal_portfolio(  
        objective=objective,  
        constraints=[  
            max_leverage,  
            dollar_neutral,  
            constrain_pos_size,  
            max_turnover,  
            factor_risk_constraints,  
        ])  

I cannot create a proper "objective" in my function because a variable named in this way doesn't work

objective = (for stock in longs:  
        order_target_percent(stock, long_weight)  
    for stock in shorts:  
        order_target_percent(stock, short_weight))  

Is there any other way in which I can fit it in my strategy?
Thanks again for the help
Mattia

Hello Mattia,

The objective is just a vector of weights. Each weight corresponds to your prediction of returns for that stock. If these predictions are correlated with true future returns, that's when you're likely to make money. I go over this here: https://www.youtube.com/watch?v=ArbIM0vhSYQ

This lecture may be very helpful if you want a deeper explanation of all this: https://www.quantopian.com/lectures/risk-constrained-portfolio-optimization

It seems like you just want to make two sets of predictions, one is that a set of longs will go up with uniform probability, and one that a set of shorts will go down with uniform probability. You should be able to achieve this by creating a vector of 1s, 0s, and -1s depending on whether you think a stock is in your longs, shorts, or neither. I'm going to forward this thread to Rob, who may be able to better help with this.

Here is my last result; apparently the strategy works way better with a universe of 1500 stocks instead of 500. Unfortunately I still haven't been able to understand how to apply the "objective" constraint in the for loop.