Back

A Flawed Implementation of PE Ratio Anomaly

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.

https://www.quantconnect.com/tutorials/strategy-library/price-earnings-anomaly

Thank you in advance.

Update Backtest








0

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.


Hi Miguel,

Thank you for raising the issue. We have fixed the strategy and posted the new algorithm in the Strategy Library. The problem was a logic flaw regarding the Universe Selection, and now we have added a conditional statement before coarse and fine selection to ensure a new Universe Selection happen at the beginning of each year. Please check that out!

About the setting the leverage globally or individually, you would use self.UniverseSetting.Leverage = 1.0 and self.Securities[symbol].SetLeverage(1.0) respectively. This page in the documentation should help!

Thanks for your support!

0

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.


Hi Alethea!

I really appreciate your effort and wanted to thank you for getting back to me. I apologize if I came off a little harsh. 

I really enjoy QuantConnect o7

Thanks again!

0

Hi Alethea,

Thank you for your recommendation with regards to setting margin with self.UniverseSetting.Leverage = 1.0.

However, as you can see with the Backtest attached, the leverage limit is not being respected. This is a direct clone of the updated P/E ratio anomaly strategy, with only leverage setting added, and a log message added to print portfolio.TotalMarginUsed. With an initial portfolio of $100,000, margin reads of $173,000 are shown.

Any ideas? Thank you for your time.

0


Hi Miguel Pascual ,

I ran the attached backtest and didn't get the $173000 value:

2016-01-01 00:00:00 2016-01-01 00:00:00 Current Margin Used post Liquidate: 0.0 TPV: 100000.0
2017-01-04 00:00:00 2017-01-04 00:00:00 Current Margin Used post Liquidate: 97170.88141947 TPV: 122610.04991737
2018-01-03 00:00:00 2018-01-03 00:00:00 Current Margin Used post Liquidate: 118865.2352946 TPV: 149754.43990781
2019-01-01 00:00:00 2019-01-01 00:00:00 Current Margin Used post Liquidate: 145697.84346245 TPV: 145834.229382456

I also added the total portfolio value.

Since TotalMarginUsed is the sum of holding cost (volume at acquisition), it is expected that its value rises as the total portfolio value is rising and the algorithm is buying as much stock as possible with SetHoldings.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed