Correct if I understand you. You can do things like this in the debugger to know for sure on things like that:
> np.nan > 2
False
> np.nan < 2
False
> np.nan == 2
False
> np.nan == np.nan
False
> np.nan != np.nan
True
So when nan is present, everything's pretty much always false, you're right, except it isn't equal to itself, and that can be useful. If I wanted to avoid np, could do if some_var != some_var
and know it's a nan if True.
I'll share with you something I did with your code to toss some ideas out there for use with the debugger. Since DXYN is a handy available example of a nan here, this can force it to be in the mix (or not) even when pipeline screens it out, to be able to see what changes in the code would do, going step by step in the debugger:
def my_rebalance(context,data):
if sid(2384) not in context.security_list:
print 'DXYN absent'
inject_dxyn = 1 # on or off
if inject_dxyn:
if sid(2384) not in context.security_list: # 2384 is DXYN
context.security_list.append(sid(2384))
op = data.history(context.security_list, 'open', 2, '1d') #.ffill().bfill()
pc = data.history(context.security_list, 'price', 2, '1d') #.ffill().bfill()
if inject_dxyn:
context.security_list = [sid(2384)]
for s in context.security_list:
cp = data.current(s,'price') ; cp=cp
if op[s][-1] > pc[s][-2] * GAP_UP:
context.security_listF[s] = s
context.rsi[s] = 100
That cp=cp is just to quiet the variable unused warning.
Then in the watch window, some ideas for things to place there:
s (I almost always have this first)
str(op[s].values)
str(pc[s].values)
pc[s][-2] * GAP_UP
By the way, did you know you can even have a function in the watch window folks?
As an example, and you just have to fix this up, replacing ma and period and then in watch, it should show the return value:
getRSI(ma, s, period)
You can also run functions from the debugger console feeding them different inputs. Just thought it might be worth mentioning.