Skip to content
All library documents

How Alphalens Factor Demeaning Creates Long-Short Weights

Article Quant Q&A · Author: JOHN

Summary

The answer explains why Alphalens factor analysis can represent a long-short portfolio after factor values are demeaned. Each value is centered by subtracting the cross-sectional mean, then scaled by the sum of the absolute demeaned values. These transformed factor values become portfolio weights: values above the mean produce positive weights, while values below it produce negative weights. The resulting positions correspond to long and short exposure, respectively.

The explanation locates the long-short construction in the centered, signed weights used to form the factor-weighted portfolio. It does not describe a trading signal's profitability or establish that every Alphalens analysis uses this precise setup; it addresses the factor-weighting procedure described in the question. The scaling step normalizes the aggregate absolute weights, while demeaning determines their signs relative to the cross-sectional mean. The document offers a conceptual explanation rather than empirical evidence about portfolio performance or implementation details beyond that transformation.

Key ideas

  • Alphalens centers factor values by subtracting their cross-sectional mean.
  • The demeaned values are scaled by the sum of their absolute values before they are used as weights.
  • Positive transformed values create long weights, while negative values create short weights.
  • The signed, factor-weighted portfolio construction is what makes the setup long-short.
  • The explanation addresses portfolio construction, not the performance of the resulting strategy.

Tags

Full text
# question about Quantopian alphalens


# question about Quantopian alphalens












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?

## Answer by Max Margenot (score 3)

https://quant.stackexchange.com/a/34290

With the factor values in Alphalens, what is specifically done is demeaning followed by division by the sum of the absolute values of all the demeaned factors. With some offhand notation, this is more like:

$$ \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.

Our new factor values will now all be centered around the mean, split with about half of them positive and half of them negative. By using the new factor values to determine the weights of their corresponding securities in our portfolios, we create a de facto long-short portfolio. New factor values that are positive will correspond to positive weights (and hence are longed) and new factor values that are negative will correspond to negative weights (and hence are shorted). If you want to read a little more about how the specific function that carries out this "standardization" is defined, check out the docs here.

This demeaning and factor-weighting is primarily what makes it long-short.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.