RANK

Top  Previous  Next

Keyword Description

Facilitates Ranking based on user-defined criteria

Class

Expression

Where Legal

Resources

Entry Logic

Exit Logic

Initial Size

Resize

(Pre-Category)

Resize

(Category-Level)

l

l

l

 

 

 

Syntax

RANK

 

Example

Sample code

 

RANK = COL1 ' first pass assigns daily ranks in SIG code

or

IF CLOSE > SMA[CLOSE, 50] THEN RANK = ATR[15] ' first pass assigns rank conditionally (see note below)

or

COL1 = RANK

IF COL1[1] < 20 THEN BUYOPEN ' second pass references rank for entry logic

or

COL1 = RANK

SIZING[1] = COL1[1] ' second pass references/saves rank for later use in SIZ code

 

ThumbTack white

After all tagged data files have been processed, each market or issue will have been assigned a rank for each day based upon the criteria found in COL1.  On a second pass you can use RANK to enter and exit trades or pass the rank on to SIZ code in the variable SIZING[1]. Each tagged item will have it's own unique rank. The item with the highest criteria value found each day will receive a rank of 1.

ThumbTack2

Conditional Ranking operates differently from unconditional ranking. Consider a case where you have S&P 500 data that includes an additional field holding a 1 or 0,  a flag indicating current membership in the index. Since a stock could go in and out of index membership it would not be good to have a test which included all the data because doing so would introduce survivorship bias into your results. Mechanica could simply carry forward the previous rank criteria when the condition was false and assume it was a normal holiday but doing so in cases like this would create a lot of unnecessary work. So because of the workload reduction, conditional ranking will execute faster and allow for ranking much larger data sets.

With unconditional/normal ranking if a date for a certain market is skipped Mechanica assumes that it is because of a holiday.and carries forward the previous criteria so that this holiday item will still be ranked along with the non-holiday markets or issues. In the S&P 500 case mentioned above it would be fairly unusual for an index member to be on holiday when other index members were not. However, in the case of futures this type of situation would not be unusual at all. So avoid conditional ranking in cases where some markets may have holidays when others do not if you want the holiday ranking to count.

See sample code above conditional and unconditional/normal ranking.

See also:

RANKPERCENTILE