Back to Community
How to Combine Factors in Alphalens?

Hi Quantopian Community,

I am wondering how to combine factors to put through alphalens i.e. Value + Momentum example below.

I have attached a code snippet for the momentum & value factors & my weak attempt to combine them.

class Momentum(CustomFactor):  
    inputs = [USEquityPricing.close]  
    window_length = 252  
    def compute(self, today, assets, out, close):  
        out[:] = close[-20] / close[0]  
class Value(CustomFactor):

    inputs = [USEquityPricing.close,  
    window_length = 1

    def compute(self, today, assets, out, close, fcf):  
        out[:] = close[-1] / fcf[-1]        

class Combined(CustomFactor):  
    inputs = [Momentum,  
    window_length = 1  
    def compute(self, today, assets, out, Momentum, fcf):  
        value_table = pd.DataFrame(index=assets)  
        value_table["momentum"] = Momentum[-1]  
        value_table["fcf"] = fcf[-1]  
        value_rank = value_table.rank("fcf").mean(axis=1)  
        mom_rank = value_table.rank("momentum").mean(axis=1)  
        out[:] = value_rank + mom_rank  
3 responses

The easiest way would be to rank each factor and then sum them. This way each factor weights the same.

mask = my_universe_filter #something like Q500US() or Q1500US()

momentum = Momentum(mask=mask)  
value = Value(mask=mask)  
combined = momentum.rank(mask=mask) + value.rank(mask=mask)  

This is a great question Lex. Alpha factor combination is an active area of research in the quant finance space, and there is certainly no one-size-fits-all approach.

I agree with Luca that the easiest way to get started is to normalize both (all) of your factors to match their variances in some way and then try a linear combination (e.g. rank, sum, re-rank) which assumes a 50% weight to each factor. From there you can think about reasons to weight factors un-equally, or perhaps even dynamically based on their trailing stand alone performance.

More recently there has been a lot of cool work looking at non-linear alpha combination approaches (see this Nomura research piece for some examples). One argument for a non-linear approach can be different timescales of your alpha factors. Value and momentum are the perfect example for this, where you may be considering a short term momentum factor, while your value factor is likely driven by slower moving inputs like quarterly financial statement data.

If you haven't come across Jonathan Larkin's blog post on the quant equity workflow I'd definitely recommend it as he provides a great overview of how the alpha combination step figures in to the full strategy design cycle.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Luca & Jess. My personal view is that it is better to focus on trying to diversify across markets to capture factor inefficiencies elsewhere rather than 'overfit' factor weights in a single market. I will potentially look into using very simple macroeconomic regime modelling to decide selection & combination. Many AI / machine learning funds have blown up over the past 30 years (Ray Dalio says this himself). The Nomura article is interesting though, particularly using a decision tree framework to arrive at factor allocations.

Does alphalens allow using macroeconomic variables as inputs? I.e. does New Manufacturing Orders predict industrials / materials sector returns 1-3 months out... this type of analysis.