# How to screen within "top" Industries

Shows some techniques for screening from best Industries

It is often desirable to screen from stocks from the best (or worst) Industry classification which can be either Sector, SubSector, Industry or SubIndustry. However, since P123 syntax is mostly geared for screening and ranking stocks, some "tricks" are required to rank at the Industry classification levels, meaning ranking industries relative to each other.

There are three techniques you can use depending on your criteria for ranking. If your criteria is technical (like 4 week return) you can use the first method for pre-built Industry series. If you use a pre-built Ind Factor use the second technique. For all other use the third method.

#### I'll illustrate the techniques by screening for all the stocks that are in the __top 50% performing industries__ of the __past 4 weeks__.

For this example use the Screener with your choice of starting universe.

**HINT**: to figure out how many Industries there are run the rule below. It screens for the largest stock by MktCap from each industry, which returns 90 stocks. This tells you that there are 90 Industries in total.

`FOrder("MktCap",#Industry,#desc) = 1 // returns largest stock in each industry (90 of them)`

## 1: Using the cap-weighted Industry time series

For Industry classifications we compute a daily cap-weighted time series indexes. We will use these indexes to get the 4 week return of each industry, then use it to rank the industries against each other. To screen for all the stocks in the top 50% of the industries with the best 4 week return you would write the following:

`FOrder("Close(0,#Industry) / Close(20,#Industry)" , #All, #Desc, TRUE) <= 45`

Since there are 90 Industries (this can change historically and it also depends on the data vendor) by doing less than or equal to 45 we get all the stocks that are in the top 50% Industries. The Cross Sectional function FOrder is used to select the top 45 industries because it has a very important 4th parameter called 'distinct'. When 'distinct' is set to TRUE it bases the order on distinct values. See the reference for FOrder for more details.

## 2: Using the pre-built Industry ("Ind") factors

There are 4 pre-built Ind factors for performance (4w, 13w, 26w and 52w) that can be used, so it's more limiting. You can find them in the reference under INDUSTRY AND SECTOR→INDUSTRY FACTOR→PRICE & VOLUME. Ind factors are computed using the Aggregate function which does a simple average of the statistic after trimming 16.5% of the outliers from each side. Therefore this method is not the same as the cap-weighted time series above.

Here's the rule using the 4 week return Ind factor:

`Forder("Pr4W%ChgInd" , #all, #desc, TRUE) <= 45`

NOTE: We currently only have Industry factors. So you cannot do this for Sector, SubSector and SubIndustry at the moment.

## 3: Using any stock formula

To rank industries based on any stock formula you first need to create your own Ind factor. You can do this by using SetVar like this:

`SetVar(@4WkInd, Aggregate("Close(0)/Close(20)", #Industry))`

This calculates the average return withing each industry. There are many more settings in the Aggregate function which you will find in the reference. Next we will use this variable we just created to screen for all the stocks where the new variable is in the top 50% of the industries like this:

`FOrder("@4WkInd" , #Previous, #desc, TRUE) <= 45`

## Final Considerations

You will not get exactly 1/2 the stocks of the universe because industries contain different number of stocks.

In addition, the two methods use different metric (one is cap weighted one is a straight average) so it will return some different industries, which in turn will return different number of stocks.

The techniques illustrated can be changed to screen in the top 10% Industries, or bottom 20%, etc. For example for top 10% change 45 to 9.

Did this answer your question?