Hi everyone,
I am trying to make an strategy that does the following:
-When the Chicago Fed Nat Index >-0.7 (bull market): buy the 20 best value stocks filtered by pcf, roe, and market cap
-When the CFNAI<-0.7 (bear market): buy the iShares 1-3Y Treasury Bond.
I don't know how to filter the best 20 value stocks with pipeline. I have read the documentation and I understand how to do it with one filter (I've attached my try which goes a bit slow too), but not with more than one. Any help?
attach_pipeline(make_pipeline(), 'fundamentals_pipeline')
def make_pipeline():
pipe = Pipeline(
columns={
'close': USEquityPricing.close.latest
},
screen = (morningstar.operation_ratios.roe > 0.10,
morningstar.valuation_ratios.pcf_ratio <15,
morningstar.valuation_ratios.pcf_ratio >2,
morningstar.valuation.market_cap >= 30e6)
)
return pipe
def before_trading_start(context, data):
context.pipe_output = pipeline_output('fundamentals_pipeline')
context.longs = context.pipe_output[context.pipe_output['close']].index