Trading System: Buy Stocks based on their Sharpe Ratio Rank

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".

Trading Strategy

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...

Here are the different trading rules of our trading system:
- 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

Trading System Backtesting Report

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)

Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.