How could I resample Indicator data in Research (QuantBook)?
In an algorithm it is done via TradeBarConsolidator(...) + algorithm.RegisterIndicator(...), but how do I do that with just the QuantBook?
QUANTCONNECT COMMUNITY
How could I resample Indicator data in Research (QuantBook)?
In an algorithm it is done via TradeBarConsolidator(...) + algorithm.RegisterIndicator(...), but how do I do that with just the QuantBook?
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.
Gurumeher Sawhney
At this time there is not a quick way to consolidate data and register an indicator to the data via QuantBook. Consolidators are updated by the LEAN engine and QuantBook is "static" research environment. If this needs to be done, minute data could be transformed into higher resolution using a pandas.Dataframe. And then an indicator would need to manually run through that data. We are aware of this shortcoming and it is on our TODO list to automate the consolidation process.
Anton Voskresenskiy
I see, okay, thanks.
What's the best way of converting TradeBar sequences into pandas DataFrames and back?
Emilio Freire
Hi Guys,
I was also trying to do this and was about to post the same question so thanks Anton! Here's my first attempt but of course it does not work! I mean it works but gives many NAs.
Any suggestions?
Thanks!
Emilio
symbol = "SPY"
ticker = qb.AddEquity(symbol)
startDate = datetime(2018, 4, 1)
endDate = datetime(2018, 7, 15)
resolution = Resolution.Minute
df = qb.History(ticker.Symbol, startDate, endDate, resolution)
df.reset_index(level = 0, drop = True, inplace = True)
prices = df["close"]
offset = "1H"
ohlc = prices.resample(offset).ohlc()
ohlc
Gurumeher Sawhney
From close analysis, the reason as to the NaNs is because of the market hours. The data is populated from 9am-4pm while the market is in session. While .resample is a convenient method to resample time series data, it added a row for every time interval in the period. The rows that are populated by NaN can be dropped via df.dropna(). The notebook below has the code running:
Emilio Freire
Beautiful! Thanks!
Erez Tison
Thanks guys for this solution.
Stragling with this issue myself I found a bit more accurate method that uses the real 'open','high' and 'close of the inner tradebar in each resample.
Take a look at:Â
https://stackoverflow.com/questions/34597926/converting-daily-stock-data-to-weekly-based-via-pandas-in-pythonÂ
ÂAnton Voskresenskiy
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!