Generated by Cython 0.29.24

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: _minute_bar_internal.c

+001: from numpy cimport ndarray, long_t
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+002: from numpy import searchsorted
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_searchsorted);
  __Pyx_GIVEREF(__pyx_n_s_searchsorted);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_searchsorted);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_searchsorted, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 003: from cpython cimport bool
 004: cimport cython
 005: 
+006: cdef inline int int_min(int a, int b): return a if a <= b else b
static CYTHON_INLINE int __pyx_f_7zipline_4data_20_minute_bar_internal_int_min(int __pyx_v_a, int __pyx_v_b) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("int_min", 0);
  __Pyx_TraceCall("int_min", __pyx_f[0], 6, 0, __PYX_ERR(0, 6, __pyx_L1_error));
  if (((__pyx_v_a <= __pyx_v_b) != 0)) {
    __pyx_t_1 = __pyx_v_a;
  } else {
    __pyx_t_1 = __pyx_v_b;
  }
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("zipline.data._minute_bar_internal.int_min", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 007: 
 008: @cython.cdivision(True)
+009: def minute_value(ndarray[long_t, ndim=1] market_opens,
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_1minute_value(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7zipline_4data_20_minute_bar_internal_minute_value[] = "Finds the value of the minute represented by `pos` in the given array of\n    market opens.\n\n    Parameters\n    ----------\n    market_opens: numpy array of ints\n        Market opens, in minute epoch values.\n\n    pos: int\n        The index of the desired minute.\n\n    minutes_per_day: int\n        The number of minutes per day (e.g. 390 for NYSE).\n\n    Returns\n    -------\n    int: The minute epoch value of the desired minute.\n    ";
static PyMethodDef __pyx_mdef_7zipline_4data_20_minute_bar_internal_1minute_value = {"minute_value", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_1minute_value, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7zipline_4data_20_minute_bar_internal_minute_value};
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_1minute_value(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_market_opens = 0;
  Py_ssize_t __pyx_v_pos;
  short __pyx_v_minutes_per_day;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minute_value (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_market_opens,&__pyx_n_s_pos,&__pyx_n_s_minutes_per_day,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_market_opens)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("minute_value", 1, 3, 3, 1); __PYX_ERR(0, 9, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minutes_per_day)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("minute_value", 1, 3, 3, 2); __PYX_ERR(0, 9, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "minute_value") < 0)) __PYX_ERR(0, 9, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_market_opens = ((PyArrayObject *)values[0]);
    __pyx_v_pos = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_pos == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L3_error)
    __pyx_v_minutes_per_day = __Pyx_PyInt_As_short(values[2]); if (unlikely((__pyx_v_minutes_per_day == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("minute_value", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 9, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.minute_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_market_opens), __pyx_ptype_5numpy_ndarray, 1, "market_opens", 0))) __PYX_ERR(0, 9, __pyx_L1_error)
  __pyx_r = __pyx_pf_7zipline_4data_20_minute_bar_internal_minute_value(__pyx_self, __pyx_v_market_opens, __pyx_v_pos, __pyx_v_minutes_per_day);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7zipline_4data_20_minute_bar_internal_minute_value(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_market_opens, Py_ssize_t __pyx_v_pos, short __pyx_v_minutes_per_day) {
  short __pyx_v_q;
  short __pyx_v_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_market_opens;
  __Pyx_Buffer __pyx_pybuffer_market_opens;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj_)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minute_value", 0);
  __Pyx_TraceCall("minute_value", __pyx_f[0], 9, 0, __PYX_ERR(0, 9, __pyx_L1_error));
  __pyx_pybuffer_market_opens.pybuffer.buf = NULL;
  __pyx_pybuffer_market_opens.refcount = 0;
  __pyx_pybuffernd_market_opens.data = NULL;
  __pyx_pybuffernd_market_opens.rcbuffer = &__pyx_pybuffer_market_opens;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer, (PyObject*)__pyx_v_market_opens, &__Pyx_TypeInfo_nn___pyx_t_5numpy_long_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 9, __pyx_L1_error)
  }
  __pyx_pybuffernd_market_opens.diminfo[0].strides = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_market_opens.diminfo[0].shape = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.shape[0];
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.minute_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__7 = PyTuple_Pack(5, __pyx_n_s_market_opens, __pyx_n_s_pos, __pyx_n_s_minutes_per_day, __pyx_n_s_q, __pyx_n_s_r); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);
/* … */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_1minute_value, NULL, __pyx_n_s_zipline_data__minute_bar_interna); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_minute_value, __pyx_t_2) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_data__minute_bar_int, __pyx_n_s_minute_value, 9, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 9, __pyx_L1_error)
 010:                  Py_ssize_t pos,
 011:                  short minutes_per_day):
 012:     """Finds the value of the minute represented by `pos` in the given array of
 013:     market opens.
 014: 
 015:     Parameters
 016:     ----------
 017:     market_opens: numpy array of ints
 018:         Market opens, in minute epoch values.
 019: 
 020:     pos: int
 021:         The index of the desired minute.
 022: 
 023:     minutes_per_day: int
 024:         The number of minutes per day (e.g. 390 for NYSE).
 025: 
 026:     Returns
 027:     -------
 028:     int: The minute epoch value of the desired minute.
 029:     """
 030:     cdef short q, r
 031: 
+032:     q = cython.cdiv(pos, minutes_per_day)
  __pyx_v_q = (__pyx_v_pos / __pyx_v_minutes_per_day);
+033:     r = cython.cmod(pos, minutes_per_day)
  __pyx_v_r = (__pyx_v_pos % __pyx_v_minutes_per_day);
 034: 
+035:     return market_opens[q] + r
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_v_q;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_pybuffernd_market_opens.diminfo[0].shape;
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_pybuffernd_market_opens.diminfo[0].shape)) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 35, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_PyInt_From_npy_longlong(((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_long_t *, __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_market_opens.diminfo[0].strides)) + __pyx_v_r)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;
 036: 
+037: def find_position_of_minute(ndarray[long_t, ndim=1] market_opens,
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_3find_position_of_minute(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7zipline_4data_20_minute_bar_internal_2find_position_of_minute[] = "Finds the position of a given minute in the given array of market opens.\n    If not a market minute, adjusts to the last market minute.\n\n    Parameters\n    ----------\n    market_opens: numpy array of ints\n        Market opens, in minute epoch values.\n\n    market_closes: numpy array of ints\n        Market closes, in minute epoch values.\n\n    minute_val: int\n        The desired minute, as a minute epoch.\n\n    minutes_per_day: int\n        The number of minutes per day (e.g. 390 for NYSE).\n\n    forward_fill: bool\n        Whether to use the previous market minute if the given minute does\n        not fall within an open/close pair.\n\n    Returns\n    -------\n    int: The position of the given minute in the market opens array.\n\n    Raises\n    ------\n    ValueError\n        If the given minute is not between a single open/close pair AND\n        forward_fill is False.  For example, if minute_val is 17:00 Eastern\n        for a given day whose normal hours are 9:30 to 16:00, and we are not\n        forward filling, ValueError is raised.\n    ";
static PyMethodDef __pyx_mdef_7zipline_4data_20_minute_bar_internal_3find_position_of_minute = {"find_position_of_minute", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_3find_position_of_minute, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7zipline_4data_20_minute_bar_internal_2find_position_of_minute};
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_3find_position_of_minute(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_market_opens = 0;
  PyArrayObject *__pyx_v_market_closes = 0;
  __pyx_t_5numpy_long_t __pyx_v_minute_val;
  short __pyx_v_minutes_per_day;
  PyBoolObject *__pyx_v_forward_fill = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_position_of_minute (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_market_opens,&__pyx_n_s_market_closes,&__pyx_n_s_minute_val,&__pyx_n_s_minutes_per_day,&__pyx_n_s_forward_fill,0};
    PyObject* values[5] = {0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_market_opens)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_market_closes)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, 1); __PYX_ERR(0, 37, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minute_val)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, 2); __PYX_ERR(0, 37, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minutes_per_day)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, 3); __PYX_ERR(0, 37, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_forward_fill)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, 4); __PYX_ERR(0, 37, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_position_of_minute") < 0)) __PYX_ERR(0, 37, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
    }
    __pyx_v_market_opens = ((PyArrayObject *)values[0]);
    __pyx_v_market_closes = ((PyArrayObject *)values[1]);
    __pyx_v_minute_val = __Pyx_PyInt_As_npy_longlong(values[2]); if (unlikely((__pyx_v_minute_val == ((npy_longlong)-1)) && PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error)
    __pyx_v_minutes_per_day = __Pyx_PyInt_As_short(values[3]); if (unlikely((__pyx_v_minutes_per_day == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 40, __pyx_L3_error)
    __pyx_v_forward_fill = ((PyBoolObject *)values[4]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 37, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.find_position_of_minute", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_market_opens), __pyx_ptype_5numpy_ndarray, 1, "market_opens", 0))) __PYX_ERR(0, 37, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_market_closes), __pyx_ptype_5numpy_ndarray, 1, "market_closes", 0))) __PYX_ERR(0, 38, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_forward_fill), __pyx_ptype_7cpython_4bool_bool, 1, "forward_fill", 0))) __PYX_ERR(0, 41, __pyx_L1_error)
  __pyx_r = __pyx_pf_7zipline_4data_20_minute_bar_internal_2find_position_of_minute(__pyx_self, __pyx_v_market_opens, __pyx_v_market_closes, __pyx_v_minute_val, __pyx_v_minutes_per_day, __pyx_v_forward_fill);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7zipline_4data_20_minute_bar_internal_2find_position_of_minute(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_market_opens, PyArrayObject *__pyx_v_market_closes, __pyx_t_5numpy_long_t __pyx_v_minute_val, short __pyx_v_minutes_per_day, PyBoolObject *__pyx_v_forward_fill) {
  Py_ssize_t __pyx_v_market_open_loc;
  Py_ssize_t __pyx_v_market_open;
  Py_ssize_t __pyx_v_delta;
  PyObject *__pyx_v_market_close = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_market_closes;
  __Pyx_Buffer __pyx_pybuffer_market_closes;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_market_opens;
  __Pyx_Buffer __pyx_pybuffer_market_opens;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__2)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_position_of_minute", 0);
  __Pyx_TraceCall("find_position_of_minute", __pyx_f[0], 37, 0, __PYX_ERR(0, 37, __pyx_L1_error));
  __pyx_pybuffer_market_opens.pybuffer.buf = NULL;
  __pyx_pybuffer_market_opens.refcount = 0;
  __pyx_pybuffernd_market_opens.data = NULL;
  __pyx_pybuffernd_market_opens.rcbuffer = &__pyx_pybuffer_market_opens;
  __pyx_pybuffer_market_closes.pybuffer.buf = NULL;
  __pyx_pybuffer_market_closes.refcount = 0;
  __pyx_pybuffernd_market_closes.data = NULL;
  __pyx_pybuffernd_market_closes.rcbuffer = &__pyx_pybuffer_market_closes;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer, (PyObject*)__pyx_v_market_opens, &__Pyx_TypeInfo_nn___pyx_t_5numpy_long_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_market_opens.diminfo[0].strides = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_market_opens.diminfo[0].shape = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer, (PyObject*)__pyx_v_market_closes, &__Pyx_TypeInfo_nn___pyx_t_5numpy_long_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_pybuffernd_market_closes.diminfo[0].strides = __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_market_closes.diminfo[0].shape = __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.shape[0];
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.find_position_of_minute", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_market_close);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__8 = PyTuple_Pack(9, __pyx_n_s_market_opens, __pyx_n_s_market_closes, __pyx_n_s_minute_val, __pyx_n_s_minutes_per_day, __pyx_n_s_forward_fill, __pyx_n_s_market_open_loc, __pyx_n_s_market_open, __pyx_n_s_delta, __pyx_n_s_market_close); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);
/* … */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_3find_position_of_minute, NULL, __pyx_n_s_zipline_data__minute_bar_interna); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_find_position_of_minute, __pyx_t_2) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(5, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_data__minute_bar_int, __pyx_n_s_find_position_of_minute, 37, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 37, __pyx_L1_error)
 038:                             ndarray[long_t, ndim=1] market_closes,
 039:                             long_t minute_val,
 040:                             short minutes_per_day,
 041:                             bool forward_fill):
 042:     """Finds the position of a given minute in the given array of market opens.
 043:     If not a market minute, adjusts to the last market minute.
 044: 
 045:     Parameters
 046:     ----------
 047:     market_opens: numpy array of ints
 048:         Market opens, in minute epoch values.
 049: 
 050:     market_closes: numpy array of ints
 051:         Market closes, in minute epoch values.
 052: 
 053:     minute_val: int
 054:         The desired minute, as a minute epoch.
 055: 
 056:     minutes_per_day: int
 057:         The number of minutes per day (e.g. 390 for NYSE).
 058: 
 059:     forward_fill: bool
 060:         Whether to use the previous market minute if the given minute does
 061:         not fall within an open/close pair.
 062: 
 063:     Returns
 064:     -------
 065:     int: The position of the given minute in the market opens array.
 066: 
 067:     Raises
 068:     ------
 069:     ValueError
 070:         If the given minute is not between a single open/close pair AND
 071:         forward_fill is False.  For example, if minute_val is 17:00 Eastern
 072:         for a given day whose normal hours are 9:30 to 16:00, and we are not
 073:         forward filling, ValueError is raised.
 074:     """
 075:     cdef Py_ssize_t market_open_loc, market_open, delta
 076: 
+077:     market_open_loc = searchsorted(market_opens, minute_val, side='right') - 1
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_searchsorted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_npy_longlong(__pyx_v_minute_val); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_market_opens));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_market_opens));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_market_opens));
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_side, __pyx_n_u_right) < 0) __PYX_ERR(0, 77, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_4, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_market_open_loc = __pyx_t_5;
+078:     market_open = market_opens[market_open_loc]
  __pyx_t_6 = __pyx_v_market_open_loc;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_pybuffernd_market_opens.diminfo[0].shape;
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_pybuffernd_market_opens.diminfo[0].shape)) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 78, __pyx_L1_error)
  }
  __pyx_v_market_open = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_long_t *, __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_market_opens.diminfo[0].strides));
+079:     market_close = market_closes[market_open_loc]
  __pyx_t_6 = __pyx_v_market_open_loc;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 79, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyInt_From_npy_longlong((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_long_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_market_closes.diminfo[0].strides))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_market_close = __pyx_t_2;
  __pyx_t_2 = 0;
 080: 
+081:     if not forward_fill and ((minute_val - market_open) >= minutes_per_day):
  __pyx_t_9 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_forward_fill)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 81, __pyx_L1_error)
  __pyx_t_10 = ((!__pyx_t_9) != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_8 = __pyx_t_10;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_10 = (((__pyx_v_minute_val - __pyx_v_market_open) >= __pyx_v_minutes_per_day) != 0);
  __pyx_t_8 = __pyx_t_10;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_8)) {
/* … */
  }
+082:         raise ValueError("Given minute is not between an open and a close")
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 82, __pyx_L1_error)
/* … */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_Given_minute_is_not_between_an_o); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);
 083: 
+084:     delta = int_min(minute_val - market_open, market_close - market_open)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_market_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyNumber_Subtract(__pyx_v_market_close, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_delta = __pyx_f_7zipline_4data_20_minute_bar_internal_int_min((__pyx_v_minute_val - __pyx_v_market_open), __pyx_t_7);
 085: 
+086:     return (market_open_loc * minutes_per_day) + delta
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyInt_FromSsize_t(((__pyx_v_market_open_loc * __pyx_v_minutes_per_day) + __pyx_v_delta)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 087: 
+088: def find_last_traded_position_internal(
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7zipline_4data_20_minute_bar_internal_4find_last_traded_position_internal[] = "Finds the position of the last traded minute for the given volumes array.\n\n    Parameters\n    ----------\n    market_opens: numpy array of ints\n        Market opens, in minute epoch values.\n\n    market_closes: numpy array of ints\n        Market closes, in minute epoch values.\n\n    end_minute: int\n        The minute from which to start looking backwards, as a minute epoch.\n\n    start_minute: int\n        The asset's start date, as a minute epoch.  Acts as the bottom limit of\n        how far we can look backwards.\n\n    volumes: bcolz carray\n        The volume history for the given asset.\n\n    minutes_per_day: int\n        The number of minutes per day (e.g. 390 for NYSE).\n\n    Returns\n    -------\n    int: The position of the last traded minute, starting from `minute_val`\n    ";
static PyMethodDef __pyx_mdef_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal = {"find_last_traded_position_internal", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7zipline_4data_20_minute_bar_internal_4find_last_traded_position_internal};
static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_market_opens = 0;
  PyArrayObject *__pyx_v_market_closes = 0;
  __pyx_t_5numpy_long_t __pyx_v_end_minute;
  __pyx_t_5numpy_long_t __pyx_v_start_minute;
  PyObject *__pyx_v_volumes = 0;
  short __pyx_v_minutes_per_day;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_last_traded_position_internal (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_market_opens,&__pyx_n_s_market_closes,&__pyx_n_s_end_minute,&__pyx_n_s_start_minute,&__pyx_n_s_volumes,&__pyx_n_s_minutes_per_day,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_market_opens)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_market_closes)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, 1); __PYX_ERR(0, 88, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end_minute)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, 2); __PYX_ERR(0, 88, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start_minute)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, 3); __PYX_ERR(0, 88, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_volumes)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, 4); __PYX_ERR(0, 88, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minutes_per_day)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, 5); __PYX_ERR(0, 88, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_last_traded_position_internal") < 0)) __PYX_ERR(0, 88, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
    }
    __pyx_v_market_opens = ((PyArrayObject *)values[0]);
    __pyx_v_market_closes = ((PyArrayObject *)values[1]);
    __pyx_v_end_minute = __Pyx_PyInt_As_npy_longlong(values[2]); if (unlikely((__pyx_v_end_minute == ((npy_longlong)-1)) && PyErr_Occurred())) __PYX_ERR(0, 91, __pyx_L3_error)
    __pyx_v_start_minute = __Pyx_PyInt_As_npy_longlong(values[3]); if (unlikely((__pyx_v_start_minute == ((npy_longlong)-1)) && PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L3_error)
    __pyx_v_volumes = values[4];
    __pyx_v_minutes_per_day = __Pyx_PyInt_As_short(values[5]); if (unlikely((__pyx_v_minutes_per_day == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 94, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 88, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.find_last_traded_position_internal", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_market_opens), __pyx_ptype_5numpy_ndarray, 1, "market_opens", 0))) __PYX_ERR(0, 89, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_market_closes), __pyx_ptype_5numpy_ndarray, 1, "market_closes", 0))) __PYX_ERR(0, 90, __pyx_L1_error)
  __pyx_r = __pyx_pf_7zipline_4data_20_minute_bar_internal_4find_last_traded_position_internal(__pyx_self, __pyx_v_market_opens, __pyx_v_market_closes, __pyx_v_end_minute, __pyx_v_start_minute, __pyx_v_volumes, __pyx_v_minutes_per_day);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7zipline_4data_20_minute_bar_internal_4find_last_traded_position_internal(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_market_opens, PyArrayObject *__pyx_v_market_closes, __pyx_t_5numpy_long_t __pyx_v_end_minute, __pyx_t_5numpy_long_t __pyx_v_start_minute, PyObject *__pyx_v_volumes, short __pyx_v_minutes_per_day) {
  Py_ssize_t __pyx_v_minute_pos;
  Py_ssize_t __pyx_v_current_minute;
  Py_ssize_t __pyx_v_q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_market_closes;
  __Pyx_Buffer __pyx_pybuffer_market_closes;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_market_opens;
  __Pyx_Buffer __pyx_pybuffer_market_opens;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__4)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_last_traded_position_internal", 0);
  __Pyx_TraceCall("find_last_traded_position_internal", __pyx_f[0], 88, 0, __PYX_ERR(0, 88, __pyx_L1_error));
  __pyx_pybuffer_market_opens.pybuffer.buf = NULL;
  __pyx_pybuffer_market_opens.refcount = 0;
  __pyx_pybuffernd_market_opens.data = NULL;
  __pyx_pybuffernd_market_opens.rcbuffer = &__pyx_pybuffer_market_opens;
  __pyx_pybuffer_market_closes.pybuffer.buf = NULL;
  __pyx_pybuffer_market_closes.refcount = 0;
  __pyx_pybuffernd_market_closes.data = NULL;
  __pyx_pybuffernd_market_closes.rcbuffer = &__pyx_pybuffer_market_closes;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer, (PyObject*)__pyx_v_market_opens, &__Pyx_TypeInfo_nn___pyx_t_5numpy_long_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 88, __pyx_L1_error)
  }
  __pyx_pybuffernd_market_opens.diminfo[0].strides = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_market_opens.diminfo[0].shape = __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer, (PyObject*)__pyx_v_market_closes, &__Pyx_TypeInfo_nn___pyx_t_5numpy_long_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 88, __pyx_L1_error)
  }
  __pyx_pybuffernd_market_closes.diminfo[0].strides = __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_market_closes.diminfo[0].shape = __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.shape[0];
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("zipline.data._minute_bar_internal.find_last_traded_position_internal", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_closes.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_market_opens.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__9 = PyTuple_Pack(9, __pyx_n_s_market_opens, __pyx_n_s_market_closes, __pyx_n_s_end_minute, __pyx_n_s_start_minute, __pyx_n_s_volumes, __pyx_n_s_minutes_per_day, __pyx_n_s_minute_pos, __pyx_n_s_current_minute, __pyx_n_s_q); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);
/* … */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal, NULL, __pyx_n_s_zipline_data__minute_bar_interna); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_find_last_traded_position_intern, __pyx_t_2) < 0) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 089:         ndarray[long_t, ndim=1] market_opens,
 090:         ndarray[long_t, ndim=1] market_closes,
 091:         long_t end_minute,
 092:         long_t start_minute,
 093:         volumes,
 094:         short minutes_per_day):
 095: 
 096:     """Finds the position of the last traded minute for the given volumes array.
 097: 
 098:     Parameters
 099:     ----------
 100:     market_opens: numpy array of ints
 101:         Market opens, in minute epoch values.
 102: 
 103:     market_closes: numpy array of ints
 104:         Market closes, in minute epoch values.
 105: 
 106:     end_minute: int
 107:         The minute from which to start looking backwards, as a minute epoch.
 108: 
 109:     start_minute: int
 110:         The asset's start date, as a minute epoch.  Acts as the bottom limit of
 111:         how far we can look backwards.
 112: 
 113:     volumes: bcolz carray
 114:         The volume history for the given asset.
 115: 
 116:     minutes_per_day: int
 117:         The number of minutes per day (e.g. 390 for NYSE).
 118: 
 119:     Returns
 120:     -------
 121:     int: The position of the last traded minute, starting from `minute_val`
 122:     """
 123:     cdef Py_ssize_t minute_pos, current_minute, q
 124: 
+125:     minute_pos = int_min(
  __pyx_v_minute_pos = __pyx_f_7zipline_4data_20_minute_bar_internal_int_min(__pyx_t_6, (__pyx_t_8 - 1));
+126:         find_position_of_minute(market_opens, market_closes, end_minute,
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_find_position_of_minute); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_npy_longlong(__pyx_v_end_minute); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
/* … */
  __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+127:                                 minutes_per_day, True),
  __pyx_t_4 = __Pyx_PyInt_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_3, __pyx_t_4, Py_True};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_3, __pyx_t_4, Py_True};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 126, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_market_opens));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_market_opens));
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, ((PyObject *)__pyx_v_market_opens));
    __Pyx_INCREF(((PyObject *)__pyx_v_market_closes));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_market_closes));
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, ((PyObject *)__pyx_v_market_closes));
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_t_4);
    __Pyx_INCREF(Py_True);
    __Pyx_GIVEREF(Py_True);
    PyTuple_SET_ITEM(__pyx_t_7, 4+__pyx_t_6, Py_True);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+128:         len(volumes) - 1
  __pyx_t_8 = PyObject_Length(__pyx_v_volumes); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 128, __pyx_L1_error)
 129:     )
 130: 
+131:     while minute_pos >= 0:
  while (1) {
    __pyx_t_9 = ((__pyx_v_minute_pos >= 0) != 0);
    if (!__pyx_t_9) break;
+132:         current_minute = minute_value(
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_minute_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
/* … */
    __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 132, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_current_minute = __pyx_t_8;
+133:             market_opens, minute_pos, minutes_per_day
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_minute_pos); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_PyInt_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_6 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_market_opens), __pyx_t_7, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_market_opens), __pyx_t_7, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_market_opens));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_market_opens));
      PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_6, ((PyObject *)__pyx_v_market_opens));
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_6, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_6, __pyx_t_4);
      __pyx_t_7 = 0;
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 134:         )
 135: 
+136:         q = cython.cdiv(minute_pos, minutes_per_day)
    __pyx_v_q = (__pyx_v_minute_pos / __pyx_v_minutes_per_day);
+137:         if current_minute > market_closes[q]:
    __pyx_t_10 = __pyx_v_q;
    __pyx_t_6 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_6 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_6 = 0;
    if (unlikely(__pyx_t_6 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_6);
      __PYX_ERR(0, 137, __pyx_L1_error)
    }
    __pyx_t_9 = ((__pyx_v_current_minute > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_long_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_market_closes.diminfo[0].strides))) != 0);
    if (__pyx_t_9) {
/* … */
    }
+138:             minute_pos = find_position_of_minute(market_opens,
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_find_position_of_minute); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
/* … */
      __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 138, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_minute_pos = __pyx_t_8;
 139:                                                  market_closes,
+140:                                                  market_closes[q],
      __pyx_t_10 = __pyx_v_q;
      __pyx_t_6 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_6 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_6 = 0;
      if (unlikely(__pyx_t_6 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_6);
        __PYX_ERR(0, 140, __pyx_L1_error)
      }
      __pyx_t_5 = __Pyx_PyInt_From_npy_longlong((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_long_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_market_closes.diminfo[0].strides))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
+141:                                                  minutes_per_day,
      __pyx_t_4 = __Pyx_PyInt_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
+142:                                                  False)
      __pyx_t_7 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_6 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[6] = {__pyx_t_7, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_5, __pyx_t_4, Py_False};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[6] = {__pyx_t_7, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_5, __pyx_t_4, Py_False};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      {
        __pyx_t_3 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_market_opens));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_market_opens));
        PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_6, ((PyObject *)__pyx_v_market_opens));
        __Pyx_INCREF(((PyObject *)__pyx_v_market_closes));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_market_closes));
        PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_6, ((PyObject *)__pyx_v_market_closes));
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_6, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_6, __pyx_t_4);
        __Pyx_INCREF(Py_False);
        __Pyx_GIVEREF(Py_False);
        PyTuple_SET_ITEM(__pyx_t_3, 4+__pyx_t_6, Py_False);
        __pyx_t_5 = 0;
        __pyx_t_4 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+143:             continue
      goto __pyx_L3_continue;
 144: 
+145:         if current_minute < start_minute:
    __pyx_t_9 = ((__pyx_v_current_minute < __pyx_v_start_minute) != 0);
    if (__pyx_t_9) {
/* … */
    }
+146:             return -1
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_int_neg_1);
      __pyx_r = __pyx_int_neg_1;
      goto __pyx_L0;
 147: 
+148:         if volumes[minute_pos] != 0:
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_volumes, __pyx_v_minute_pos, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_NeObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 148, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_9) {
/* … */
    }
+149:             return minute_pos
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_minute_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;
 150: 
+151:         minute_pos -= 1
    __pyx_v_minute_pos = (__pyx_v_minute_pos - 1);
    __pyx_L3_continue:;
  }
 152: 
 153:     # we've gone to the beginning of this asset's range, and still haven't
 154:     # found a trade event
+155:     return -1
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_int_neg_1);
  __pyx_r = __pyx_int_neg_1;
  goto __pyx_L0;