Hello I have definied some conditions about fundamental factors in order to select stock that meet these conditions. Within the FineSelectionFunction, I create the following list:
filtered_fine = [x for x in fine if ((x.EarningReports.BasicEPS.OneMonth - x.EarningReports.BasicEPS.ThreeMonths)/ (x.EarningReports.BasicEPS.ThreeMonths)) > 0.25
and (x.OperationRatios.ROE.OneMonth) > 0.17
and ((x.FinancialStatements.IncomeStatement.TotalRevenue.OneMonth -x.FinancialStatements.IncomeStatement.TotalRevenue.ThreeMonths)/ (x.FinancialStatements.IncomeStatement.TotalRevenue.ThreeMonths)) >0.25]
When the algo start to run I have the following error:
Runtime Error: InvalidOperation : [<class 'decimal.DivisionUndefined'>]
at FineSelectionFunction in main.py:line 51
at <listcomp> in main.py:line 51
InvalidOperation : [<class 'decimal.DivisionUndefined'>] (Open Stacktrace)
I write with try and except to handle the error but the error continue. Sth know how to fix this?
Thanks for the help
Nicolás
Jing Wu
Hi Nicolas, not every fundamental factor has values for multiple periods. When you use the fundamental factor value, please add a check to make sure their values are not zero.
filtered_fine = [x for x in fine if x.EarningReports.BasicEPS.OneMonth != 0 and x.EarningReports.BasicEPS.ThreeMonths != 0 and ((x.EarningReports.BasicEPS.OneMonth - x.EarningReports.BasicEPS.ThreeMonths)/ (x.EarningReports.BasicEPS.ThreeMonths)) > 0.25
You can check if the value of a fundamental factor for the specified period is available via the research notebook.
# add a few symbols and retrieve the factor value without specifying the period qb.GetFundamental(["AAPL","AIG","BAC","GOOG","IBM"], "EarningReports.BasicEPS")
For example the output "3M:0.035714; 6M:0.075714; 9M:0.055714; 12M:0.083571" means EarningReports.BasicEPS data are available for ThreeMonths, SixMonths, NineMonths and TwelveMonths.
Nicolas Ferrari
Hello Jing Wu, thanks for your response. Now is working!!
Best Regards,
Nicolás
Nicolas Ferrari
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!