Why ranking securities in a trading system is important and how it works?
This post will try to answer these questions and show you three different methods to rank securities in a trading system. Each method has of course its own advantages and disadvantages and you should apply the one that is most appropriate for your situation.
Why ranking stocks?
Here is an example: You create a trading system that buys a security when the relative strength index crosses above 70.
You have no positions in your trading system and you have specified that the maximum number of positions that your portfolio can contain at the same time is 5.
On the first day, the simulator or backtester founds that 10 stocks meet your buy rule criterion. He can then buys those 10 stocks, however, he also know that you want a maximum of 5 positions in your portfolio.
So, the question is, how will the simulator choose those five stocks? (among the 10 available)
The answer is by ranking those stocks based on a metric and then choosing the ones that have the highest score. It is a simple and powerful technique.
Trading System Example
Let us create a basic trading system to demonstrate how to use the different ranking methods explained in this article.
- Select "Analysis" then "Simulator"
- Click on "New" to create a new strategy
- Select "Create trading system using the formula editor" tab
- Type the following formula:
buy = rsi(14) > 70; // Buy when 14-Bar RSI is above 70
sell = rsi(14) < 30; // Sell when 14-Bar RSI is below 30
The first technique consists of applying a ranking system. You can implement a ranking system within the "Create Trading System" form or by using the ranking system tool, which can be opened by selecting "Analysis" then "Ranking System Manager".
Select the "Ranking" tab then click on "Define Long & Short Ranking System". You can create two different ranking systems, one for the long and one for the short strategy.
In "Simulator Ranking System", you can choose to load an existing ranking system by clicking on "Select a ranking system" button or create a new one by selecting "Update ranking system".
Let us create a new one:
- Click on "Update ranking system" button
- In the new form, click on "Add Formula"
- Select the new formula node (No Name)
- In the "formula" field (bottom), type:
- Click on "OK"
Our simulator will now rank stocks based on their 14-bar relative strength index.
The following technique consists of implementing the ranking system directly within the trading system formula.
You can do with the help of two functions: SetSimLongRank and SetSimShortRank. The former allows you to define the ranking formula for the long strategy and the latter the ranking formula for the short strategy.
Given our previous example, you can define the 14-bar relative strength index as a rank measure by typing the following line (in the formula editor)
To give higher rank to stocks with low RSI value, use the minus sign:
If you haven't heard of the composite function then I suggest you look at the following articles:
How to create market indicators using the composite function - Part 1, Part 2 and Part 3.
This function is very powerful and it has many uses. It can also be used to rank stocks in a trading strategy. The problem, however, is that it is much slower than the other methods.
The idea is to use the "Rank" calculation method to rank stocks based on their 14-bar RSI. Only stocks, whose 14-bar RSI is above 70, are considered.
Composite Formula: rsi(14)
Calculation Method: Rank
Grouping Formula: 1 (Disabled)
Filter Formula: rsi(14) > 70
This translates into:
buy = comp(rsi(14), "rank", 1, rsi(14) > 70) <= 5;
sell = rsi(14) < 30;
Note how we compare the composite function with 5, which is the maximum number of simultaneous positions in the portfolio. We instruct the simulator to enter an order to buy a stock only it is rank is lower or equal to 5.
No Ranking in your simulation or portfolio
What happens if we do not define a ranking system and we encounter a situation as described in the beginning of this post?
The simulator will buy the first stocks that it analyzes. It usually analyzes stocks by the alphabetical order of the ticker symbol.