I'm new to Python and Quantopian, and probably this algo has been vetted by way more experienced users, but i think i am correct in reading this (please correct me if im wrong though).
close[-1] is the most recent price in the lookback period denoted by window_length parameter.
close is the oldest price in the same lookback period.
Referring to this other algo: https://www.quantopian.com/posts/long-short-pipeline-multi-factor
Their momentum factor is computed as " close[-20] / close " for a 252 window_length, which means a one-year return, but excluding the most recent 1 month (20 trading days); therefore, technically a 232 days period. Thereafter, they long the tail via "context.longs = ranks.tail(200)" after ranking the momentum factor (along with other factors) in default ascending order . This supports my understanding of the direction of 'close[-1]'.
So back to the algo in this thread, if i got the direction of close[-1] and close correctly, the next question will be the direction of the built-in function .top() and .bottom(). According to the documentation, the definition for .top() is "Construct a Filter matching the top N asset values of self each day." I am understanding it as, finding the top N asset with the HIGHEST factor value, rather than functioning like .head().
Referring to Q's lecture series:
".top()" is used to filter out list of asset to LONG via "longs = combined_factor.top(TOTAL_POSITIONS//2, mask=universe)", which would support my interpretation of the direction of the .top(), that is, to obtain the N assets with the highest factor value.
If my understanding of the direction of "close[-1]" and ".top()" function is correct, then there is a mistake with the long short rules in the algo from this thread, it should be swapped.
Again, please correct me if i am wrong about this fundamentally important concept. I have no confidence in myself, given that people with way more experience than me have vetted this code.