def cross(series, cross=<NUM_LIT:0>, direction='<STR_LIT>'):
<EOL>above=series.values > cross<EOL>below=scipy.logical_not(above)<EOL>left_shifted_above = above[<NUM_LIT:1>:]<EOL>left_shifted_below = below[<NUM_LIT:1>:]<EOL>x_crossings = []<EOL>if direction == '<STR_LIT>':<EOL><INDENT>idxs = (left_shifted_above & below[<NUM_LIT:0>:-<NUM_LIT:1>]).nonzero()[<NUM_LIT:0>]<EOL><DEDENT>elif direction == '<STR_LIT>':<EOL><INDENT>idxs = (left_shifted_below & above[<NUM_LIT:0>:-<NUM_LIT:1>]).nonzero()[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>rising = left_shifted_above & below[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL>falling = left_shifted_below & above[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL>idxs = (rising | falling).nonzero()[<NUM_LIT:0>]<EOL><DEDENT>x1 = series.index.values[idxs]<EOL>x2 = series.index.values[idxs+<NUM_LIT:1>]<EOL>y1 = series.values[idxs]<EOL>y2 = series.values[idxs+<NUM_LIT:1>]<EOL>x_crossings = (cross-y1)*(x2-x1)/(y2-y1) + x1<EOL>return x_crossings<EOL>
From http://stackoverflow.com/questions/10475488/calculating-crossing-intercept-points-of-a-series-or-dataframe

Given a Series returns all the index values where the data values equal 
the 'cross' value. 

Direction can be 'rising' (for rising edge), 'falling' (for only falling 
edge), or 'cross' for both edges