RealTest User Guide
RealTest User Guide

 

 

Navigation: Realtest Script Language > Syntax Element Details >

#DenseRank

 

 

 

 

Category

Cross-Sectional Functions

Description

For each date, evaluates a formula for each symbol, then calculates the rank of each symbol's value among all symbols on that date and stores those rank numbers in the data item array for each symbol.

Syntax

#DenseRank formula

Example

Data:
   Factor: ROC(C, 20)
   SectScore: #Avg #BySect Factor
   DenseSectRank: #DenseRank SectScore
   RankInSect: #Rank #BySect Factor
   TopPick: DenseSectRank <= 5 and RankInSect = 1

This first calculates a sector score as the average 20-day return of the symbols in that sector. All symbols in the same sector will have the same score. #DenseRank is then used to assign sector ranks to each symbol starting with 1 for the top sector, 2 for the next sector, etc. This makes it possible to determine e.g. the top stock from each of the top 5 sectors using a custom scoring factor.

Notes

If the formula result is nan (not a number -- unable to calculate) then that stock is not included in the ranking list (reducing the total count) and its rank value would be nan as well.

If the formula result is the same for two symbols then they both get the same rank number. Use #Rank if you want every symbol to have a unique rank number.

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC