Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
avoiding de-listing of securities

In the Quantopian Open contest and real-money trading for winners, if your algo crashes, is it game over for you (although if you've made a profit, you get it). One thing I forgot to consider is that one or more of the securities in my algo could be de-listed. Here's some code that should manage de-listing. Questions/comments/improvements welcome.

def initialize(context):  
    # master list of securities  
    context.stocks_master = [sid(24),  
                             sid(8229),  
                             sid(3951),  
                             sid(20387),  
                             sid(21947)]  
    # list of available securities  
    context.stocks = []

def handle_data(context, data):  
    # build list of available securities from master list  
    context.stocks = []  
    for stock in context.stocks_master:  
        if stock.security_end_date >= get_datetime():  
            context.stocks.append(stock)  
    # number of available securities  
    num_stocks = len(context.stocks)  
    record(num_stocks = num_stocks)  
    # maintain equal-weight portfolio  
    pct = 1.0/num_stocks  
    for stock in context.stocks:  
        order_target_percent(stock, pct)  
7 responses

@Grant, I'm curious; now that you've proven your algo can make $ over the last 2 years + 1 month, how does it fair when you run it against the ugly times of '08 and '11? Is it robust enough to weather such different conditions than what we've seen for the last few years? I'll understand if you care not to answer; there are enough wicked smart people here who might tease useful information from your answer. (Since we're all essentially independent brigands and pirates here, your loss may be my gain (not that I take the contest seriously).)

Hello Market Tech,

We'll see how things play out over the next six months. I will say that there is no explicit code to guard against hitting the $90K limit. I tried to work something out, but never came up with a satisfactory solution. It's easy enough to go to cash, but then you need to decide when to go back in. If there's a 10% drawdown early on, I'm sunk (of course, if the market drops that much, then 6 months from now, it might not make it back up anyway).

Grant

Why not:

def initialize(context):  
    # master list of securities  
    context.stocks_master = [sid(24),  
                             sid(8229),  
                             sid(3951),  
                             sid(20387),  
                             sid(21947)]  
    # list of available securities  
    context.stocks = context.stocks_master 

for stock in context.stocks:  
        if stock.security_end_date >= get_datetime():  # delisted ?  
            context.stocks.remove(stock)  

It's minor.

Grant, OK, fair enough, you side-stepped the question but I generally accepted that that would be the case.

How about this question: Now that you have more than a month of real time returns, if you backtest the same algo, over the same periods that actual returns are available -- do they match? That is, can you replicate in backtest what your algo did real time? I suspect not, but I'm curious as to how far off the numbers are. And I suppose this goes for anyone paper trading for any long enough period: can you replicate your RT results in BT?

@MT check out this thread: https://www.quantopian.com/posts/backtesting-to-live-trading-progression-example

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, I remember that post. Thanks. I'm hoping Grant can confirm that a strategy that trades more frequently than once a month can also match up, RT vs BT.

Hello Market Tech,

I did a backtest of the winning algo, and the performance was similar to what resulted from the Quantopian 15-minute delayed trading over the contest month. Also, running in parallel with the Quantopian-funded algo, I have the same algo running against the 15-minute delayed data (default commission and slippage settings). After a couple trading days, there are some slight differences but nothing I'd consider significant (e.g. -0.2% simulated return versus -0.3% actual return).

You raise an interesting general point that for some styles of trading, the default commission and slippage models may not be valid (as Simon Thornington has discussed). So, if Quantopian is looking to use simulations to evaluate algos for investment by their fund, then they'll have to sort this out.

Grant