Back to Community
Exit securities which no longer trade

What happens when my strategy can't get out of a position due, I'm assuming, to the fact that a security has vanished from the data stream?

I've got a strategy that uses fundamental data, rebalancing periodically, exiting with a trailing stop. If a security has not exited I include it in the next rebalancing event. I also have a "re-selection" event where I allow the strategy to go back to the fundamentals and request a new bundle of fresh securities to add to the remaining ones I've held on to. However, I only perform this re-selection when my open position pool drops below 10% of my original position count.

What happens here is that these securities:
CIN
H
JCL_WI
OII_WI
PCZ_WI
PHS
PUB
TIMHY
TOL_WI
UCL
WWW_WI
clog up the works.
They were "told" to exit, but did not. And they did not because they no longer exist. So, these remaining dead soldiers, who all have open positions, but no current prices, hang around my open positions count and negate the whole "Rebalance when open positions < 10% of original count of 100".

You can't close these now because they don't exist. They're stuck. Open but not open.

Here they are in November of 2007:

And here they still are in January of 2009

They're zombies, orphaned positions I can't get rid of. What to do?

14 responses

Supporting code to explore this issue. (The _WI securities, no idea where they come from or where they go, Cotton-eyed Joe.)

Start the test sometime in early 2005.

Updated with Alisa's comments below. Expired stocks are removed from new positions.

from datetime import timedelta

def initialize(context):  
    set_symbol_lookup_date('2006-07-19')  
    symbols("CIN","H", "PHS","PUB","TIMHY","UCL")  
    context.Expired = []

def handle_data(context, data):  
    today = get_datetime()  
    for stock in data:  
        if (context.portfolio.positions[stock].amount == 0):  
            if (stock in context.Expired):  
                continue  
            order(stock, 100)  
            print("Bought {0}".format(stock.symbol))  
        elif (today.month > 1 and today.year > 2008):  
            if (not get_open_orders(stock)):  
                order_target_percent(stock, 0.0)  
                print("Sold   {0}".format(stock.symbol))

    for stock in context.portfolio.positions:  
        if (stock not in data):  
            if (context.portfolio.positions[stock].amount != 0):  
                print("Position held in zombie stock {0}".format(stock.symbol))  
            else:  
                print("NO Position held in zombie stock {0}".format(stock.symbol))

    for stock in data:  
        if (stock.end_date <= (get_datetime() + timedelta(days=30))):  
            if (stock in context.Expired):  
                continue  
            order_target_percent(stock, 0)  
            print("Expired {0}".format(stock.symbol))  
            context.Expired.append(stock)  

In the real world, if you own a stock that has gotten delisted, you're stuck with the shares. They can't be sold because there is no longer a market for them. They remain part of your portfolio, but are no longer worth anything.

If your algorithm, you can use this approach to remove delisted stocks from the strategy. That should solve this issue.

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.

I ran into this problem with my early experiments with the Acquirer's Multiple algo. Here's an explanation about the *_WI tickers: https://www.quantopian.com/posts/what-do-symbols-ending-in-wi-indicate

I basically avoid buying these, but I suspect you could actually build an algo around buying into bankruptcies that you think will emerge. But my foo is just not strong enough in understanding those situations.

I also end up with some dead tickers, but I basically just try to keep track of them. I'll have to take a closer look at Alisa's suggestion tonight.

Hi Alisa,

Hmm? Doesn't sound correct regarding "...you're stuck with the shares. They can't be sold because there is no longer a market for them...[and they] are no longer worth anything." Just because company XYZ is no longer listed on an exchange supported by the Quantopian database doesn't mean that the shares would be worthless. And I could be the sole remaining shareholder in XYZ, with nobody else on the planet interested in buying my shares, but I should still have rights as an owner, which could result in cash in my pocket. Right?

I think that the bottom line is that there is no way to accurately model the value of de-listed securities using the Quantopian platform, even though they could still have value beyond the de-listing date.

If anybody has de-listed shares of presumably no value that they want to give me, I'll take 'em! The whole lot for a penny. See, there is a market.

Grant

Hi Grant,

There may be exceptions to this and I am not an expert, but once a company has been really dissolved in bankruptcy and there is no potential for re-emergence, I think those shares really are zombies.

I once foolishly bought some penny stocks recommended by an overpriced Motley Fool newsletter. Needless to say, the share prices eventually went to zero and they're still hanging around in my brokerage account to this day. You can't sell them because there is no market for them, but if you can figure out a way for USAA to transfer whatever amounts to ownership of them post-bankruptcy, I'd happily sell them to you for nothing!

Hello Dan,

Yeah, I suppose there are lots of stock certificates for buggy whip manufacturers out there. I was just highlighting that it is probably an over-generalization that immediately upon de-listing, every stock is worthless. In fact, it may be just the opposite. Buying what's been so beat down that nobody wants it could be a profitable strategy.

Grant

Hey Grant,

I see what you mean. I was having tunnel-vision about my own experience. As you point out, "de-listing" may just mean that a stock is no longer traded on a major exchange, but rather, perhaps OTC, which most of us probably avoid. You're totally right about that. We probably need a better nomenclature to discriminate between de-listed and whatever you call a company that just plain doesn't exist anymore. Even bankruptcy seems to be a transitional state from which companies may return.

Apologies for the confusion.

Regarding the fix Seong posted on https://www.quantopian.com/posts/when-a-company-gets-acquired-my-portfolio-still-owns-shares-of-the-original-company-is-that-right, and suggested by Alisa, I have not dug into the details, but there is an obvious risk of look-ahead bias if not done carefully. In a backtest, as stock cannot be dropped until after the date is was announced that it would be de-listed. Also, I'm wondering if under live trading, this information is available to an algo? Does Quantopian set the security end dates such that scheduled de-listings are visible? A quick check using SPY reveals and end date of:

2015-04-13 00:00:00+00:00  

So, I think one would have to feed any scheduled de-listing dates in using fetcher. Or am I missing something?

Grant

The most accurate treatment of these securities is to, as Alisa points out, hold on to them -- period. I too have a number of zombie stocks in my IRA (victims of '08 and specifically GMs death and phoenix rebirth). Unfortunately, if one examines them they appear to have value, when, for all intensive porpoises (grin) they do not. My desire to remove them was due to my use of open position count as a threshold for re-triggering a dip back into the set_universe pool.

I decided that, in this instance, the look ahead error was worth the discrepancy introduced as I did not want to have to rejigger this strategy. But yes, undoubtedly there is a problem with this technique. If one uses separate means of determining open positions minus expired, or works a different security management than just "stocks in data" (to me, if they were in my data they were fair game), then leaving these orphaned positions dangling is a more accurate method.

There are dozens and dozens of these walking dead that I pick up using the fundamental filter I've adopted. It's like my strategy is a terrified heroine screaming in the dark; and then here they come: "RETURNnnnssss, we want to eat your RETURNnnnsssss."

I guess I'm not following how the Q backtester handles stocks the are de-listed. It sounds like it just keeps forward-filling the price until the cows come home, but orders are dis-allowed due to the stale datetime stamps on the prices. If, in fact, the assumption is that upon de-listing, the stocks have no value, shouldn't prices be forward-filled with zeros?

Here's a quick notebook we put together today to filter out the mysterious "_WI" stocks (i.e. "When Issued").

Loading notebook preview...
Notebook previews are currently unavailable.
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.

There are other symbols which end in WI but do not have an _, but which I still think are when-issued...

Josh,

Under live trading, I don't see how you are going to handle securities that are scheduled to expire (e.g. due to de-listing)? Could you add a field to the securities data feed with this information? Or offer it as a separate data set, along with this "when issued" jazz? It seems you should also provide real time information on whether a stock has had trading temporarily suspended, but not de-listed.

Grant

We've made an update to how the backtester handles delisted securities and removes them from your portfolio. You can learn more about it here.

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.