What a tough algo! After running a variety of backtests and combinations of set_universe, it looks like your algorithm doesn't recover after the end of a quarter if one of those stocks went bankrupt.
In the example that you posted, your algo maintained its positions in SOQ and GNLB after the universe rollover. It wasn't able to close these positions because these stocks stopped trading during this period and we couldn't sell the stock. In the backtester, the last-known price gets forward filled. The year 2009 had many stocks exit the exchanges as companies went bankrupt!
I attached a backtest that ran from January - August 2009. I expected the algo to close the positions at the end of the quarter (March, June) and buy the new universe the following day. However, after one universe change (March 31 or June 30 as you pointed out) the algo doesn't buy the new stocks.
I dug through the code by heavily logging the information and it looks like after March 31, the line "checkFrameConditions(context, data, sellAllAtQuarter=True)" always returns true. Digging further, this line gets evaluated to true each bar after the universe rolls over:
if not context.last_frame is None and get_datetime().date() == context.last_frame.date()
As a result, the algo exits the run of handle_data() and it doesn't reach the reallocate_stocks method to buy a new universe.
If you change the set_universe to use higher-volume stocks ( 61-63%) these survived the financial downturn and kept trading. And your algorithm continues buying/selling orders. Hope this helps and if any you have any follow-up questions, I'd be happy to take another look.
Disclaimer
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.