Back to Community
Quantopian Contest Tutorial

Today we added a new tutorial: Writing a Contest Algorithm. This tutorial is designed to help you write an algorithm for the upcoming new contest. The new contest will require participating algorithms to satisfy a number of criteria. The tutorial is divided into lessons which cover each of the contest criteria, providing tools, tips, and examples to help you write an algorithm for the contest.

Many of the criteria can be met in a fairly straightforward manner by supplying constraints to order_optimal_portfolio. These are covered in the tutorial lessons. Others, like beta-to-SPY or exposure to short term reversal (from the Quantopian risk model) can be a little more tricky, and frequently need to be considered much earlier on in your workflow when you are researching and designing your alpha factor(s). We are currently working on adding more content to help you meet these criteria. In the meantime, you can try providing constraints to order_optimal_portfolio as demonstrated in lessons 8 & 9. This doesn’t work well for all algorithms, but it might help in some cases. When we publish more content on these subjects, we will add them to the tutorial.

We expect the new contest to open up for submission in early February. At that time, we will make an announcement with the official versions of the new rules and the new prize structure. We recommend that you start working on an algorithm for the new contest today so that you have something ready to submit in a few weeks!

As always, we’re looking for feedback on the tutorial. As much as possible, we ask that you keep questions about the rules in the new contest rules thread, and try to keep the focus of this thread on the tutorial.


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.

5 responses

@Karl, the algorithm score is not quite the same as Information Ratio because algorithm score only computes the standard deviation (volatility) of the algo returns as opposed to IR's which is standard deviation of [Rp - Rb] aka "Active Returns". Below is contest scoring code:

def volatility_adjusted_daily_return(trailing_returns):  
    Normalize the last daily return in `trailing_returns` by the annualized  
    volatility of `trailing_returns`.  
    todays_return = trailing_returns[-1]  
    # Volatility is floored at 2%.  
    volatility = max(ep.annual_volatility(trailing_returns), 0.02)  
    score = (todays_return / volatility)  
    return score  
def compute_score(returns):  
    Compute the score of a backtest from its returns.  
    result = []  
    cumulative_score = 0  
    count = 0  
    daily_scores = returns.rolling(63).apply(volatility_adjusted_daily_return)  
    cumulative_score = np.cumsum(daily_scores[504:])  
    latest_score = cumulative_score[-1]  
    print ''  
    print 'Score computed between %s and %s.' % (cumulative_score.index[0].date(), daily_scores.index[-1].date())  
    plt.title('Out-of-Sample Score Over Time')  
    print 'Cumulative Score: %f' % latest_score  

@Karl, love to humor you, again. In your equation above:

excess_returns = algo_returns - spy_returns :: algo returns above the benchmark ie. attributable to algorithm's alpha
Score = (todays_return / volatility) :: excess_returns / std(excess_returns)

Where do you see this implementation the subtraction of SPY returns to algo returns and the subtraction of SPY volatility to algo volatility in actual code of score below?

def volatility_adjusted_daily_return(trailing_returns):
Normalize the last daily return in trailing_returns by the annualized
volatility of trailing_returns.
todays_return = trailing_returns[-1]
# Volatility is floored at 2%.
volatility = max(ep.annual_volatility(trailing_returns), 0.02)
score = (todays_return / volatility)
return score

It does not compute excess returns, only algo returns and (are you laughing now?)
it does compute excess volatility, only algo volatility to conform to IR. Do you get it now?

Quite simply Karl, and just quote Investopedia:

What is a 'Zero-Beta Portfolio'
A zero-beta portfolio is a portfolio constructed to have zero systematic risk or, in other words, a beta of zero. A zero-beta portfolio would have the same expected return as the risk-free rate. Such a portfolio would have zero correlation with market movements, given that its expected return equals the risk-free rate or a relatively low rate of return compared to higher-beta portfolios.

Read more: Zero-Beta Portfolio
Follow us: Investopedia on Facebook

And by the way Karl, I tried to give you hints in my other thread and just in case you haven't read it, here is it below and quote myself:

@Karl, "Relativity", a word made famous by Prof. Albert Einstein is the key to understanding Information Ratio in the context of market neutral strategies. What does the hedge fund industry use as benchmark for market neutral strategies? Three month US Treasury Bills (aka risk free rates) not SPY. Below I quote a Morningstar whitepaper ( :

Because market-neutral funds hedge out broad
market risk, a cashlike benchmark (such as Treasury
bills) is more appropriate than a stock or bond
market index.


Not really.. let's ask more precisely:
How do we characterise the Returns in excess of SPY even as Beta-to-SPY gets to zero?

The Holy Grail! Have you found it, please share?