Hi, I am quite new to python and dont fully understand limits and capabilities of the language.
I am trying to run a backtest where I look at my fundamental factor which is a ratio computed across Q1500 stocks within their industries and want to go short 10th deciles and long 1st deciles stocks.
It wouldnt be that complicated if I looked at the fundamentals across whole Q1500, but i want to account for industries because top/bottom decile might be skewed towards some particular industry.
I came up with this code but obviously it doesnt work, its breaking after return pipe.
Any idea/solution would be much appreciated, thanks.
pipe = Pipeline(
columns={
'n1': NI1,
'n2': NI2,
'ts': TD,
'recent_indebt' : recent_indebt,
'sectors' : sectors
},
screen = (sector)
#mask = universe
)
return pipe
dec = pipe.groupby(['sectors'])['ts'].transform(
lambda x: pd.qcut(x, 10, labels=range(1,11)))
pipe.add(dec, 'dec')
low_returns = pipe['dec'].eq('10')
pipe.add(low_returns, 'low_returns')
pipe['high_returns'] = pipe['dec'].eq('1')
pipe.add(high_returns, 'high_returns')