Hi All,
I love QC and I'm getting more and more into it, but I really hope the learning curve flattens out at some point because the most basic stuff takes ages to figure out! I guess the effort will pay off!
I'm just trying to join historical OHLC with some indicators in a single dataframe. I gave up after a long time trying.
The below code runs but the result is wrong as the index is not being kept properly.
Any help please?
df = qb.History(spy.Symbol, startDate, endDate, resolution)
mom = Momentum(11)
momdf = qb.Indicator(mom, "SPY", startDate, endDate, resolution)
results = pd.concat([df, momdf])
results
Gurumeher Sawhney
Thanks for submitting the code used. The indexing issue comes primarily due to the fact that the historical data is multi-indexed. Since only one asset is being analyzed, it made sense to remove the symbol index from the OHLC DataFrame. This can be done via .unstack() or .reset_index(). The notebook below has the code above running and another indicator added was to show how multiple indicators can be created and implemented into DataFrames together.
Emilio Freire
Thank you!! I understand now :)
Emilio
Ahmet sarıoğlu
Hi All,
I know this is an old thread but I'm having the same issue. Access to the code Gurumeher shared above seems to be denied. In the main.py accessing OHLC data and Indicators with rollingwindows and merging two dataframes seems tricky because of the index mismatch. Does anyone have an idea on merging price data and indicators in the main.py.
Ahmet sarıoğlu
I found the necessary code piece in the documents. Thanks anyways
Emilio Freire
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!