Click here to Login




3 ways to rank stocks in a trading system - Simulator and Potfolio

Updated on 2011-10-25





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



Ranking System

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:

rsi(14)

- Click on "OK"

Our simulator will now rank stocks based on their 14-bar relative strength index.


Ranking Rule

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)

SetSimLongRank(rsi(14));

To give higher rank to stocks with low RSI value, use the minus sign:

SetSimLongRank(-rsi(14));


Composite Function

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.

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











no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1461 days ago

Profile Graphs
Posted 1566 days ago

QuantShare
Previous Posts

More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.