Please bear with me...
This illustration can be replicated on "Build Algorithm" or debugging mode..
Please mark a debug tag (blue tag) on the line 104.
First I am going to disable all of the code below with "#".
# Rank factor 1 and add the rank to our pipeline
factor1_rank = factor1.rank(mask=top_2000)
pipe.add(factor1_rank, 'f1_rank')
# Rank factor 2 and add the rank to our pipeline
factor2_rank = factor2.rank(mask=top_2000)
pipe.add(factor2_rank, 'f2_rank')
# Take the average of the two factor rankings, add this to the pipeline
combo_raw = (factor1_rank+factor2_rank)/2
pipe.add(combo_raw, 'combo_raw')
# Rank the combo_raw and add that to the pipeline
pipe.add(combo_raw.rank(mask=top_2000), 'combo_rank')
because, I suspect the "rank" not working properly.
click "Build Algorithm"
When I try to call "context.output" in the debug screen....
I get below securities
Equity(24 [AAPL])
Equity(1091 [BRK_A])
Equity(5061 [MSFT])
Equity(26578 [GOOG_L])
Equity(46631 [GOOG])
And I get "factor_1" (pe ratio) and "factor_2" (debt/equity ratio) as expected. Very happy!
But now I will activate the codes in the above box. run again. This is when things gets unpredictable. Not only do I lose the securities.
I get whole new sets of securities.....
Equity(1091 [BRK_A])
Equity(16841 [AMZN])
Equity(25729 [CTRP])
Equity(26401 [CRM])
Equity(44747 [DATA])
"factor_1" and "factor_2" columns are filled with wierd numbers and I have no clue what "f1_rank" is for anymore.
Please help me understand what "rank" is doing. What I was anticipating was with the same 5 stocks and original "factor_1" (pe ratio) and "factor_2" (debt/equity ratio) respectively, plus "f1_rank" to display the rankings of "factor_1". So why is it not happening? What should I do to get what I want to do. Thank you