Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Market on close orders

Market-On-Close orders or 'at-the-close' orders allow you to execute a trade 'X' minutes before the market closes. This allows you to execute an order as close to the closing price as you can get.

Market-On-Close orders are used for a couple of reasons:

  • Buying or selling a stock because of an after-hours event (e.g. after-hours earnings announcement or news story)
  • Getting as close to the closing price as possible
  • If you know that the value of a stock tends to rise at the end of a trading day, a market-on-close order to sell that stock will let you take advantage of that higher price

Generally, the NYSE accepts MOC orders until 3:45pm EST. For more information on rules click here

As for the function itself endofday_activities will execute your order at 'X' minutes before market-close while endofday_check handles the time logic.

-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.

4 responses

Hello Seong,

Have you thought about the issue raised here concerning security end dates in the future for "many securities"?

[EDIT: I wrote that before I really looked at the code. It's not an issue in this algo.]

P.

Hello Seong,

Thanks for the above code - I'm using it for diffferent purposes in one of my algos. I made a change to get the early closing days from the start of the backtest rather than the security start date but that's really cosmetic.

I'm interested in the daily closing price so I check the early closing day for hour == 13 which gave me some odd results i.e.

2008-07-03endofday_check:43DEBUG2008-07-03 17:00:00+00:00  
2008-07-03endofday_check:43DEBUG2008-07-03 17:01:00+00:00  
2008-11-28endofday_check:43DEBUG2008-11-28 18:00:00+00:00  
2008-11-28endofday_check:43DEBUG2008-11-28 18:01:00+00:00  
2008-11-28endofday_check:43DEBUG2008-11-28 18:36:00+00:00  
2008-11-28endofday_check:43DEBUG2008-11-28 18:38:00+00:00  
2008-12-24endofday_check:43DEBUG2008-12-24 18:00:00+00:00  
2008-12-24endofday_check:43DEBUG2008-12-24 18:01:00+00:00  
2009-11-27endofday_check:43DEBUG2009-11-27 18:00:00+00:00  
2009-11-27endofday_check:43DEBUG2009-11-27 18:01:00+00:00  
2009-12-24endofday_check:43DEBUG2009-12-24 18:00:00+00:00  
2009-12-24endofday_check:43DEBUG2009-12-24 18:01:00+00:00  
2009-12-24endofday_check:43DEBUG2009-12-24 18:17:00+00:00  
2010-11-26endofday_check:43DEBUG2010-11-26 18:00:00+00:00  
2010-11-26endofday_check:43DEBUG2010-11-26 18:01:00+00:00  
2010-11-26endofday_check:43DEBUG2010-11-26 18:05:00+00:00  
2010-11-26endofday_check:43DEBUG2010-11-26 18:06:00+00:00  
2011-11-25endofday_check:43DEBUG2011-11-25 18:00:00+00:00  
2011-11-25endofday_check:43DEBUG2011-11-25 18:01:00+00:00  
2011-11-25endofday_check:43DEBUG2011-11-25 18:16:00+00:00  
2012-07-03endofday_check:43DEBUG2012-07-03 17:00:00+00:00  
2012-07-03endofday_check:43DEBUG2012-07-03 17:01:00+00:00  
2012-11-23endofday_check:43DEBUG2012-11-23 18:00:00+00:00  
2012-11-23endofday_check:43DEBUG2012-11-23 18:01:00+00:00  
2012-12-24endofday_check:43DEBUG2012-12-24 18:00:00+00:00  
2012-12-24endofday_check:43DEBUG2012-12-24 18:01:00+00:00  
2013-07-03endofday_check:43DEBUG2013-07-03 17:00:00+00:00  
2013-07-03endofday_check:43DEBUG2013-07-03 17:01:00+00:00  
End of logs.  

This suggests there is data on these days after the official close. (The timestamps are GMT as I am in the UK.)

P.

Peter,

You're right, the same doesn't seem to happen for hour == 16


2013-08-05endofday_check:50DEBUG2013-08-05 20:00:00+00:00  
2013-08-06endofday_check:50DEBUG2013-08-06 20:00:00+00:00  
2013-08-07endofday_check:50DEBUG2013-08-07 20:00:00+00:00  
2013-08-08endofday_check:50DEBUG2013-08-08 20:00:00+00:00  
2013-08-09endofday_check:50DEBUG2013-08-09 20:00:00+00:00  
2013-08-12endofday_check:50DEBUG2013-08-12 20:00:00+00:00  
2013-08-13endofday_check:50DEBUG2013-08-13 20:00:00+00:00  
2013-08-14endofday_check:50DEBUG2013-08-14 20:00:00+00:00  
2013-08-15endofday_check:50DEBUG2013-08-15 20:00:00+00:00  
2013-08-16endofday_check:50DEBUG2013-08-16 20:00:00+00:00  
2013-08-19endofday_check:50DEBUG2013-08-19 20:00:00+00:00  
2013-08-20endofday_check:50DEBUG2013-08-20 20:00:00+00:00  
2013-08-21endofday_check:50DEBUG2013-08-21 20:00:00+00:00  
2013-08-22endofday_check:50DEBUG2013-08-22 20:00:00+00:00  
2013-08-23endofday_check:50DEBUG2013-08-23 20:00:00+00:00  
2013-08-26endofday_check:50DEBUG2013-08-26 20:00:00+00:00  
2013-08-27endofday_check:50DEBUG2013-08-27 20:00:00+00:00  
2013-08-28endofday_check:50DEBUG2013-08-28 20:00:00+00:00  
2013-08-29endofday_check:50DEBUG2013-08-29 20:00:00+00:00  
2013-08-30endofday_check:50DEBUG2013-08-30 20:00:00+00:00  
2013-09-03endofday_check:50DEBUG2013-09-03 20:00:00+00:00  
End of logs.  

I think I know what's happening on this one. I think we built our trading database before we had a good market calendar, and we didn't filter out some of the after-hour trades on a few of the half-days. I'm tracking this one in a bug.

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.