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.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58fcdb78612e1e44cc7c6c7e
There was a runtime error.
3 responses


(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()):