Hey,
I've checked the Documentation (https://www.quantconnect.com/docs/algorithm-reference/historical-data) but could not find any examples for handling historical Tick data.
5 Minutes before the Market opens I want to process the Tick-Data of the last 2 trading days to make a guess for the upcoming session. Its very important that the last 2 days are trading days (e.g on a Monday I want to process Thursday and Friday).
Any hints how to achieve this?
Lukas Malik
Hey Paul,
you can do this by
first adding the stocks you want to trade in initialize
second adding a schedule function that is executed everyday before the market opens
third getting the historical data ( which was your question) with:
history = self.History(self.Securities.Keys, 2, Resolution.Daily)
this returns a pandas dataframe.
for reference you can have a look at the algorithm I posted a few days ago:
https://www.quantconnect.com/forum/discussion/7388/inside-bar-momentum-strategy-from-babypips/p1
and you can consult the documentation
https://www.quantconnect.com/docs/algorithm-reference/historical-dataPaul N. Lee
FoolishObserver: "history = self.History(self.Securities.Keys, 2, Resolution.Daily)"
This only gives me 2 daily bars but not the tickdata.
Lukas Malik
ahh i see, sorry for the confusion:
I think the main problem is that there can be multiple ticks per second so you can not be too sure of how many observations you have to look back. You could, however, change the code below to look back >2 days and then only select the relevant data according to the timestamp.
lookback = 2*24*60*60 # number of seconds in 2 days
history = self.History(self.Securities.Keys, lookback, Resolution.Tick)
hope this helps!
Rahul Chowdhury
Hey Paul,
Tick data is raw unfiltered data. There may be bad ticks which skew your trade results. You can learn about how to handle tick data in the documenation.
All the tick data from a given second is grouped together in backtesting. This means you can follow FoolishObserver's logic to retrieve the lookback period for the history call.
Best
Rahul
Paul N. Lee
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!