# This Trading Algorithm Landed Me in the Top 10 on Quantopian

I have developed a trading algorithm that was able to land me on the top 10 list of Quantopian’s algo trading contest. In this article I describe the details of my algorithm.

Quantopian is a Boston-based company that aims to create a crowd-sourced hedge fund by letting freelance quantitative analysts develop, test, and use trading algorithms to buy and sell securities.

All members can compete against other members in a series of contests called the “Quantopian Open.” Anyone can join the site and enter the contests. Quantopian provides members with free data sources and tools, largely built in the Python programming language.

I have developed a trading algorithm that was able to meet their contest criteria. These are listed below:

Trade liquid stocks: Trade liquid stocks: Contest entries must have 95% or more of their invested capital in stocks in the QTradableStocksUS universe (QTU, for short). This is checked at the end of each trading day by comparing an entry’s end-of-day holdings to the constituent members of the QTradableStocksUS on that day. Contest entries are allowed to have as little as 90% of their invested capital invested in members of the QTU on up to 2% of trading days in the backtest used to check criteria. This is in place to help mitigate the effect of turnover in the QTU definition.

Low position concentration:  Contest entries cannot have more than 5% of their capital invested in any one asset. This is checked at the end of each trading day. Algorithms may exceed this limit and have up to 10% of their capital invested in a particular asset on up to 2% of trading days in the backtest used to check criteria.

Long/short:  Contest entries must not have more than 10% net dollar exposure. This means that the long and short arms of a Contest entry can not be more than 10% different (measured as 10% of the total capital base). For example, if the entry has 100% of its capital invested, neither the sum value of the long investments nor the sum value of the short investments may exceed 55% of the total capital. This is measured at the end of each trading day. Entries may exceed this limit and have up to a 20% net dollar exposure on up to 2% of trading days in the backtest used to check criteria.

Turnover:  Contest entries must have a mean daily turnover between 5%-65% measured over a 63-trading-day rolling window. Turnover is defined as amount of capital traded divided by the total portfolio value. For algorithms that trade once per day, Turnover ranges from 0-200% (200% means the algorithm completely moved its capital from one set of assets to another). Entries are allowed to have as little as 3% rolling mean daily turnover on up to 2% of trading days in the backtest used to check criteria. In addition, entries are allowed to have as much as 80% rolling mean daily turnover on 2% of trading days in the same backtest.

Leverage:  Contest entries must maintain a gross leverage between 0.8x-1.1x. In other words entries must have between 80% and 110% of their capital invested in US equities. The leverage of an algorithm is checked at the end of each trading day. Entries are allowed to have as little as 70% of their capital invested (0.7x leverage) on up to 2% of trading days in the backtest used to check criteria. In addition, entries are allowed to have as much as 120% of their capital invested (1.2x leverage) on up to 2% of trading days in the same backtest. These buffers are meant to provide leniency in cases where trades are canceled, fill prices drift, or other events that can cause leverage to change unexpectedly.

Low beta-to-SPY:  Contest entries must have an absolute beta-to-SPY below 0.3 (low correlation to the market). Beta-to-SPY is measured over a rolling 6-month regression length and is checked at the end of each trading day. The beta at the end of each day must be between -0.3 and 0.3. Contest entries can exceed this limit and have a beta-to-SPY of up to 0.4 on 2% of trading days in the backtest used to check criteria.

Low exposure to Quantopian risk model:  Contest entries must be less than 20% exposed to each of the 11 sectors defined in the Quantopian risk model. Contest entries must also be less than 40% exposed to each of the 5 style factors in the risk model. Exposure to risk factors in the Quantopian risk model is measured as the mean net exposure over a 63-trading-day rolling window at the end of each trading day. Contest entries can exceed these limits on up to 2% of trading days 2 from years before the entry was submitted to today. Entries are allow to have each of sector exposure as high as 25% on 2% of trading days. Additionally, each style exposure can go as high as 50% on 2% of trading days.

Positive returns:  Contest entries must have positive total returns. The return used for the Positive Returns constraint is defined as the portfolio value at the end of the backtest used to check criteria divided by the starting capital ($10M). As with all the criteria, the positive returns criterion is re-checked after each day that an entry remains active in the contest. The returns can be seen below:  Total Returns: 16.95 % Leverage: 1.00x Specific Returns: 5.71 % Turnover: 8.30 % Common Returns: 11.07 % Beta To SPY: -0.07 Sharpe: 0.73 Position Concentration: 0.37 % Max Drawdown: -16.09 % Net Dollar Exposure: 0.09 % Volatility: 0.06 The algorithm isn’t as sophisticated as one might think. I tried to keep it as simple as possible. The basic idea is as follows: • Trade only US securities. • Exclude ADR. • Exclude utility and financial stocks. • Include only companies with a market cap greater than > 50,000,000 USD • Compute each company’s $$value = \frac{1}{(PB \times PE)}$$ • Rank them by$latex value\$ in descending order. That way a company with a high PB and PE ratio will land at the bottom.
• Short the bottom 300 stocks and go long the top 300 stocks.
• Rebalance every day.

The complete source code can be seen below:

Written on August 20, 2021