Back

OnData Close Price Question? Accurately retrieving the current days Close?

If I were subscribed to a single stock, let's say SPY, with a daily resolution and we are only halfway through the day what would the expected data["SPY"].Close value be? The price up to that current point? This close price could differ from that actual price at the end of the day?

I am asking because I am trying to create a rolling window of historical close prices, but my code may not be valid if I am not retrieving the most accurate close price.

def Initialize(self):
self.SetStartDate(2010, 10, 11)
self.SetCash(10000)

self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.AddForex("EURUSD", Resolution.Minute)

self.Close = RollingWindow[float](100)

def OnData(self, data):

if 8 <= self.Time.hour <= 12:
self.Close.Add(data["EURUSD"].Close)

Is the above code not capturing the most accurate closing price? If so, can someone give me some advice? I was thinking of using a RollingWindow of QuoteBars instead, but I believe I'd run into the same problem.

Many thanks and Happy New Year
Marc

Update Backtest







0

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.


In your example above you're using Minute data in the example means you'll get the close price of the previous minute, 

In your text though it says "let's say SPY, with a daily resolution". With daily resolution the if statement would never trigger as the daily data points are emitted at midnight (Time 00:00). I highly recommend using minute resolution data as much as possible to ensure accurate backtesting.

1

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.


Hey Jack,

Thanks for the clarification that the close price is of the previous minute. Do you know if these apply to other resolutions? Mid-hour and mid-day would receive the previous hour and day?

Sorry, I thought the daily resolution example would have been more helpful understanding my question since there is a 24 hour gap.

Thanks.

0

The daily example is a good one for understanding! It would be set to the last time the loop processed; for daily data, it would be the close of yesterday. 

Under the hood there's no magic; if you ask for X-resolution data; the prices will move at lagging X-time-steps. It will be the close of yesterday until 11.59.99 then at midnight the close of "today"/yesterday will arrive. So if you need intraday data, we recommend asking for as fine-grained resolution as you can handle. 

The with minute bars it arrives at 9.31 am, so if you ask for price at 9.31.30 it'll be 9.31's price. 

1

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.


Awesome thank you all for your replies!

0

Update Backtest





0

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.


Loading...

This discussion is closed