The examples in the documentation don't remove NaN values before sorting.
For example, if we use
def FundamentalFunction(self, fundamentals: List[Fundamental]) -> List[Symbol]:
sorted_by_pe_ratio = sorted(
[f for f in fundamentals if f.HasFundamentalData],
key=lambda fundamental: fundamental.ValuationRatios.PERatio
)
self.Log(f"First: {sorted_by_pe_ratio[0].ValuationRatios.PERatio} / min: {min([x.ValuationRatios.PERatio for x in sorted_by_pe_ratio])}")
The examples need to be updated to include np.isnan(). For example
def FundamentalFunction(self, fundamentals: List[Fundamental]) -> List[Symbol]:
sorted_by_pe_ratio = sorted(
[f for f in fundamentals if f.HasFundamentalData and not np.isnan(f.ValuationRatios.PERatio)],
key=lambda fundamental: fundamental.ValuationRatios.PERatio
)
self.Log(f"First: {sorted_by_pe_ratio[0].ValuationRatios.PERatio} / min: {min([x.ValuationRatios.PERatio for x in sorted_by_pe_ratio])}")
The second code snippet under Create Universes is an example of one that may not work as intended. The text should also explicitly mention the requirement of np.isnan() where appropriate.
Checklist
[x] I have completely filled out this template
[x] I have confirmed that this issue exists on the current master branch
[x] I have confirmed that this is not a duplicate issue by searching issues
Expected Behavior
The universe selection examples work as intended.
Actual Behavior
The examples in the documentation don't remove NaN values before sorting. For example, if we use
then we get
The examples need to be updated to include
np.isnan()
. For exampleThe second code snippet under Create Universes is an example of one that may not work as intended. The text should also explicitly mention the requirement of
np.isnan()
where appropriate.Checklist
master
branch