Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Handling company acquisition

While trying to develop some strategies, I have noted my cash was always going negative. I have taken care of closing all open orders before any rebalance, and I am exclusively using order_target_percent (both tips I have found in this excellent community). After some debugging, I have discovered the cause for this was related to companies being acquired by another.

In the following backtest (which is a concise algo for replicating the case with minimum code), the company named RIN (RINKER GROUP LIMITED ADS) has been acquired at about June 2007. From this day on, RIN continues to exists in the portfolio and, for every order_target_percent later, the algo produced a negative cash equivalent to the value of the "dead" RIN positions.

The same happens to bankrupted companies, as in the LEH. The impact on cash is not that big, because such company slowly decrease value and almost zeroes out when delisted (see the return reducing from May 2008 to Sept 2008 due to LEH decline).

If you try to sell these companies after the merge/bankruptcy, the order is accepted but never completes.

I have made an workaround to avoid negative cash by doing an artificial leverage (smaller than 1.0, derived from the inactive stocks value) while calling all order_target_percent, in order to compensate the negative cash. But this is not realistic since I would never get the cash back from those acquisitions.

What would be the best way to handle these situations?

10 responses

Thanks a lot.

I have thought about this workaround, but I was expecting this would be handled by Quantopian system in a different and more automated way. The referenced post suggest we sell the company a few days (2 days in the case) before the company ends trading (by checking the end_date field. I guess this would be a fairly reallistic way, since I would say we dont get surprised by some company ending operations from night to day. In real life situations, we might have time to sell the company. In the case of an acquisition, an algo would only be buying the new owner company if that fits its criteria. In the above example, I have found 4 days before is a minimum. Otherwise, the order might not be executed. This could be an issue with other companies in such situation.

I believe such issue might be happening more frequently with the use of get_fundamentals to set the universe of companies to buy stocks. I have found RIN (and a dozen others) while developing a filter for healthy dividend growth companies.

I have implemented an utility function sell_companies_about_to_end which is called from handle_data.
We could also avoid buying companies who are about to die, by calling the function is_company_about_to_end , right before considering a company for a new purchase.

Anyway,

Why order_target_percent produces leverage (negative cash) when these dead companies are in the portfolio? Isnt this a bug?

order_target_percent functions make their calculations based on filled orders, and don't consider the status of open orders to reach their target. As a guard, add this check to your code:

if get_open_orders():  
    return  

Here's a thread with more explanation: https://www.quantopian.com/posts/order-target-percent-ordering-too-much

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.

Alisa,

Thats what I do. But whenever we have delisted stocks in our portfolio, order_target_percent produces negative cash, as you can see in my first backtest, or the second one, by setting context.adjust_for_inactive_stocks to False.

Hi Rafael,
The problem is that the stock becomes unlisted, and the value of the stock is removed from the net positional value when ordering. You can see, in the backtest below, on 8/1/2007, RIN gets acquired and the algorithm can no longer order that stock. Subsequently, order_target_percent is called for your other two stocks, and they increase their target from 33% to 50% of your portfolio. However, RIN has not been sold, so extra cash is used to increase from 66% to 100% of your portfolio which is why it goes negative. I agree, this behavior definitely isn't intuitive! Sorry about that.

Gus

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.

Wouldnt it be easier to close the position and get cash automatically when a company is delisted?

The problem is that in backtesting, once the end_date has passed, you are stuck with positions. There is no automatic exiting of a position upon delisting.

A recent thread on the topic:

https://www.quantopian.com/posts/dealing-with-securities-that-expire

Isn't this a major problem for bankruptcies and stocks that get halted then delisted and immediately lose most of their value (like Chinese frauds)? As far as the backtester knows, it's still trading at the last listed price but in reality your position would be down 90%.

This also poses a problem for the workaround since it will "look into the future" and get you out of stocks before those events happen, sidestepping the losses.

Walter Lu,

I am using the workaround, but since the beginning I thought I would be introducing some kind of lookahead bias. Since we dont have an official solution, I will keep using the workaround.