Hi everyone,
I call a function 1 minuter after market opens everyday:
context.Schedule.On(
context.DateRules.EveryDay('SPY'),
context.TimeRules.AfterMarketOpen('SPY', 1),
Action(context.my_trade))
Then I get the histroical data for each stock in my universe:
for x in context.my_universe:
data = context.History(x, 31, Resolution.Daily)
context.Log(data)
Which returns this data:
2018-05-02 09:31:00
open high low close volume
symbol time
ASRVP RB8TP14WK0O5 2018-03-22 27.384970 27.403869 27.384970 27.384970 201.0
2018-03-23 27.384970 27.403869 27.384970 27.384970 0.0
2018-03-24 27.384970 27.403869 27.384970 27.384970 0.0
2018-03-27 27.403869 27.403869 27.403869 27.403869 200.0
2018-03-28 27.403869 27.403869 27.403869 27.403869 0.0
2018-03-29 27.403869 27.403869 27.403869 27.403869 0.0
2018-03-30 25.702939 25.702939 25.513947 25.702939 845.0
2018-04-03 25.523397 27.299923 25.523397 27.299923 348.0
2018-04-04 26.429536 26.429536 26.429536 26.429536 66.0
2018-04-05 26.304323 26.391009 26.005738 26.005738 2181.0
2018-04-06 26.304323 26.391009 26.005738 26.005738 0.0
2018-04-07 26.294691 26.294691 26.294691 26.294691 200.0
2018-04-10 26.294691 26.294691 26.294691 26.294691 0.0
2018-04-11 26.391009 26.391009 26.391009 26.391009 100.0
2018-04-12 26.487326 26.940019 26.487326 26.940019 651.0
2018-04-13 26.940019 27.373448 26.940019 27.373448 300.0
2018-04-14 26.940019 27.373448 26.940019 27.373448 0.0
2018-04-17 26.940019 27.373448 26.940019 27.373448 0.0
2018-04-18 26.940019 27.373448 26.940019 27.373448 0.0
2018-04-19 26.940019 27.373448 26.940019 27.373448 0.0
2018-04-20 26.304323 26.304323 26.304323 26.304323 100.0
2018-04-21 26.304323 26.304323 26.304323 26.304323 0.0
2018-04-24 26.304323 26.304323 26.304323 26.304323 0.0
2018-04-25 26.304323 26.304323 26.304323 26.304323 0.0
2018-04-26 26.304323 26.304323 26.304323 26.304323 0.0
2018-04-27 26.304323 26.304323 26.304323 26.304323 0.0
2018-04-28 26.313955 26.342850 26.313955 26.342850 351.0
2018-05-01 26.313955 26.342850 26.313955 26.342850 0.0
2018-05-02 27.277130 27.489029 27.209708 27.209708 460.0
Which raises the question:
What it the closing price on may 2nd given that I am calling this function 1 minute after market opens ON may 2nd .... As a matter of fact, what are the High and Low prices as well ?
Thanks a lot for clarifying this info for me,
Best
Jing Wu
context.History(symbol, 31, Resolution.Daily) request the history price in daily resolution.
The datetime index in history request is the EndTime of the bar. It is designed in LEAN to prevent the forward-looking in algorithm trading as the daily closing price is only available after the market closes. Therefore, in the timeframe, the price with the index 2018-05-02 is actually the daily open/high/low/close price on 2018-05-01.
Stephane b
I see ! Thanks ! So basically, all the prices shows in this dataframe above are actually for the day before, correct ?
Also, how can I pull the open price of a security 1 minute after the market opens ? Is there an easy/quick way to do that ? I basically want to pull theopen prices of the past 31 days (including the current day) and the closing price of the past 31 days (obviously excluding the current day)
Thanks again !
Jing Wu
Correct. The daily history request returns the price a day before because the today's close price is available after the market closes and a daily bar is constructed with open/high/low/close. However, you can get the daily open price after the market open. For example, you can schedule the event to fire 1 min after the market open and get the open price of the first-minute bar with
self.Securities[symbol].Open
Then you can append this open price to the end of the history open price series.
Stephane b
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!