Back

Joining Historical Data and Historical Indicators

I am currently trying to train a model inside the algorithm environment on a given symbol's daily close, volume and various indicators. Ideally, I want to convert all this data to a dataframe. self.History() provides this data however I can't figure out how to join, say, a 20 day Simple Moving Average onto the dataframe.

Could somebody please advise?

Thanks!

Update Backtest








As an added note, this is easy to do in the research environemnt with the following commands: 

qb = QuantBook()
sma = SimpleMovingAverage(20)
smadf = qb.Indicator(sma,"SPY",3600,Resolution.Daily)
smadf.head(n=2)

I see no easy translation however to the Algo environment

0

Hi Corey Davis, QC historical dataframe is multi-layered, which is not easy to play with (as far as for me - -;). It would be much easier to re-create dataframes of data that you want, and then combine them (if you want). I attached a sample algo how to re-create and cobine DFs. Please check 'Logs'. Hope this helps. Thank you.

0


Thank you HanByul P - this is very helpful! My one question is how would I maintain the index of "time" in this new table in order to maintain the time series component?

0

Corey Davis, I'm glad that it was helpful. You mentioned "..in order to maintain the time series component". I'm sorry I don't understand what exactly you want. The new table could be a multi-indexed df or a panel or something else. Can you clearly describe what your goal is or can you show us what your desired output is so that we can help you better?. BTW, I attached a sample algo where the new table has 'datetime' info as a column. I think if you want to work with dataframes, it'll be much easier to work with single-indexed dataframes. Thank you.   

0


Thanks HanByul P ,

Upon reviewing this further I realize I was confused and have since clarifed. 

0

Update Backtest





0

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.


Loading...

This discussion is closed