There must be an efficient way to do this, but I can't figure it out.
Suppose for the sake of example I have a Pipeline that uses a custom factor with Fundamentals to restrict the universe of securities to only those whose trailing 12-month EBIT is greater than the previous year's EBIT, and that I generate orders for some subset of those securities.
Then on subsequent trading days - say four quarters later - I might want to evaluate the securities in my portfolio based on some other fundamental data, e.g., sell the ones that now have current assets less than the previous year's current assets. How can I get the fundamental data for the securities in my portfolio? The pipeline will only fetch data for ones whose TTM EBIT is less than the previous year's, but some of the securities in my portfolio may not satisfy that condition.
The only way I can think of doing this is to have the pipeline return fundamental data for the entire universe of e.g., QTradableStocksUS and then filter them in before_trading_start, but that is no doubt going to be tremendously inefficient.
I had thought of passing in the context to the make_pipeline function, but as a different thread pointed out, everything in that function is eagerly evaluated when the Pipeline object is created, not when pipeline_output gets called for some particular date -- and in fact the pipeline might asynchronously fetch multiple days of data at once, so it wouldn't even be in a position to know what securities are in the portfolio for days that haven't been traded yet.
Is there any other way of doing a lookup on fundamental data besides using the Pipeline API?