Is there anyway to return the rank of each fundamental instead of the actual fundamental float?
This code obviously doesn't work, but demonstrates what I want to do:
top_quality = sorted(sortedByDollarVolume, key=lambda x: x.OperationRatios.ROIC.ThreeMonths.rank() + x.OperationRatios.LongTermDebtEquityRatio.ThreeMonths.rank() + (x.ValuationRatios.CashReturn + x.ValuationRatios.FCFYield).rank(), reverse=True)[:self.num_screener]
How would I create a panda series in my FineSelectionFunction that wouldc contain the rank of each symbol for each fundamental and then sort based on those rankings rather than the actual fundamental data?
Thanks for your help.
Nathan
I think I found something close - though my experience with panda is limited so I don't really know if it is doing the same thing...
Â
ROIC = sorted(sortedByDollarVolume, key=lambda x: x.OperationRatios.ROIC.ThreeMonths, reverse=True) LTDER = sorted(sortedByDollarVolume, key=lambda x: x.OperationRatios.LongTermDebtEquityRatio.ThreeMonths, reverse=True) FCFY = sorted(sortedByDollarVolume, key=lambda x: x.ValuationRatios.FCFYield, reverse=True) CR = sorted(sortedByDollarVolume, key=lambda x: x.ValuationRatios.CashReturn, reverse=True) ## Create dictionary to store scores scores = {} ## Assign a score to each stock. for i,ele in enumerate(ROIC): ROIC_rank = i LTDER_rank = LTDER.index(ele) FCFY_rank = FCFY.index(ele) CR_rank = CR.index(ele) scores[ele] = ROIC_rank + LTDER_rank + (FCFY_rank*0.5 + CR_rank*0.5) #Return top quality stocks top_quality = sorted(scores.items(), key=lambda d:d[1],reverse=False)[:self.num_screener]
Â
Rahul Chowdhury
Hey Nathan,
That's super close to the behavior I think you're looking for. I think the translation of this line
(x.ValuationRatios.CashReturn + x.ValuationRatios.FCFYield).rank()
could have been done better. You want the rank when sorted by the sum of CashReturn and FCFY, not the sum of the ranks.
Instead of sorting separately
FCFY = sorted(sortedByDollarVolume, key=lambda x: x.ValuationRatios.FCFYield, reverse=True) CR = sorted(sortedByDollarVolume, key=lambda x: x.ValuationRatios.CashReturn, reverse=True)
you can sort by the sum.
FCFY_CR = sorted(sortedByDollarVolume, key=lambda x: x.ValuationRatios.FCFYield + x.ValuationRatios.CashReturn, reverse=True)
Then you can retrieve the rank of the sum.
FCFY_CR_rank = FCFY_CR.index(ele) scores[ele] = ROIC_rank + LTDER_rank + FCFY_CR_RANK
Â
Nathan
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!