Also recommend a progressive mask something like this , starting with m = Q1500US()
. But add on each step the screening of nans. For example, after the rsi =
line, add a line: m &= rsi.notnull()
which adds to the mask. And then always utilizing the latest mask with each step whenever calling a factor. Usually ending with screen = m
. Not in this case once I decided to try offering an actual example. I've never dealt with anything quite like this before. It might need more parens.
A benefit: You can add or comment lines out more easily. But it starts with the main thing, avoiding nans in math operations.
def make_pipeline():
m = Q1500US() # original mask
price_close = USEquityPricing.close.latest
m &= price_close.notnull() # add to progressive mask
# Utilize the progressive mask ...
sma10 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10 , mask=m)
sma50 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=50 , mask=m)
sma200 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=200, mask=m)
rsi = RSI(inputs=[USEquityPricing.close], window_length=14, mask=m) # Using mask
m &= rsi.notnull() # add to progressive mask
fq0_eps, fq1_eps, fq2_eps, fq3_eps, fq4_eps, fq5_eps, fq6_eps, fq7_eps = ZacksEarningsSurp(mask=m) # Using mask
m &= fq0_eps.notnull()
m &= fq1_eps.notnull()
# Long mask
longs = m & (fq0_eps > 0.0)
longs &= m & (fq1_eps > 0.0)
longs &= m & (price_close - sma10) > 0.0
longs &= m & (sma10 - sma50) > 0.0
longs &= m & (sma50 - sma200) > 0.0
longs &= m & (rsi < 70.0)
shrts = m & (fq0_eps < 0.0)
shrts &= m & (fq1_eps < 0.0)
shrts &= m & (price_close - sma10) < 0.0
shrts &= m & (sma10 - sma50) < 0.0
shrts &= m & (sma50 - sma200) < 0.0
shrts &= m & (rsi > 20.0)
return Pipeline(
columns = {
'longs' : longs,
'shrts' : shorts,
'price' : price_close,
'rsi' : rsi,
'sma10' : sma10,
'sma50' : sma50,
'sma200' : sma200,
'fq0_eps': fq0_eps,
'fq1_eps': fq1_eps,
},
screen = (longs | shrts),
)
# Many columns included just for preview. Once set, comment out any not used, for speed.
From there I'd use this to vet pipeline values, to see what's there, it is easy to add.
Since it also shows the number of rows (stocks) plus min/max values, makes for quickly finding the changes if certain lines are altered, and getting a feel for what you're working with. Pipe wrangling. :p
As far as the original error, try removing the comma on this line:
time_rules.market_open(hours=1)