Hello,
I am really new to QuantConnect and I am having a little bit of a hard time understanding the Slice object. I need to be able to analyse TradeBars, one TradeBar at a time. So my questions are as follow:
1) Does Slice.Bars contain more than one TradeBar object?
2) What is the length (in time) of a Slice? Does it depend on my data resolution? Say I choose to have data in seconds and I want to analyze one second bars, how do I access the one second bar from the Slice object?
Thank you
Alexandre Catarino
Please checkout the docs, under Handling Data, for detailed information about the Slice object.
1) Slice.Bars refers to a TradeBars object. A TradeBars is a dictionary of TradeBar, where the key is the Symbol and the value is a TradeBar. For instance, if you subscribed to SPY and IBM, you will be able to get their bar like this:
spy_bar = slice.Bars["SPY"] ibm_bar = slice.Bars["IBM"]
Note that you can get their bars directly from the Slice object:
spy_bar = slice["SPY"] ibm_bar = slice["IBM"]
2) Yes, Slice depends on the data resolution. OnData is called with the hightest resolution we have subcribed to. For example, we asked for minute-resolution data from SPY and second-resolution data from IBM: OnData will teiggered every second. In the Slice object we will have different IBM bars every second, but SPY will only change every minute.
Angel Ortiz
How could I access the slice or handle it in the research env of quantconnect?
Derek Melchin
Hi Angel,
To get Slice objects in the Research Environment, see Request Data and Get Historical Data.
Best,
Derek Melchin
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.
Anthony Serrano
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!