I would like to get historical (e.g. trailing twelve month) fundamental data in my algorithm. The fine fundamentals available during universe selection only have the most recent quarter or most recent full year values as far as I can tell. I've seen other forum posts recommending to move the backtest start date earlier so it has time to collect the data, but this is not good for a few reasons: it won't work for a live algorithm, it makes porting research code to backtest much more involved, and I have use cases where I may want a longer period (5-10 years) of historical fundamental data.
So, why can't I just instantiate a QuantBook inside my algorithm and call GetFundamental()? It seems to work (see attached backtest). It would be easy to write a simple wrapper that prevents forward bias by enforcing calls to GetFundamental() do not ask for any data past current algorithm time.
Questions:
- Is there any reason GetFundamental() is not in QCAlgorithm, with the same guardraiils against forward bias that is there for History()? This would be much preferred to my hack.
- Are there any framework issues that may arise with instantiating a QuantBook and calling GetFundamental() inside a backtest? From the code it looks like it shouldn't affect any global state but I am not too familiar with the internals of LEAN.
Thanks,Karthik
Derek Melchin
Hi Karthik,
There shouldn't arise any framework issues from instantiating a QuantBook in the backtesting environment, however, it's not what the QuantBook class is intended for. We are adding a fundamental history method to the backtester. Subscribe to this GitHub Issue to be notified of our progress.
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.
Greg Kendall
Pretty slick. I was running a backtest algorithm to collect initial data on a fundamental universe and then storing that into an ObjectStore and then running a script in the research environment that would read in the ObjectStore, get the needed historical fundamental data and make buy/sell decisions and then store those decisions in another ObjectStore and then run a second backtest algorithm that processed the trades. The research environment is much easier to use to get fundamental historical data and play around with it. It will be nice when the backtest environment can do historical fundamental data calls, but this is a slick solution until then! Thanks, Karthik Kailash
Big mak
As of some point in the last week, this isn't working anymore. Cloning and running the exact algorithm in the original post gets an ugly error.
All versions of my algorithms that use this also stopped working with similar errors. Even copy-pasting previously successful backtests throws errors. Derek Melchin , any ideas how we can approach fixing this while the github issue you linked is still in progress?
Big mak
A little bit more information to help debugging; this link in the docs says to replace qb = Quantbook() with qb = self. Doing this avoids the error.
However, it also says “GetFundamental in research does not have any counterpart in backtesting”. This is certainly a recent change since GetFundamental worked up until last week in the backtester.
Why remove this? This was a perfect workaround while we don't have fundamental history.
Louis Szeto
Hi Big mak
We've tested the backtest attached in the original post, which did not result in any error. However, we would not recommend using this method to obtain Fundamental history as this method received datetime object that could be a future time of the backtest's time. You might easily fall into the trap of forward bias! Similar reason on why "GetFundamental in research does not have any counterpart in backtesting". You could easily create your own fundamental history by pandas dataframe for backtesting.
As for research purposes, the .GetFundamental method is also working. Please find the embedded backtest and research notebook as references.
Best,
Louis Szeto
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.
Big mak
Louis,
I just checked the OP algorithm and my own algorithms - it's all working now. No idea what happened a few days ago but it was definitely not working for some time, producing the error I linked above. I understand the concerns on the forward looking bias: I worked extremely hard to avoid this by creating my own wrapper. Check out my thread here.
Karthik Kailash
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!