How to handle NA data for lagged factors

I'm analyzing a factor using a Loop in P123, and I noticed that when a company stops reporting a particular metric, P123 seems to forward-fill the last available value.

Take OWLT:USA as an example (pictured).

According to the data, the last available value for ROE%Q was reported in November 2022. Since then, the company has released earnings reports, it's just that P123 no longer reports this specific metric — which is fine.

However, when I calculate something like the median ROE over the last 12 quarters, the results suggest that P123 is filling in the missing quarters with the last reported value of -591. So the median calculation ends up being something like:
median(-274, ..., -591, -591, -591, ..., -591) — with every post-Nov. 2022 quarter using the repeated -591 value. This dramatically biases the metric, and could damper performance.

Instead of forward-filling, I'd prefer to use something like the industry average for those missing quarters. Or even 0 would be fine.

Is there a way in P123 to replace missing data with the industry average, or at least prevent it from being forward-filled in the Loop?

LoopMedian has options for NA handling. See www.portfolio123.com/doc/doc_detail.jsp?factor=LoopMedian. What you're seeing is not that the missing quarters are being filled with the last available datapoint, but that NAs are being skipped altogether, so that the median reflects fewer and fewer data points.

2 Likes

Ahh, I see. Thank you Yuval, that's perfect.