Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
store list on day 1 to use on day 3

What I am trying to do is to rank stocks on day 1 of the month and sell the stocks that are out of the portfolio - on day 3 buy the stocks that need buying. What I don't want is to rerank stocks on day 3, I want to use the list created on day 1.

Does anyone know how to do this? I tried several different methods but was not able to implement.

3 responses

Georges,

(Without reviewing your code)... Seems like a quick fix would be to run pipeline once per month in your 'rebalance' function, instead of every day in before_trading_start.

Exactly! Thanks for the help to such a simple issue. I was over complicating the solution!

Somehow I was under the impression that pipeline always had to be called from before_trading_start. Instead, apparently because it is always there if it is ever there, we can access its content from anywhere. Hmm. So, revising my original comment, removed. By the way here's the fix for the two warning messages ...

    context.long_list = context.output.sort(['combo_raw'], ascending=False).iloc[:context.long_num]

FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)

    context.long_list = context.output.sort_values(by='combo_raw', ascending=False).iloc[:context.long_num]


            if stock not in security_lists.leveraged_etf_list:

Evaluating inclusion in security_lists is deprecated. Use `sid in <security_list>.current_securities(dt)` instead.

            if stock not in security_lists.leveraged_etf_list.current_securities(get_datetime()):