I might be overlooking something simple here but I cannot understand why the 2 following codes don't produce the same results. They both create market orders at the exact same time. However, when I'm consolidating data myself, I always get worse fill prices. I have tested it with multiple different equities and time periods. In the added example the first difference is shown in the 2nd order.
# example 1: without consolidating data manually
class CalibratedParticleCoreWave(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2020, 2, 1)
self.SetCash(100000)
self.symbol = self.AddEquity("SPY", Resolution.Hour, Market.USA, False, 2, False)
def OnData(self, data):
if self.Portfolio.Invested:
self.SetHoldings("SPY", -1)
else:
self.SetHoldings("SPY", 1)
# example 2: with consolidating data manually
class CalibratedParticleCoreWave(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2020, 2, 1)
self.SetCash(100000)
self.symbol = self.AddEquity("SPY", Resolution.Minute, Market.USA, False, 2, False)
self.Consolidate("SPY", timedelta(minutes=60), self.OnDataConsolidated)
def OnDataConsolidated(self, bar):
if self.Portfolio.Invested:
self.SetHoldings("SPY", -1)
else:
self.SetHoldings("SPY", 1)
def OnData(self, data):
pass
Alexandre Catarino
Hi Stinus Hojensbo ,
When the algorithm subscribed to low-resolution data (hourly and daily), it only adds one data type: trade bars. In this case, market orders are filled at the last trade price (the closing price of the bar). On the other hand, when the algorithm subscribes to high-resolution data (second and minute), it adds two data types: trade bar and quote bar. In this case, the market orders are filled with the last bid or ask (according to the order direction) which is worse than using the last trade price.
Stinus Hojensbo
Alexandre Catarino, thank you for clearing that up (this should be added to the documentation imo).
Does that mean that high-resolution algorithms are more reliable since hour/daily algorithms might be showing overoptimistic fill prices?
Jared Broad
The prices aren't "unrealistic" they're just emitted on the hour-daily boundary, and we assume hourly-daily strategies are not as sensitive to the spread. Most of the time stocks move far more in an hour than the spread.
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.
Stinus Hojensbo
Jared Broad , but when I'm using an hourly strategy and putting in a market order it's filled at the immediate ask price right (if I go long)? Unless I'm creating a limit order It's not like I'm getting the last close price. Or maybe I got it wrong?
Stinus Hojensbo
didn't explain myself clearly above.
If in my backtest I use hourly data and creates a marketorder at time 10:00, it's filled in the backtest as the close price of the 10 am bar right? But if I used minute data it would be filled at the 10:00 bar.ask price right ?
would be great to get clarification on this Jared Broad . thank you :)
Jared Broad
Correct Hour-Daily bars are modeled with trade fill prices not spread.
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.
Stinus Hojensbo
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!