Print Page  
FORMULA FUNCTIONS / CROSS SECTIONAL
FRank("formula" [, scope, sort, incl_na])
Full Description
Returns the percentile rank for each stock based on user specified parameters for the formula, the scope and the sorting direction. It works like this:
  • The formula in quotes is evaluated for all the stocks in each scope. The formula could be a single factor, like "MktCap" or more complex like "Close(0)/Close(10)".
  • The results are placed in an array
  • The array is sorted using the 'sort' parameter. If you selected a sector scope multiple sorts are executed for each sector.
  • A percentile is assigned to each stock. This is the value returned by FRank. For example: if your universe is 500 stocks the top stock in the array gets 100, the next one 100 - 100/500 = 99.8, the next one 99.6 and so on. If you rank within and industry/sector you'll have multiple stocks with 100.
Special cases:
  • NA's, if included, are always placed at the bottom of the array and all get the same percentile. The percentile assigned is the next percentile below the last meaningful value
  • Equal values get assigned the same percentile. The next non-equal value gets a percentile equal to: (percentile of the equal values) minus (number of equal values * rank-delta)

Parameters

scope: determines how stocks are grouped before ranking (see below)

sort: Direction of sort within the group
     #ASC- ascending (lower is better)
     #DESC- descending (default; higher is better)

incl_na: Whether to include stocks with NA values in the rank
     #InclNA - include NA values in the set to be ranked (default)
     #ExclNA - exclude NA values from the set to be ranked, assigning NA to such stocks

Examples

Rank within each sector by the ratio of the latest price divided by price 5 bars ago (1 week return)

FRank("Close(0)/Close(5)",#Sector,#DESC)

Rank in three groups: stocks that have a yield = 0 , yield less than 5% , and 5% or more. Then return the stock in each group with the highest MktCap rank.

setvar(@group , eval( Yield=0 , 0 , eval ( Yield > 5 , 2 , 1) ) )
SetVar(@rank,FRank("MktCap",#GroupVar,#DESC))
@rank=100

This produces these stocks in July 2020:

For Yield = 0 AMZN with a MktCap of 1.4T
For Yield 0-5 APPL with a MktCap of 1.6T
For Yield > 5 T with a MktCap of 200M


Scope Parameter

Values Stocks ETFs Description
#AllYYOperates on current universe
#Previous1YYOperates on the results from previous rules
#GroupVar1YYOperates on groups based on value of variable @Group
--------------------------- For Stocks Only ---------------------------
#SectorYOperates within each Sector of current universe
#SubSectorYOperates within each SubSector of current universe
#IndustryYOperates within each Industry of current universe
#SubIndustryYOperates within each SubIndustry of current universe
--------------------------- For ETFs Only ------------------------------
#FamilyYOperates within each ETF Family
#AssetClassYOperates within each ETF Class
#RegionYOperates within each ETF Region
#CountryYOperates within each ETF Country
#MethodYOperates within each ETF Method
#StyleYOperates within each ETF Style
#SizeYOperates within each ETF Size
#ETFSectorYOperates within each ETF Sector
1Available only in the Screener and Custom Universe