Cross-sectional functions allow you to perform tests against a body of related stocks, on the fly and point in time.

### On-The-Fly Calculations

There are five basic cross-sectional functions available:

- Count (FCount)
- Median (FMedian)
- Ordinal Rank (FOrder)
- Percentile Rank (FRank)
- Sum (FSum)

You would use these to examine the entire universe and get a number that plugs into a rule. For example:

FRank("MktCap")>90

FRank gets the percentile ranks for each company in the universe, so using that inequality will return the top 10% of the universe by market cap.

### ZScore

There are two special cross-sectional functions as well. The first of them is ZScore. It returns, for each stock, how many standard deviations it is from the mean for the datum of your choice.

So for example:

ZScore("MktCap")>2

would return only stocks that had market caps more than two standard deviations above the mean.

### Aggregate

Much more complicated is Aggregate. Aggregate returns the aggregate for a given datum. Think of the function as an average on steroids.

Porfolio123 calculates its own aggregates when necessary. We have built upon a large amount of research to do so.

One quirk of financial data is that cross-sectional outliers are unavoidable, material and frequent. They are caused by actual events that happen to actual companies. That still doesn't mean that we want them in our averages.

Aggregate solves this by putting all of the data to be averaged into a row, large to small, and then lopping off about 16.5% of the population at the tails.

This may seem like a large amount, but it's actually quite reasonable. In testing, we found that for some data it was possible to cut off a total of 70% at the tails without a significant change in the averages.

By default, the aggregate function tosses 16.5% at each tail and calculates a simple mean.

But if you don't like the default, the function is capable of automatically performing a cap-weighted average, doing Winsorization, excluding ADRs, and excluding zero values.