Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Order at market open and at market close daily strategy

In a daily strategy how do I make sure that my opening orders are placed at Market Open and that my closing order is placed at Market close?

(I've seen all the answers for a minute strategy. Just trying to find out if there is an effective way for a daily strategy.)

4 responses

Hi Tim,

I might be misunderstanding you, but if by daily strategy you mean daily mode, it's not possible to create a strategy for Market Open and Market Close execution times. In daily mode, orders are executed (at the fastest) the next bar. So if you place an order on 10/1/2014, it'll get executed on 10/2/2014 at the closing price of 10/2/2014.

However in minutely mode, you can execute an order as soon as 9:31:00 AM and as late as 3:59:00 PM. You mentioned that you've seen the answers for minutely strategies but these are some threads that can help if you haven't already viewed them.

Feel free to clarify if this wasn't what you were asking about

Seong

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.

Tim ~

You can make orders at the open or close in daily backtesting mode by using a custom slippage model. Grant Kiehne helped me out with this - you can find more here: https://www.quantopian.com/posts/backtest-results-different-in-minute-and-daily-mode

I stand corrected! Sorry Tim!

I think that the code I posted would need some tweaking to buy at the open and sell at the close. As it stands, it will only apply one price (e.g. at or near the daily close). If you'll always be buying at the open, and selling at the close, you could use the sign of the number of shares to distinguish between an open buy and a close sell. Otherwise, maybe another global could be used (e.g. a dictionary of order IDs and order types, open or close). --Grant