Replicate backtest in screen

This seems like simple question, but having trouble working it out in a screen. I’m basically trying to replicate a backtest, such that I have the performance value in my screen for use in other formulas.

For example, find the median/avg return of group of stocks passing certain rules in the past.

i.e. For stocks in highest decile ranked by P/E, 1 month ago, what is the median/average return today (1 month return)?

Can you use an offset in “frank” or “rating”? Tried “fhist” as well but it didn’t like it in combination with “rating”.

Looking to have that value in my screen for other rules, i.e. has the factor/rule had positive monthly performance vs negative, etc.

Thanks!
Ryan

Or put another way - you run a decile test for a ranking system under “performance”. Trying to create a formula in a screen or ranking system that replicates calculating the return of the top (or any given) decile for any given period (1 month in this case).

Thoughts?

ShowVar(@1MoPERank,FRank(FHist("PEExclXorTTM",4),#all,#asc))
ShowVar(@Return,FMedian(“Eval(@1MoPERank > 90,Pr4W%Chg, NA)”))

That is fantastic Yuval, thanks! The (`) is new to me, is this required for “double nesting”?

Thanks again,
Ryan

Yes, for nesting you alternate between " and `, in any order.

I realized later that there is some survivorship bias in my formula. A stock with a very low PE that went out of business or was acquired in the last month will not be counted when calculating the return.

There’s no way to avoid this, I’m afraid. A current screen cannot access data for a dead ticker.

Good to know on the " and `. I did notice some variation between results of the formula and the actual screen backtests. Will need to dig in and see if/how this impacts overall OOS. Still, a very good start for what I’m after.