Cython: _minute_bar_internal.pyx

Generated by Cython 3.1.8

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, int64_t

      __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_3) < (0)) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +002: from numpy import searchsorted

      __pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_searchsorted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_numpy, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_searchsorted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_searchsorted, __pyx_t_2) < (0)) __PYX_ERR(0, 2, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[39]))
      __Pyx_TraceStartFunc("int_min", __pyx_f[0], 6, 0, 0, 0, __PYX_ERR(0, 6, __pyx_L1_error));
      __pyx_t_2 = (__pyx_v_a <= __pyx_v_b);
      if (__pyx_t_2) {
        __pyx_t_1 = __pyx_v_a;
      } else {
        __pyx_t_1 = __pyx_v_b;
      }
      __pyx_r = __pyx_t_1;
      __Pyx_TraceReturnCValue(__pyx_r, __Pyx_PyLong_From_int, 2, 0, __PYX_ERR(0, 6, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 6, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.data._minute_bar_internal.int_min", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_PyMonitoring_ExitScope(0);
      return __pyx_r;
    }

     007:

    +008: @cython.cdivision(True)

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_1minute_value(PyObject *__pyx_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/
    PyDoc_STRVAR(__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(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_1minute_value, __Pyx_METH_FASTCALL|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,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyArrayObject *__pyx_v_market_opens = 0;
      Py_ssize_t __pyx_v_pos;
      short __pyx_v_minutes_per_day;
      #if !CYTHON_METH_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("minute_value (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_market_opens,&__pyx_mstate_global->__pyx_n_u_pos,&__pyx_mstate_global->__pyx_n_u_minutes_per_day,0};
      PyObject* values[3] = {0,0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 8, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  3:
            values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 8, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 8, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 8, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "minute_value", 0) < (0)) __PYX_ERR(0, 8, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("minute_value", 1, 3, 3, i); __PYX_ERR(0, 8, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 3)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 8, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 8, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 8, __pyx_L3_error)
        }
        __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_PyLong_As_short(values[2]); if (unlikely((__pyx_v_minutes_per_day == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("minute_value", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 8, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_mstate_global->__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;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      goto __pyx_L7_cleaned_up;
      __pyx_L0:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __pyx_L7_cleaned_up:;
      __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_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[40]))
      __Pyx_TraceStartFunc("minute_value", __pyx_f[0], 8, 0, 0, 0, __PYX_ERR(0, 8, __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_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 8, __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_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 8, __pyx_L1_error));
      #endif
      __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_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_1minute_value, 0, __pyx_mstate_global->__pyx_n_u_minute_value, NULL, __pyx_mstate_global->__pyx_n_u_zipline_data__minute_bar_interna, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[40])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_minute_value, __pyx_t_3) < (0)) __PYX_ERR(0, 8, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     009: def minute_value(ndarray[int64_t, ndim=1] market_opens,

     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_PyLong_From_npy_int64(((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_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;
      __Pyx_TraceReturnValue(__pyx_r, 11, 0, __PYX_ERR(0, 35, __pyx_L1_error));
      goto __pyx_L0;

     036:

    +037: def find_position_of_minute(ndarray[int64_t, ndim=1] market_opens,

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_4data_20_minute_bar_internal_3find_position_of_minute(PyObject *__pyx_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/
    PyDoc_STRVAR(__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(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_3find_position_of_minute, __Pyx_METH_FASTCALL|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,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyArrayObject *__pyx_v_market_opens = 0;
      PyArrayObject *__pyx_v_market_closes = 0;
      __pyx_t_5numpy_int64_t __pyx_v_minute_val;
      short __pyx_v_minutes_per_day;
      PyLongObject *__pyx_v_forward_fill = 0;
      #if !CYTHON_METH_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("find_position_of_minute (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_market_opens,&__pyx_mstate_global->__pyx_n_u_market_closes,&__pyx_mstate_global->__pyx_n_u_minute_val,&__pyx_mstate_global->__pyx_n_u_minutes_per_day,&__pyx_mstate_global->__pyx_n_u_forward_fill,0};
      PyObject* values[5] = {0,0,0,0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 37, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  5:
            values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 37, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  4:
            values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 37, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  3:
            values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 37, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 37, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 37, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "find_position_of_minute", 0) < (0)) __PYX_ERR(0, 37, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 5; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, i); __PYX_ERR(0, 37, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 5)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 37, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 37, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 37, __pyx_L3_error)
          values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 37, __pyx_L3_error)
          values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 37, __pyx_L3_error)
        }
        __pyx_v_market_opens = ((PyArrayObject *)values[0]);
        __pyx_v_market_closes = ((PyArrayObject *)values[1]);
        __pyx_v_minute_val = __Pyx_PyLong_As_npy_int64(values[2]); if (unlikely((__pyx_v_minute_val == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error)
        __pyx_v_minutes_per_day = __Pyx_PyLong_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 = ((PyLongObject *)values[4]);
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("find_position_of_minute", 1, 5, 5, __pyx_nargs); __PYX_ERR(0, 37, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_mstate_global->__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_mstate_global->__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_mstate_global->__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;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      goto __pyx_L7_cleaned_up;
      __pyx_L0:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __pyx_L7_cleaned_up:;
      __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_int64_t __pyx_v_minute_val, short __pyx_v_minutes_per_day, PyLongObject *__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_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[41]))
      __Pyx_TraceStartFunc("find_position_of_minute", __pyx_f[0], 37, 0, 0, 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_int64_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_int64_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);
      __Pyx_XDECREF(__pyx_t_6);
      { 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_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 37, __pyx_L1_error));
      #endif
      __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_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_3find_position_of_minute, 0, __pyx_mstate_global->__pyx_n_u_find_position_of_minute, NULL, __pyx_mstate_global->__pyx_n_u_zipline_data__minute_bar_interna, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[41])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_find_position_of_minute, __pyx_t_3) < (0)) __PYX_ERR(0, 37, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     038:                             ndarray[int64_t, ndim=1] market_closes,

     039:                             int64_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_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_searchsorted); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyLong_From_npy_int64(__pyx_v_minute_val); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        assert(__pyx_t_2);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
        __pyx_t_5 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[3 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, ((PyObject *)__pyx_v_market_opens), __pyx_t_4};
        __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_side, __pyx_mstate_global->__pyx_n_u_right, __pyx_t_6, __pyx_callargs+3, 0) < (0)) __PYX_ERR(0, 77, __pyx_L1_error)
        __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_3, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_t_3 = __Pyx_PyLong_SubtractObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_market_open_loc = __pyx_t_7;

    +078:     market_open = market_opens[market_open_loc]

      __pyx_t_8 = __pyx_v_market_open_loc;
      __pyx_t_9 = -1;
      if (__pyx_t_8 < 0) {
        __pyx_t_8 += __pyx_pybuffernd_market_opens.diminfo[0].shape;
        if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_8 >= __pyx_pybuffernd_market_opens.diminfo[0].shape)) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 78, __pyx_L1_error)
      }
      __pyx_v_market_open = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_market_opens.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_market_opens.diminfo[0].strides));

    +079:     market_close = market_closes[market_open_loc]

      __pyx_t_8 = __pyx_v_market_open_loc;
      __pyx_t_9 = -1;
      if (__pyx_t_8 < 0) {
        __pyx_t_8 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
        if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_8 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 79, __pyx_L1_error)
      }
      __pyx_t_3 = __Pyx_PyLong_From_npy_int64((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_market_closes.diminfo[0].strides))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 79, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_market_close = __pyx_t_3;
      __pyx_t_3 = 0;

     080:

    +081:     if not forward_fill and ((minute_val - market_open) >= minutes_per_day):

      __pyx_t_11 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_forward_fill)); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 81, __pyx_L1_error)
      __pyx_t_12 = (!__pyx_t_11);
      if (__pyx_t_12) {
      } else {
        __pyx_t_10 = __pyx_t_12;
        goto __pyx_L4_bool_binop_done;
      }
      __pyx_t_12 = ((__pyx_v_minute_val - __pyx_v_market_open) >= __pyx_v_minutes_per_day);
      __pyx_t_10 = __pyx_t_12;
      __pyx_L4_bool_binop_done:;
      if (unlikely(__pyx_t_10)) {
    /* … */
      }

    +082:         raise ValueError("Given minute is not between an open and a close")

        __pyx_t_1 = NULL;
        __Pyx_INCREF(__pyx_builtin_ValueError);
        __pyx_t_6 = __pyx_builtin_ValueError;
        __pyx_t_5 = 1;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_Given_minute_is_not_between_an_o};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __PYX_ERR(0, 82, __pyx_L1_error)

     083:

    +084:     delta = int_min(minute_val - market_open, market_close - market_open)

      __pyx_t_3 = PyLong_FromSsize_t(__pyx_v_market_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 84, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Subtract(__pyx_v_market_close, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 84, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = __Pyx_PyLong_As_int(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_13 = __pyx_f_7zipline_4data_20_minute_bar_internal_int_min((__pyx_v_minute_val - __pyx_v_market_open), __pyx_t_9); if (unlikely(__pyx_t_13 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L1_error)
      __pyx_v_delta = __pyx_t_13;

     085:

    +086:     return (market_open_loc * minutes_per_day) + delta

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = PyLong_FromSsize_t(((__pyx_v_market_open_loc * __pyx_v_minutes_per_day) + __pyx_v_delta)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 40, 0, __PYX_ERR(0, 86, __pyx_L1_error));
      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,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/
    PyDoc_STRVAR(__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(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal, __Pyx_METH_FASTCALL|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,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyArrayObject *__pyx_v_market_opens = 0;
      PyArrayObject *__pyx_v_market_closes = 0;
      __pyx_t_5numpy_int64_t __pyx_v_end_minute;
      __pyx_t_5numpy_int64_t __pyx_v_start_minute;
      PyObject *__pyx_v_volumes = 0;
      short __pyx_v_minutes_per_day;
      #if !CYTHON_METH_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("find_last_traded_position_internal (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_market_opens,&__pyx_mstate_global->__pyx_n_u_market_closes,&__pyx_mstate_global->__pyx_n_u_end_minute,&__pyx_mstate_global->__pyx_n_u_start_minute,&__pyx_mstate_global->__pyx_n_u_volumes,&__pyx_mstate_global->__pyx_n_u_minutes_per_day,0};
      PyObject* values[6] = {0,0,0,0,0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 88, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  6:
            values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  5:
            values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  4:
            values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  3:
            values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 88, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "find_last_traded_position_internal", 0) < (0)) __PYX_ERR(0, 88, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 6; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, i); __PYX_ERR(0, 88, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 6)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 88, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 88, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 88, __pyx_L3_error)
          values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 88, __pyx_L3_error)
          values[4] = __Pyx_ArgRef_FASTCALL(__pyx_args, 4);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 88, __pyx_L3_error)
          values[5] = __Pyx_ArgRef_FASTCALL(__pyx_args, 5);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[5])) __PYX_ERR(0, 88, __pyx_L3_error)
        }
        __pyx_v_market_opens = ((PyArrayObject *)values[0]);
        __pyx_v_market_closes = ((PyArrayObject *)values[1]);
        __pyx_v_end_minute = __Pyx_PyLong_As_npy_int64(values[2]); if (unlikely((__pyx_v_end_minute == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 91, __pyx_L3_error)
        __pyx_v_start_minute = __Pyx_PyLong_As_npy_int64(values[3]); if (unlikely((__pyx_v_start_minute == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L3_error)
        __pyx_v_volumes = values[4];
        __pyx_v_minutes_per_day = __Pyx_PyLong_As_short(values[5]); if (unlikely((__pyx_v_minutes_per_day == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 94, __pyx_L3_error)
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("find_last_traded_position_internal", 1, 6, 6, __pyx_nargs); __PYX_ERR(0, 88, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_mstate_global->__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_mstate_global->__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;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      goto __pyx_L7_cleaned_up;
      __pyx_L0:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __pyx_L7_cleaned_up:;
      __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_int64_t __pyx_v_end_minute, __pyx_t_5numpy_int64_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_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[42]))
      __Pyx_TraceStartFunc("find_last_traded_position_internal", __pyx_f[0], 88, 0, 0, 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_int64_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_int64_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];
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_4data_20_minute_bar_internal_5find_last_traded_position_internal, 0, __pyx_mstate_global->__pyx_n_u_find_last_traded_position_intern, NULL, __pyx_mstate_global->__pyx_n_u_zipline_data__minute_bar_interna, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[42])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_find_last_traded_position_intern, __pyx_t_3) < (0)) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     089:         ndarray[int64_t, ndim=1] market_opens,

     090:         ndarray[int64_t, ndim=1] market_closes,

     091:         int64_t end_minute,

     092:         int64_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_t_9 = __pyx_f_7zipline_4data_20_minute_bar_internal_int_min(__pyx_t_7, (__pyx_t_8 - 1)); if (unlikely(__pyx_t_9 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 125, __pyx_L1_error)
      __pyx_v_minute_pos = __pyx_t_9;

    +126:         find_position_of_minute(market_opens, market_closes, end_minute,

      __pyx_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_find_position_of_minute); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyLong_From_npy_int64(__pyx_v_end_minute); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    /* … */
      __pyx_t_7 = __Pyx_PyLong_As_int(__pyx_t_1); if (unlikely((__pyx_t_7 == (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_5 = __Pyx_PyLong_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 127, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        assert(__pyx_t_2);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_3, __pyx__function);
        __pyx_t_6 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[6] = {__pyx_t_2, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_4, __pyx_t_5, Py_True};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_6, (6-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }

    +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_10 = (__pyx_v_minute_pos >= 0);
        if (!__pyx_t_10) break;

    +132:         current_minute = minute_value(

        __pyx_t_3 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_minute_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
    /* … */
        __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_4 = PyLong_FromSsize_t(__pyx_v_minute_pos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_2 = __Pyx_PyLong_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_6 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_3);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_6 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[4] = {__pyx_t_3, ((PyObject *)__pyx_v_market_opens), __pyx_t_4, __pyx_t_2};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (4-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
        }

     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_11 = __pyx_v_q;
        __pyx_t_9 = -1;
        if (__pyx_t_11 < 0) {
          __pyx_t_11 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
          if (unlikely(__pyx_t_11 < 0)) __pyx_t_9 = 0;
        } else if (unlikely(__pyx_t_11 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_9 = 0;
        if (unlikely(__pyx_t_9 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_9);
          __PYX_ERR(0, 137, __pyx_L1_error)
        }
        __pyx_t_10 = (__pyx_v_current_minute > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_market_closes.diminfo[0].strides)));
        if (__pyx_t_10) {
    /* … */
        }

    +138:             minute_pos = find_position_of_minute(market_opens,

          __pyx_t_5 = NULL;
          __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_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_11 = __pyx_v_q;
          __pyx_t_9 = -1;
          if (__pyx_t_11 < 0) {
            __pyx_t_11 += __pyx_pybuffernd_market_closes.diminfo[0].shape;
            if (unlikely(__pyx_t_11 < 0)) __pyx_t_9 = 0;
          } else if (unlikely(__pyx_t_11 >= __pyx_pybuffernd_market_closes.diminfo[0].shape)) __pyx_t_9 = 0;
          if (unlikely(__pyx_t_9 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_9);
            __PYX_ERR(0, 140, __pyx_L1_error)
          }
          __pyx_t_4 = __Pyx_PyLong_From_npy_int64((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_market_closes.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_market_closes.diminfo[0].strides))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);

    +141:                                                  minutes_per_day,

          __pyx_t_3 = __Pyx_PyLong_From_short(__pyx_v_minutes_per_day); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);

    +142:                                                  False)

          __pyx_t_6 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
            assert(__pyx_t_5);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
            __pyx_t_6 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[6] = {__pyx_t_5, ((PyObject *)__pyx_v_market_opens), ((PyObject *)__pyx_v_market_closes), __pyx_t_4, __pyx_t_3, Py_False};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_6, (6-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }

    +143:             continue

          goto __pyx_L3_continue;

     144:

    +145:         if current_minute < start_minute:

        __pyx_t_10 = (__pyx_v_current_minute < __pyx_v_start_minute);
        if (__pyx_t_10) {
    /* … */
        }

    +146:             return -1

          __Pyx_XDECREF(__pyx_r);
          __Pyx_INCREF(__pyx_mstate_global->__pyx_int_neg_1);
          __pyx_r = __pyx_mstate_global->__pyx_int_neg_1;
          __Pyx_TraceReturnValue(__pyx_r, 52, 0, __PYX_ERR(0, 146, __pyx_L1_error));
          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, PyLong_FromSsize_t, 0, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_10 = (__Pyx_PyLong_BoolNeObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 148, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_10) {
    /* … */
        }

    +149:             return minute_pos

          __Pyx_XDECREF(__pyx_r);
          __pyx_t_1 = PyLong_FromSsize_t(__pyx_v_minute_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_r = __pyx_t_1;
          __pyx_t_1 = 0;
          __Pyx_TraceReturnValue(__pyx_r, 60, 0, __PYX_ERR(0, 149, __pyx_L1_error));
          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_mstate_global->__pyx_int_neg_1);
      __pyx_r = __pyx_mstate_global->__pyx_int_neg_1;
      __Pyx_TraceReturnValue(__pyx_r, 64, 0, __PYX_ERR(0, 155, __pyx_L1_error));
      goto __pyx_L0;