Back to Community
Making a revenue-growth weighting of stocks
longs = base_universe & rankedVal.percentile_between(60, 100) & rankedQual.percentile_between(85, 100) & RankedFinStrength.percentile_between(70,100) & Volatility().rank().percentile_between(0,70) & rankedDebtHistory.rank().percentile_between(50, 100)  
    shorts = base_universe & rankedVal.percentile_between(0, 35) & rankedQual.percentile_between(0,15)  & RankedFinStrength.percentile_between(0, 40) & rankedDebtHistory.rank().percentile_between(0, 60)

    pipe = Pipeline(  
        screen = (longs | shorts),  
        columns = {  
            'longs': longs,  
            'shorts': shorts,  
            'ebitda_margin': Latest(inputs=[mstar.operation_ratios.ebitda_margin], mask=(longs|shorts)),  
            'revenue_growth': Latest(inputs=[mstar.operation_ratios.revenue_growth], mask=(longs|shorts)),  
        }  
    )  
    return pipe  

I just added the ebitda margin and revenue growth columns, not sure if I did them correctly... Then I want to be able to make a weighting based on revenue growth and ebitda margin for the long stocks. So I want a sum of the ebitda_margin but only for longs stocks, and then weight it based on what percentage each long stock is of ebitda margin and have ebitda margin and revenue growth each contribute 50% towards the weightings.

So let's say the sum of all the ebitda margins is 250% and revenue growth is 100%. A stock has an ebitda margin of 25% as well as a revenue growth of 20%. So that's 10% of total ebitda margin and 20% of total revenue growths, so the weighting this stock would get would be 0.5(percentage of total ebitda) + 0.5(percentage of total revenue growth).

How can I do this? Any similar examples?