Quantopian has this package alphalens to do series of analysis on factors.

I decided to dig in the code and make sense of the analysis.

The question I have is: There are a lot of demean in the factors and factors returns, the argument is when you demean, the analysis is for long short portfolio and when you do not demean, you have a long only portfolio.

Can anyone explain why demean of the return gives analysis on long short portfolio?

$$\bar{F}_i =\frac{F_i - E[F]}{\sum_{n=1}^N |F_n|}$$
Where $F_i$ is the original factor value, $F$ is the set of all original factor values, and $\bar{F}_i$ is our new demeaned and compressed factor value. This new set of $\{\bar{F}_i\}_{i=1}^N$ is then used to construct a factor-weighted portfolio.