Calculate the first passage time of a sequence consisting of prices
else-after-continue
This:
  if -threshold &lt; cum_return &lt; threshold:
     # this possibility will probably occur the most frequently
     continue
  elif cum_return &gt; threshold:
     times.append(cum_return)
     up_threshold += threshold
     down_threshold += threshold
  else:
     times.append(cum_return)
     up_threshold -= threshold
     down_threshold -= threshold

can be
  if -threshold &lt; cum_return &lt; threshold:
     # this possibility will probably occur the most frequently
     continue

  times.append(cum_return)

  if cum_return &gt; threshold:
     up_threshold += threshold
     down_threshold += threshold
  else:
     up_threshold -= threshold
     down_threshold -= threshold