Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Bug: wrong stats from dead stocks

Hi,

It seems there is a kind of "bug" about stats for stocks that "died".

After a stock crash, the mavg, vwap and price don't go to zero, but stay at the last known values. In other words, even if the stock does not exist anymore, high average prices are reported.

The sample shows the Lehman Brothers case for example.

Some may wonder why it matters to have stats about dead stocks. Well, if you follow a pack of stocks, your results might be misleading/wrong since the dead stocks still contribute despite they are dead.

Cheers,
Arnaud

5 responses

Hello Arnaud,

If you add the line:

print stock.price  

you will see that there is no data for LEH after 2008-09-17. The 'record' feature continues to display the last values - I think this is the bug.

P.

I think that you're both right, actually.

record() does forward-fill values, and that is what you're seeing in the graph.

That said, we don't have a clean way to handle stocks that are de-listed. Sometimes they go bankrupt and go to zero, sometimes they go bankrupt and come back at a lower value, sometimes they get de-listed and start trading OTC, etc. We don't have a canonical datasource that helps us re-value those stocks that are no longer trading. It's something we can improve in the future.

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.

Hi Dan,

Is this planned to be fixed anytime soon?
...in the meantime, is there a workaround to detect that a stock is de-listed?

@Peter:
Thanks for the answer. Interestingly, this seems related to another bug:

If you only register a single stock, the "handle_data" is apparently not even called after the stock is de-listed.

def initialize(context):  
    context.stock = sid(11326) # LEH  
    # context.aapl = sid(32146) # AAPL  
    context.count = 0  
def handle_data(context, data):  
    context.count += 1  
    record(count = context.count)  

In the above code, you will see two different curves depending if only LEH, or both LEH,AAPL are included. In the first case, the counter will stop increasing once LEH is de-listed. In the second case, the counter will continue increasing normally. Surprising, isn't it? Just try it out ;)

Hello Arnaud,

This is the converse example where 'record' would give an error if the security has not yet started trading so a check is required. With start of 2010-01-01 run:

def initialize(context):  
    pass

def handle_data(context, data):  
    if sid(40207) in data:  
        record(CELG_Z=data[sid(40207)].close_price)  

To check if current data exists for a security try

if data[sid(11326)].datetime < get_datetime():  

P.

Thanks for the tip, the datetime check works!