How can I use price earning ratio instead of price in my strategy in OnData part?
So, instead of
data[self.symbol].Close
I would like to have something like
data[self.symbol].Close / data[self.symbol].CurrentEarnings
I know CurrentEarning are not contained in the data object, but how can I get current earnings in my algo?
I saw examples with universes and fine filtering, but I only need need this for one stock.
Derek Melchin
Hi Mislav,
To receive fundamental data during a backtest, we must use a fine universe filter. Just return the single stock during universe selection in this case.
Fundamental data can then be access through the stock's Security object. See the source code for reference.
data[self.symbol].CurrentEarnings
does not exist. Consider using the `NormalizedPERatio` property from MorningStar.
See the attached backtest for reference.
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.
Derek Melchin
Hi Mislav,
(1) The difference is that we can create composite universes by using AddUniverseSelection. If we only have one universe selection model in the algorithm, SetUniverseSelection is more appropriate.
(2) To get the NormalizedPERatio into the indicator's Update method, we have to save a reference to the Security when constructing the indicator. We can then access the ratio with
self.security.Fundamentals.ValuationRatios.NormalizedPERatio
Note that to do this, we have to replace AddEquity with a FineFundamentalUniverseSelectionModel and create the indicator inside OnSecuritiesChanged. See the attached backtest for reference.
Don't feel discouraged to ask for help. Our community members are very eager to provide assistance.
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.
Derek Melchin
Hi Mislav,
(1) The technique used to warm up an indicator depends on the algorithm. In this use case, the SetWarmUp method does not work with universe selection, so we should manually warm up the indicator with a History request inside the SadfIndicator constructor.
(2) The indicator is updated automatically when we use the RegisterIndicator method.
The framework algorithm above isn't working because the indicator's Update method is not defined with the correct signature. Additionally, the indicator class is missing some members from the previous version. See the attached backtest for a working example.
If you provide further assistance, please open a new thread. Since this one is no longer just about "Earnings data in OnData", a new thread will be more helpful to community members searching for answers.
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.
Mislav Sagovac
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!