One of the samples in the Strategy Library is the PE Ratio Anomaly based on Persson/Stahlberg.

The strategy as presented is a poor implementation. As seen in the backtest with date range slightly extended, it's obvious the active security swap is implemented improperly. This is caused in part because Liquidate and SetHolding objects do not update the portfolio real time within the same OnData iteration. As a consequence, the routine selects less and less equities that do not match self.filtered_fine until all are liquidated. In addition, stocks are stored in self.Portfolio even though there are no longer any active holdings, further preventing new stocks from being added to holdings. I've spent some time trying to efficiently address these concerns but would like to give staff the opportunity to weigh in on how to address this issue.

Lastly, almost all the alpha shown in the original backtest can be attributed to the strategy's unrestrained use of leverage at 2X for equities (in spite of the active securities shortcoming). How would leverage constraints be set globally (or individually at equity swap) to prevent overexposure and false alpha? If the strategy only ever held 10 securities as designed, this may not be an issue.

Thank you in advance.