UnivStdDev and UnivStdDevP added to Aggregate Series factors

We have added UnivStdDev and UnivStdDevP to our Aggregate Series factors (UnivAvg, UnivCapAvg, UnivCnt, UnivMax, UnivMedian, UnivMin, and UnivSum). These are calculated just like the StdDev, StdDevP, LoopStdDev, and LoopStdDevP factors, skipping N/As and using the n-1 method.

Yuval, Awesome. Thank you -Jim. P123 is the best.

I’m a bit stuck on using UnivStdDev.

I want to plot the number of stocks with Pr2SalesTTM greater than one StdDev over the universe mean Pr2Sales and that are above their 20-day SMA.

Any suggestions?

UnivStdDev won’t be any help for this. Here’s the solution: create a universe with these four rules:

SetVar(@meanp2s,aggregate(“Pr2SalesTTM”,#all,#avg,2.5))
SetVar(@stdevp2s,aggregate(“(Pr2SalesTTM-@meanp2s)^2”,#all,#avg,2.5)^0.5)
Pr2SalesTTM > @stdevp2s + @meanp2s
Price > SMA(20)

Then use that universe in your aggregate series with the command UnivCnt(“1”).

Some notes:

I used 2.5 as my trim. I tried it with 0 and got very high numbers, even for the S&P 500. The problem with Pr2SalesTTM is that some stocks have insane numbers (RCL is 90 right now and there are 53 companies in the Russell 3000 with Pr2Sales > 100, most of them biotechs with negligible revenue). But if you want to use 0 instead for a very straight mean and standard deviation, please be my guest.

The second line relies on the standard definition of standard deviation: the square root of the average of the squared distances between the mean and the population.

Let me know if anything here is unclear or if I got anything wrong.

Hi Yuval,

Thanks for the solution. I think my mental model for Aggregate Series needs refinement.

BTW, I think ZScore(“Pr2salesTTM”,#All,2.5,0)>1 would work just as well as a Universe filter in this case.

Walter