Advanced Functions / Group Summary Statistics
Aggregate("formula", scope [, method, outlier_pct, outlier_handl, excl_zero, excl_adrs, median_fallback])
Full Description

Returns the average or cap-weighted average for the formula for each scope. It can be used, for example, to calculate your own averages for industries or the SP500.  Most of the time we would recommend a simple average as cap-weighting results in more volatile values (for ex.if a large cap is a borderline outlier).

Parameters

formula: any valid stock formula 
scope: how stocks are grouped before the aggregate is calculated (see below) 
method: how the aggregate value is calculated. Use #CapAvg or #Avg (the recommended default)
outlier_pct: trim percent for outliers from each side. Default is 16.5% 
outlier_handler: how the outliers are treated:
   #Exclude: excludes outliers from the aggregation (default) 
   #Winsor: the outliers are set to the highest/lowest value that are not outliers 
ex_zero: when set to TRUE 0 values are discarded (handy for factors like Yield). Default is FALSE. 
ex_adrs: when set to TRUE ADR's are excluded. Default is TRUE. 
median_fallback: when set to > 0 it triggers a fallback to a simple median calculation when not enough stocks are in the scope. Handy for small industries. Default is 0 or no fallback. 

Examples


1) Screen for stocks whose PE is less than the Industry average 
PEExclXorTTM < Aggregate("PEExclXorTTM",#Industry, #Avg) 
 

2) Set the reserved @group variable to three distinct values for a) stocks that have a yield = 0 b) stocks with yield less than 5%, and c) stocks with yield of 5% or more. Then screen for stocks that have a MktCap less than the group's average.

ShowVar(@group, Eval(Yield=0, 0, Eval(Yield > 5, 2, 1))) 
ShowVar(@groupAvgCap, Aggregate("MktCap",#GroupVar, #Avg)) 
MktCap < @groupAvgCap

Copy and paste the above in the screener's text editor to see the results.


Show more details