#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

Updated on 2011-05-03

Here is how to implement a trading system based on ranking stocks by their Sharpe measure. The strategy is not difficult to implement, although it use advanced techniques.

Sharpe Ratio

This ratio measures the excess return or risk premium per unit of risk of an asset or trading strategy. In this strategy, we will use the Sharpe ratio to measure individual stocks. The technical indicator that calculates the Sharpe ratio is already available in QuantShare and its name is "Sharpe".

The idea is to rank stocks daily based on their one-month Sharpe ratio. The stock that has the highest Sharpe ratio will get a score of one, the next one will get a score of two...

- Ignore illiquid stocks and stocks from OTC exchanges
- Buy the top 20 stocks (Sharpe score lower than 20)
- Sell the ones that no longer belong to our top 20
- Market Timing: Enter new positions only if the average Sharpe ratio of all stocks (not including illiquid stocks) is higher than 0.4

The backtest report shows that our strategy produced an annual return of 24.16% for the 2001-2011 period. The maximum drawdown is equal to 25.83% and the trading system Sharpe ratio is 1.01.

The overall performance of the strategy can be highly improved by adding new buy/sell rules, adding stop rules, optimizing the different trading indicator variables, adding some money management rules...

Optimization

There are several variables you can optimize; you can for example calculate the Sharpe ratio of the last year or 10 days instead of the last month; or you can increase the maximum number of positions and buy the top 30 or 50 stocks.

Here is an example that shows you how to optimize the lookback parameter of the Sharpe ratio:
Optimize("param1", 10, 50, 10);
sp = Sharpe(close, param1);

We specified that the variable "param1" should be optimized with the following settings: Min=10, Max=50, Step=10. This will create five trading systems.

Formula

Here is the complete formula that we used to implement this strategy: (In Symbols Selection control, do not include OTC stocks)

filter1 = close > 2 and close*sma(volume, 30) > 500000;
sp = sharpe(close, 25);
market1 = Comp(sp, "avg", 1, filter1);
rank1 = Comp(sp, "rank", 1, filter1);
buy = rank1 < 20 and market1 > 0.4;
sell = rank1 >= 20;