Cython: _finance_ext.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: _finance_ext.c

    +001: cimport cython

      __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 cpython cimport PyObject

     003: from libc.math cimport sqrt

     004:

     005: cimport numpy as np

    +006: import numpy as np

      __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __pyx_t_2) < (0)) __PYX_ERR(0, 6, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +007: import pandas as pd

      __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_pandas, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_pd, __pyx_t_2) < (0)) __PYX_ERR(0, 7, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     008:

     009: from zipline._protocol cimport InnerPosition

     010: from zipline.assets._assets cimport Future

     011:

     012:

    +013: cpdef update_position_last_sale_prices(positions, get_price, dt):

    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(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*/
    static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt, CYTHON_UNUSED int __pyx_skip_dispatch) {
      struct __pyx_obj_7zipline_9_protocol_InnerPosition *__pyx_v_inner_position = 0;
      __pyx_t_5numpy_float64_t __pyx_v_last_sale_price;
      PyObject *__pyx_v_outer_position = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[39]))
      __Pyx_TraceStartFunc("update_position_last_sale_prices", __pyx_f[0], 13, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 13, __pyx_L1_error));
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XDECREF((PyObject *)__pyx_v_inner_position);
      __Pyx_XDECREF(__pyx_v_outer_position);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(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_7finance_12_finance_ext_update_position_last_sale_prices, "Update the positions' last sale prices.\n\n    Parameters\n    ----------\n    positions : OrderedDict\n        The positions to update.\n    get_price : callable[Asset, float]\n        The function to retrieve the price for the asset.\n    dt : pd.Timestamp\n        The dt to set as the last sale date if the price is not nan.\n    ");
    static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices = {"update_position_last_sale_prices", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_update_position_last_sale_prices};
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(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
    ) {
      PyObject *__pyx_v_positions = 0;
      PyObject *__pyx_v_get_price = 0;
      PyObject *__pyx_v_dt = 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("update_position_last_sale_prices (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_positions,&__pyx_mstate_global->__pyx_n_u_get_price,&__pyx_mstate_global->__pyx_n_u_dt,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, 13, __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, 13, __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, 13, __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, 13, __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, "update_position_last_sale_prices", 0) < (0)) __PYX_ERR(0, 13, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, i); __PYX_ERR(0, 13, __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, 13, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 13, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 13, __pyx_L3_error)
        }
        __pyx_v_positions = values[0];
        __pyx_v_get_price = values[1];
        __pyx_v_dt = values[2];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 13, __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.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(__pyx_self, __pyx_v_positions, __pyx_v_get_price, __pyx_v_dt);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      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_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[39]))
      __Pyx_TraceStartFunc("update_position_last_sale_prices (wrapper)", __pyx_f[0], 13, 0, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(__pyx_v_positions, __pyx_v_get_price, __pyx_v_dt, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, 0, __pyx_mstate_global->__pyx_n_u_update_position_last_sale_prices, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[39])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_update_position_last_sale_prices, __pyx_t_2) < (0)) __PYX_ERR(0, 13, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     014:     """Update the positions' last sale prices.

     015:

     016:     Parameters

     017:     ----------

     018:     positions : OrderedDict

     019:         The positions to update.

     020:     get_price : callable[Asset, float]

     021:         The function to retrieve the price for the asset.

     022:     dt : pd.Timestamp

     023:         The dt to set as the last sale date if the price is not nan.

     024:     """

     025:     cdef InnerPosition inner_position

     026:     cdef np.float64_t last_sale_price

     027:

    +028:     for outer_position in positions.values():

      __pyx_t_2 = 0;
      if (unlikely(__pyx_v_positions == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values");
        __PYX_ERR(0, 28, __pyx_L1_error)
      }
      __pyx_t_5 = __Pyx_dict_iterator(__pyx_v_positions, 0, __pyx_mstate_global->__pyx_n_u_values, (&__pyx_t_3), (&__pyx_t_4)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 28, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_1);
      __pyx_t_1 = __pyx_t_5;
      __pyx_t_5 = 0;
      while (1) {
        __pyx_t_6 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_3, &__pyx_t_2, NULL, &__pyx_t_5, NULL, __pyx_t_4);
        if (unlikely(__pyx_t_6 == 0)) break;
        if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 28, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_5);
        __pyx_t_5 = 0;

    +029:         inner_position = outer_position.inner_position

        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_outer_position, __pyx_mstate_global->__pyx_n_u_inner_position); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 29, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_mstate_global->__pyx_ptype_7zipline_9_protocol_InnerPosition))))) __PYX_ERR(0, 29, __pyx_L1_error)
        __Pyx_XDECREF_SET(__pyx_v_inner_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_5));
        __pyx_t_5 = 0;

     030:

    +031:         last_sale_price = get_price(inner_position.asset)

        __pyx_t_7 = NULL;
        __Pyx_INCREF(__pyx_v_get_price);
        __pyx_t_8 = __pyx_v_get_price;
        __pyx_t_9 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_7);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_9 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, ((PyObject *)__pyx_v_inner_position->asset)};
          __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
        }
        __pyx_t_10 = __Pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_10 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_v_last_sale_price = __pyx_t_10;

     032:

     033:         # inline ~isnan because this gets called once per position per minute

    +034:         if last_sale_price == last_sale_price:

        __pyx_t_11 = (__pyx_v_last_sale_price == __pyx_v_last_sale_price);
        if (__pyx_t_11) {
    /* … */
        }
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +035:             inner_position.last_sale_price = last_sale_price

          __pyx_v_inner_position->last_sale_price = __pyx_v_last_sale_price;

    +036:             inner_position.last_sale_date = dt

          __Pyx_INCREF(__pyx_v_dt);
          __Pyx_GIVEREF(__pyx_v_dt);
          __Pyx_GOTREF(__pyx_v_inner_position->last_sale_date);
          __Pyx_DECREF(__pyx_v_inner_position->last_sale_date);
          __pyx_v_inner_position->last_sale_date = __pyx_v_dt;

     037:

     038:

    +039: @cython.final

    struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats {
      PyObject_HEAD
      __pyx_t_5numpy_float64_t gross_exposure;
      __pyx_t_5numpy_float64_t gross_value;
      __pyx_t_5numpy_float64_t long_exposure;
      __pyx_t_5numpy_float64_t long_value;
      __pyx_t_5numpy_float64_t net_exposure;
      __pyx_t_5numpy_float64_t net_value;
      __pyx_t_5numpy_float64_t short_exposure;
      __pyx_t_5numpy_float64_t short_value;
      __pyx_t_5numpy_uint64_t longs_count;
      __pyx_t_5numpy_uint64_t shorts_count;
      PyObject *position_exposure_array;
      PyObject *position_exposure_series;
      PyObject *underlying_value_array;
      PyObject *underlying_index_array;
    };

     040: cdef class PositionStats:

     041:     """Computed values from the current positions.

     042:

     043:     Attributes

     044:     ----------

     045:     gross_exposure : float64

     046:         The gross position exposure.

     047:     gross_value : float64

     048:         The gross position value.

     049:     long_exposure : float64

     050:         The exposure of just the long positions.

     051:     long_value : float64

     052:         The value of just the long positions.

     053:     net_exposure : float64

     054:         The net position exposure.

     055:     net_value : float64

     056:         The net position value.

     057:     short_exposure : float64

     058:         The exposure of just the short positions.

     059:     short_value : float64

     060:         The value of just the short positions.

     061:     longs_count : int64

     062:         The number of long positions.

     063:     shorts_count : int64

     064:         The number of short positions.

     065:     position_exposure_array : np.ndarray[float64]

     066:         The exposure of each position in the same order as

     067:         ``position_tracker.positions``.

     068:     position_exposure_series : pd.Series[float64]

     069:         The exposure of each position in the same order as

     070:         ``position_tracker.positions``. The index is the numeric sid of each

     071:         asset.

     072:

     073:     Notes

     074:     -----

     075:     ``position_exposure_array`` and ``position_exposure_series`` share the same

     076:     underlying memory. The array interface should be preferred if you are doing

     077:     access each minute for better performance.

     078:

     079:     ``position_exposure_array`` and ``position_exposure_series`` may be mutated

     080:     when the position tracker next updates the stats. Do not rely on these

     081:     objects being preserved across accesses to ``stats``. If you need to freeze

     082:     the values, you must take a copy.

     083:     """

    +084:     cdef readonly np.float64_t gross_exposure

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[41]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 84, 0, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->gross_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.gross_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +085:     cdef readonly np.float64_t gross_value

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[42]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 85, 0, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->gross_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.gross_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +086:     cdef readonly np.float64_t long_exposure

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[43]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 86, 0, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->long_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.long_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +087:     cdef readonly np.float64_t long_value

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[44]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 87, 0, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->long_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.long_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +088:     cdef readonly np.float64_t net_exposure

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[45]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 88, 0, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->net_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.net_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +089:     cdef readonly np.float64_t net_value

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[46]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 89, 0, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->net_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.net_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +090:     cdef readonly np.float64_t short_exposure

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[47]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 90, 0, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->short_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.short_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +091:     cdef readonly np.float64_t short_value

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[48]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 91, 0, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->short_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.short_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +092:     cdef readonly np.uint64_t longs_count

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[49]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 92, 0, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyLong_From_npy_uint64(__pyx_v_self->longs_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.longs_count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +093:     cdef readonly np.uint64_t shorts_count

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[50]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 93, 0, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyLong_From_npy_uint64(__pyx_v_self->shorts_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.shorts_count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +094:     cdef readonly object position_exposure_array

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[51]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 94, 0, 0, 0, __PYX_ERR(0, 94, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_self->position_exposure_array);
      __pyx_r = __pyx_v_self->position_exposure_array;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 94, __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, 94, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.position_exposure_array.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +095:     cdef readonly object position_exposure_series

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self); /*proto*/
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[52]))
      __Pyx_TraceStartFunc("__get__", __pyx_f[0], 95, 0, 0, 0, __PYX_ERR(0, 95, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_self->position_exposure_series);
      __pyx_r = __pyx_v_self->position_exposure_series;
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 95, __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, 95, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.position_exposure_series.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     096:

     097:     # These are the same memory exposed through ``position_exposure_array``

     098:     # and ``position_exposure_series``. These are hidden from Python.

     099:     cdef object underlying_value_array

     100:     cdef object underlying_index_array

     101:

    +102:     @classmethod

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls,
    #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*/
    static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new = {"new", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      #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("new (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);
      if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("new", 1, 0, 0, __pyx_nargs); return NULL; }
      const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
      if (unlikely(__pyx_kwds_len < 0)) return NULL;
      if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("new", __pyx_kwds); return NULL;}
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(((PyTypeObject*)__pyx_v_cls));

      /* function exit code */
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(PyTypeObject *__pyx_v_cls) {
      struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self = 0;
      PyObject *__pyx_v_es = NULL;
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[40]))
      __Pyx_TraceStartFunc("new", __pyx_f[0], 102, 0, 0, 0, __PYX_ERR(0, 102, __pyx_L1_error));
    /* … */
      /* 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_5);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_XDECREF(__pyx_t_9);
      __Pyx_XDECREF(__pyx_t_10);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 102, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.new", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF((PyObject *)__pyx_v_self);
      __Pyx_XDECREF(__pyx_v_es);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PositionStats_new, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[40])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2, __pyx_t_2) < (0)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GetNameInClass(__pyx_t_2, (PyObject*)__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2, __pyx_t_3) < (0)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     103:     def new(cls):

    +104:         cdef PositionStats self = cls()

      __pyx_t_2 = NULL;
      __Pyx_INCREF((PyObject *)__pyx_v_cls);
      __pyx_t_3 = ((PyObject *)__pyx_v_cls);
      __pyx_t_4 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats))))) __PYX_ERR(0, 104, __pyx_L1_error)
      __pyx_v_self = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_t_1);
      __pyx_t_1 = 0;

    +105:         self.position_exposure_series = es = pd.Series(

      __pyx_t_3 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 105, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    /* … */
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_self->position_exposure_series);
      __Pyx_DECREF(__pyx_v_self->position_exposure_series);
      __pyx_v_self->position_exposure_series = __pyx_t_1;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_v_es = __pyx_t_1;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +106:             np.array([], dtype='float64'),

      __pyx_t_6 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_4 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8);
        assert(__pyx_t_6);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
        __pyx_t_4 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_7};
        __pyx_t_9 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 106, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_float64, __pyx_t_9, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 106, __pyx_L1_error)
        __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_9);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      }

    +107:             index=np.array([], dtype='int64'),

      __pyx_t_9 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_4 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
        assert(__pyx_t_9);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
        __pyx_t_4 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_9, __pyx_t_7};
        __pyx_t_10 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 107, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_int64, __pyx_t_10, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 107, __pyx_L1_error)
        __pyx_t_8 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_6, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_10);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 107, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      }
      __pyx_t_4 = 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_4 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_3, __pyx_t_2};
        __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, __pyx_t_8, __pyx_t_6, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 105, __pyx_L1_error)
        __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }

     108:         )

    +109:         self.underlying_value_array = self.position_exposure_array = es.values

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_es, __pyx_mstate_global->__pyx_n_u_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_self->underlying_value_array);
      __Pyx_DECREF(__pyx_v_self->underlying_value_array);
      __pyx_v_self->underlying_value_array = __pyx_t_1;
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_self->position_exposure_array);
      __Pyx_DECREF(__pyx_v_self->position_exposure_array);
      __pyx_v_self->position_exposure_array = __pyx_t_1;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +110:         self.underlying_index_array = es.index.values

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_es, __pyx_mstate_global->__pyx_n_u_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_v_self->underlying_index_array);
      __Pyx_DECREF(__pyx_v_self->underlying_index_array);
      __pyx_v_self->underlying_index_array = __pyx_t_5;
      __pyx_t_5 = 0;

    +111:         return self

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF((PyObject *)__pyx_v_self);
      __pyx_r = ((PyObject *)__pyx_v_self);
      __Pyx_TraceReturnValue(__pyx_r, 34, 0, __PYX_ERR(0, 111, __pyx_L1_error));
      goto __pyx_L0;

     112:

     113:

    +114: cpdef calculate_position_tracker_stats(positions, PositionStats stats):

    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(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*/
    static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_calculate_position_tracker_stats(PyObject *__pyx_v_positions, struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats, CYTHON_UNUSED int __pyx_skip_dispatch) {
      Py_ssize_t __pyx_v_npos;
      PyArrayObject *__pyx_v_index = 0;
      PyArrayObject *__pyx_v_position_exposure = 0;
      PyArrayObject *__pyx_v_old_index = 0;
      PyArrayObject *__pyx_v_old_position_exposure = 0;
      __pyx_t_5numpy_float64_t __pyx_v_value;
      __pyx_t_5numpy_float64_t __pyx_v_exposure;
      __pyx_t_5numpy_float64_t __pyx_v_net_value;
      __pyx_t_5numpy_float64_t __pyx_v_gross_value;
      __pyx_t_5numpy_float64_t __pyx_v_long_value;
      __pyx_t_5numpy_float64_t __pyx_v_short_value;
      __pyx_t_5numpy_float64_t __pyx_v_net_exposure;
      __pyx_t_5numpy_float64_t __pyx_v_gross_exposure;
      __pyx_t_5numpy_float64_t __pyx_v_long_exposure;
      __pyx_t_5numpy_float64_t __pyx_v_short_exposure;
      __pyx_t_5numpy_uint64_t __pyx_v_longs_count;
      __pyx_t_5numpy_uint64_t __pyx_v_shorts_count;
      struct __pyx_obj_7zipline_9_protocol_InnerPosition *__pyx_v_position = 0;
      Py_ssize_t __pyx_v_ix;
      PyObject *__pyx_v_outer_position = NULL;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_index;
      __Pyx_Buffer __pyx_pybuffer_index;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_old_index;
      __Pyx_Buffer __pyx_pybuffer_old_index;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_old_position_exposure;
      __Pyx_Buffer __pyx_pybuffer_old_position_exposure;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_position_exposure;
      __Pyx_Buffer __pyx_pybuffer_position_exposure;
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55]))
      __Pyx_TraceStartFunc("calculate_position_tracker_stats", __pyx_f[0], 114, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 114, __pyx_L1_error));
      __pyx_pybuffer_index.pybuffer.buf = NULL;
      __pyx_pybuffer_index.refcount = 0;
      __pyx_pybuffernd_index.data = NULL;
      __pyx_pybuffernd_index.rcbuffer = &__pyx_pybuffer_index;
      __pyx_pybuffer_position_exposure.pybuffer.buf = NULL;
      __pyx_pybuffer_position_exposure.refcount = 0;
      __pyx_pybuffernd_position_exposure.data = NULL;
      __pyx_pybuffernd_position_exposure.rcbuffer = &__pyx_pybuffer_position_exposure;
      __pyx_pybuffer_old_index.pybuffer.buf = NULL;
      __pyx_pybuffer_old_index.refcount = 0;
      __pyx_pybuffernd_old_index.data = NULL;
      __pyx_pybuffernd_old_index.rcbuffer = &__pyx_pybuffer_old_index;
      __pyx_pybuffer_old_position_exposure.pybuffer.buf = NULL;
      __pyx_pybuffer_old_position_exposure.refcount = 0;
      __pyx_pybuffernd_old_position_exposure.data = NULL;
      __pyx_pybuffernd_old_position_exposure.rcbuffer = &__pyx_pybuffer_old_position_exposure;
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      __Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 114, __pyx_L1_error));
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_8);
      { 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_index.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.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, 114, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_index);
      __Pyx_XDECREF((PyObject *)__pyx_v_position_exposure);
      __Pyx_XDECREF((PyObject *)__pyx_v_old_index);
      __Pyx_XDECREF((PyObject *)__pyx_v_old_position_exposure);
      __Pyx_XDECREF((PyObject *)__pyx_v_position);
      __Pyx_XDECREF(__pyx_v_outer_position);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(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_7finance_12_finance_ext_2calculate_position_tracker_stats, "Calculate various stats about the current positions.\n\n    Parameters\n    ----------\n    positions : OrderedDict\n        The ordered dictionary of positions.\n\n    Returns\n    -------\n    position_stats : PositionStats\n        The computed statistics.\n    ");
    static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats = {"calculate_position_tracker_stats", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats};
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(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
    ) {
      PyObject *__pyx_v_positions = 0;
      struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats = 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("calculate_position_tracker_stats (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_positions,&__pyx_mstate_global->__pyx_n_u_stats,0};
      PyObject* values[2] = {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, 114, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 114, __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, 114, __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, "calculate_position_tracker_stats", 0) < (0)) __PYX_ERR(0, 114, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 2; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, i); __PYX_ERR(0, 114, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 2)) {
          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, 114, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 114, __pyx_L3_error)
        }
        __pyx_v_positions = values[0];
        __pyx_v_stats = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)values[1]);
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 114, __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.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stats), __pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, 1, "stats", 0))) __PYX_ERR(0, 114, __pyx_L1_error)
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats(__pyx_self, __pyx_v_positions, __pyx_v_stats);
      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_7finance_12_finance_ext_2calculate_position_tracker_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_positions, struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats) {
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55]))
      __Pyx_TraceStartFunc("calculate_position_tracker_stats (wrapper)", __pyx_f[0], 114, 0, 0, 0, __PYX_ERR(0, 114, __pyx_L1_error));
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_calculate_position_tracker_stats(__pyx_v_positions, __pyx_v_stats, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_TraceException(__pyx_lineno, 0, 0);
      #if CYTHON_USE_SYS_MONITORING
      __Pyx_TraceExceptionUnwind(0, 0);
      #else
      __Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 114, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, 0, __pyx_mstate_global->__pyx_n_u_calculate_position_tracker_stats, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_calculate_position_tracker_stats, __pyx_t_3) < (0)) __PYX_ERR(0, 114, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     115:     """Calculate various stats about the current positions.

     116:

     117:     Parameters

     118:     ----------

     119:     positions : OrderedDict

     120:         The ordered dictionary of positions.

     121:

     122:     Returns

     123:     -------

     124:     position_stats : PositionStats

     125:         The computed statistics.

     126:     """

    +127:     cdef Py_ssize_t npos = len(positions)

      __pyx_t_1 = PyObject_Length(__pyx_v_positions); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 127, __pyx_L1_error)
      __pyx_v_npos = __pyx_t_1;

     128:     cdef np.ndarray[np.int64_t] index

     129:     cdef np.ndarray[np.float64_t] position_exposure

     130:

    +131:     cdef np.ndarray[np.int64_t] old_index = stats.underlying_index_array

      __pyx_t_2 = __pyx_v_stats->underlying_index_array;
      __Pyx_INCREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 131, __pyx_L1_error)
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          __pyx_v_old_index = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_old_index.rcbuffer->pybuffer.buf = NULL;
          __PYX_ERR(0, 131, __pyx_L1_error)
        } else {__pyx_pybuffernd_old_index.diminfo[0].strides = __pyx_pybuffernd_old_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_old_index.diminfo[0].shape = __pyx_pybuffernd_old_index.rcbuffer->pybuffer.shape[0];
        }
      }
      __pyx_v_old_index = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;

     132:     cdef np.ndarray[np.float64_t] old_position_exposure = (

    +133:         stats.underlying_value_array

      __pyx_t_2 = __pyx_v_stats->underlying_value_array;
      __Pyx_INCREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 133, __pyx_L1_error)
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          __pyx_v_old_position_exposure = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer.buf = NULL;
          __PYX_ERR(0, 132, __pyx_L1_error)
        } else {__pyx_pybuffernd_old_position_exposure.diminfo[0].strides = __pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_old_position_exposure.diminfo[0].shape = __pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer.shape[0];
        }
      }
      __pyx_v_old_position_exposure = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;

     134:     )

     135:

     136:     cdef np.float64_t value

     137:     cdef np.float64_t exposure

     138:

     139:     cdef np.float64_t net_value

     140:     cdef np.float64_t gross_value

    +141:     cdef np.float64_t long_value = 0.0

      __pyx_v_long_value = 0.0;

    +142:     cdef np.float64_t short_value = 0.0

      __pyx_v_short_value = 0.0;

     143:

     144:     cdef np.float64_t net_exposure

     145:     cdef np.float64_t gross_exposure

    +146:     cdef np.float64_t long_exposure = 0.0

      __pyx_v_long_exposure = 0.0;

    +147:     cdef np.float64_t short_exposure = 0.0

      __pyx_v_short_exposure = 0.0;

     148:

    +149:     cdef np.uint64_t longs_count = 0

      __pyx_v_longs_count = 0;

    +150:     cdef np.uint64_t shorts_count = 0

      __pyx_v_shorts_count = 0;

     151:

     152:     # attempt to reuse the memory of the old exposure series

    +153:     if len(old_index) < npos:

      __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_old_index)); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 153, __pyx_L1_error)
      __pyx_t_3 = (__pyx_t_1 < __pyx_v_npos);
      if (__pyx_t_3) {
    /* … */
        goto __pyx_L3;
      }

     154:         # we don't have enough space in the cached buffer, allocate a new

     155:         # array

    +156:         stats.underlying_index_array = index = np.empty(npos, dtype='int64')

        __pyx_t_4 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
          assert(__pyx_t_4);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
          __pyx_t_7 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_t_5};
          __pyx_t_8 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 156, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_int64, __pyx_t_8, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 156, __pyx_L1_error)
          __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_6, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_8);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 156, __pyx_L1_error)
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_v_stats->underlying_index_array);
        __Pyx_DECREF(__pyx_v_stats->underlying_index_array);
        __pyx_v_stats->underlying_index_array = __pyx_t_2;
        __pyx_t_9 = ((PyArrayObject *)__pyx_t_2);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            }
            __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
          }
          __pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 156, __pyx_L1_error)
        }
        __pyx_t_9 = 0;
        __Pyx_INCREF(__pyx_t_2);
        __pyx_v_index = ((PyArrayObject *)__pyx_t_2);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +157:         stats.underlying_value_array = position_exposure = np.empty(

        __pyx_t_6 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 157, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    /* … */
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 157, __pyx_L1_error)
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_v_stats->underlying_value_array);
        __Pyx_DECREF(__pyx_v_stats->underlying_value_array);
        __pyx_v_stats->underlying_value_array = __pyx_t_2;
        __pyx_t_14 = ((PyArrayObject *)__pyx_t_2);
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
            }
            __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0;
          }
          __pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 157, __pyx_L1_error)
        }
        __pyx_t_14 = 0;
        __Pyx_INCREF(__pyx_t_2);
        __pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_2);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +158:             npos,

        __pyx_t_8 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 158, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_6);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_7 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_8};
          __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_float64, __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 157, __pyx_L1_error)
          __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }

     159:             dtype='float64',

     160:         )

     161:

    +162:         stats.position_exposure_array = position_exposure

        __Pyx_INCREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_array);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_array);
        __pyx_v_stats->position_exposure_array = ((PyObject *)__pyx_v_position_exposure);

     163:         # create a new series to expose the arrays

    +164:         stats.position_exposure_series = pd.Series(

        __pyx_t_5 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 164, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_series);
        __pyx_v_stats->position_exposure_series = __pyx_t_2;
        __pyx_t_2 = 0;

     165:             position_exposure,

    +166:             index=index,

        __pyx_t_7 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_5);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_7 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, ((PyObject *)__pyx_v_position_exposure)};
          __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 164, __pyx_L1_error)
          __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }

     167:         )

    +168:     elif len(old_index) > npos:

      __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_old_index)); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 168, __pyx_L1_error)
      __pyx_t_3 = (__pyx_t_1 > __pyx_v_npos);
      if (__pyx_t_3) {
    /* … */
        goto __pyx_L3;
      }

     169:         # we have more space than needed, slice off the extra but leave it

     170:         # available

    +171:         index = old_index[:npos]

        __pyx_t_2 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 171, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_index), __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 171, __pyx_L1_error)
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            }
            __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
          }
          __pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 171, __pyx_L1_error)
        }
        __pyx_v_index = ((PyArrayObject *)__pyx_t_2);
        __pyx_t_2 = 0;

    +172:         position_exposure = old_position_exposure[:npos]

        __pyx_t_2 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_position_exposure), __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 172, __pyx_L1_error)
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
            }
            __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0;
          }
          __pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 172, __pyx_L1_error)
        }
        __pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_2);
        __pyx_t_2 = 0;

     173:

    +174:         stats.position_exposure_array = position_exposure

        __Pyx_INCREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_array);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_array);
        __pyx_v_stats->position_exposure_array = ((PyObject *)__pyx_v_position_exposure);

     175:         # create a new series with the sliced arrays

    +176:         stats.position_exposure_series = pd.Series(

        __pyx_t_8 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_series);
        __pyx_v_stats->position_exposure_series = __pyx_t_2;
        __pyx_t_2 = 0;

     177:             position_exposure,

    +178:             index=index,

        __pyx_t_7 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_8);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_7 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_8, ((PyObject *)__pyx_v_position_exposure)};
          __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 176, __pyx_L1_error)
          __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }

     179:         )

     180:     else:

     181:         # we have exactly the right amount of space, no slicing or allocation

     182:         # needed

    +183:         index = old_index

      /*else*/ {
        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_old_index), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            }
            __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
          }
          __pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 183, __pyx_L1_error)
        }
        __Pyx_INCREF((PyObject *)__pyx_v_old_index);
        __pyx_v_index = ((PyArrayObject *)__pyx_v_old_index);

    +184:         position_exposure = old_position_exposure

        {
          __Pyx_BufFmt_StackElem __pyx_stack[1];
          __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
          __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_old_position_exposure), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
          if (unlikely(__pyx_t_10 < 0)) {
            PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
            if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
              Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
              __Pyx_RaiseBufferFallbackError();
            } else {
              PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
            }
            __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0;
          }
          __pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0];
          if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 184, __pyx_L1_error)
        }
        __Pyx_INCREF((PyObject *)__pyx_v_old_position_exposure);
        __pyx_v_position_exposure = ((PyArrayObject *)__pyx_v_old_position_exposure);

     185:

    +186:         stats.position_exposure_array = position_exposure

        __Pyx_INCREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_array);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_array);
        __pyx_v_stats->position_exposure_array = ((PyObject *)__pyx_v_position_exposure);

    +187:         stats.position_exposure_series = pd.Series(

        __pyx_t_5 = NULL;
        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 187, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 187, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
        __Pyx_DECREF(__pyx_v_stats->position_exposure_series);
        __pyx_v_stats->position_exposure_series = __pyx_t_2;
        __pyx_t_2 = 0;
      }
      __pyx_L3:;

     188:             position_exposure,

    +189:             index=index,

        __pyx_t_7 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          assert(__pyx_t_5);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
          __pyx_t_7 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, ((PyObject *)__pyx_v_position_exposure)};
          __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 187, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 187, __pyx_L1_error)
          __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
        }

     190:         )

     191:

     192:     cdef InnerPosition position

    +193:     cdef Py_ssize_t ix = 0

      __pyx_v_ix = 0;

     194:

    +195:     for outer_position in positions.values():

      __pyx_t_1 = 0;
      if (unlikely(__pyx_v_positions == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values");
        __PYX_ERR(0, 195, __pyx_L1_error)
      }
      __pyx_t_8 = __Pyx_dict_iterator(__pyx_v_positions, 0, __pyx_mstate_global->__pyx_n_u_values, (&__pyx_t_15), (&__pyx_t_10)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_XDECREF(__pyx_t_2);
      __pyx_t_2 = __pyx_t_8;
      __pyx_t_8 = 0;
      while (1) {
        __pyx_t_16 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_15, &__pyx_t_1, NULL, &__pyx_t_8, NULL, __pyx_t_10);
        if (unlikely(__pyx_t_16 == 0)) break;
        if (unlikely(__pyx_t_16 == -1)) __PYX_ERR(0, 195, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_8);
        __pyx_t_8 = 0;

    +196:         position = outer_position.inner_position

        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_outer_position, __pyx_mstate_global->__pyx_n_u_inner_position); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 196, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_mstate_global->__pyx_ptype_7zipline_9_protocol_InnerPosition))))) __PYX_ERR(0, 196, __pyx_L1_error)
        __Pyx_XDECREF_SET(__pyx_v_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_8));
        __pyx_t_8 = 0;

     197:

     198:         # NOTE: this loop does a lot of stuff!

     199:         # we call this function every time the portfolio value is needed,

     200:         # which is at least once per simulation day, so let's not iterate

     201:         # through every single position multiple times.

    +202:         exposure = position.amount * position.last_sale_price

        __pyx_v_exposure = (__pyx_v_position->amount * __pyx_v_position->last_sale_price);

     203:

    +204:         if type(position.asset) is Future:

        __pyx_t_3 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_position->asset))) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_7zipline_6assets_7_assets_Future));
        if (__pyx_t_3) {
    /* … */
          goto __pyx_L6;
        }

     205:             # Futures don't have an inherent position value.

    +206:             value = 0

          __pyx_v_value = 0.0;

     207:

     208:             # unchecked cast, this is safe because we do a type check above

    +209:             exposure *= position.asset.price_multiplier

          __pyx_v_exposure = (__pyx_v_exposure * __pyx_v_position->asset->price_multiplier);

     210:         else:

    +211:             value = exposure

        /*else*/ {
          __pyx_v_value = __pyx_v_exposure;
        }
        __pyx_L6:;

     212:

    +213:         if exposure > 0:

        __pyx_t_3 = (__pyx_v_exposure > 0.0);
        if (__pyx_t_3) {
    /* … */
          goto __pyx_L7;
        }

    +214:             longs_count += 1

          __pyx_v_longs_count = (__pyx_v_longs_count + 1);

    +215:             long_value += value

          __pyx_v_long_value = (__pyx_v_long_value + __pyx_v_value);

    +216:             long_exposure += exposure

          __pyx_v_long_exposure = (__pyx_v_long_exposure + __pyx_v_exposure);

    +217:         elif exposure < 0:

        __pyx_t_3 = (__pyx_v_exposure < 0.0);
        if (__pyx_t_3) {
    /* … */
        }
        __pyx_L7:;

    +218:             shorts_count += 1

          __pyx_v_shorts_count = (__pyx_v_shorts_count + 1);

    +219:             short_value += value

          __pyx_v_short_value = (__pyx_v_short_value + __pyx_v_value);

    +220:             short_exposure += exposure

          __pyx_v_short_exposure = (__pyx_v_short_exposure + __pyx_v_exposure);

     221:

     222:         with cython.boundscheck(False), cython.wraparound(False):

    +223:             index[ix] = position.asset.sid

        __pyx_t_17 = __pyx_v_position->asset->sid;
        __pyx_t_18 = __pyx_v_ix;
        *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_index.diminfo[0].strides) = __pyx_t_17;

    +224:             position_exposure[ix] = exposure

        __pyx_t_18 = __pyx_v_ix;
        *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_position_exposure.diminfo[0].strides) = __pyx_v_exposure;

     225:

    +226:         ix += 1

        __pyx_v_ix = (__pyx_v_ix + 1);
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     227:

    +228:     net_value = long_value + short_value

      __pyx_v_net_value = (__pyx_v_long_value + __pyx_v_short_value);

    +229:     gross_value = long_value - short_value

      __pyx_v_gross_value = (__pyx_v_long_value - __pyx_v_short_value);

     230:

    +231:     net_exposure = long_exposure + short_exposure

      __pyx_v_net_exposure = (__pyx_v_long_exposure + __pyx_v_short_exposure);

    +232:     gross_exposure = long_exposure - short_exposure

      __pyx_v_gross_exposure = (__pyx_v_long_exposure - __pyx_v_short_exposure);

     233:

    +234:     stats.gross_exposure = gross_exposure

      __pyx_v_stats->gross_exposure = __pyx_v_gross_exposure;

    +235:     stats.gross_value = gross_value

      __pyx_v_stats->gross_value = __pyx_v_gross_value;

    +236:     stats.long_exposure = long_exposure

      __pyx_v_stats->long_exposure = __pyx_v_long_exposure;

    +237:     stats.long_value = long_value

      __pyx_v_stats->long_value = __pyx_v_long_value;

    +238:     stats.longs_count = longs_count

      __pyx_v_stats->longs_count = __pyx_v_longs_count;

    +239:     stats.net_exposure = net_exposure

      __pyx_v_stats->net_exposure = __pyx_v_net_exposure;

    +240:     stats.net_value = net_value

      __pyx_v_stats->net_value = __pyx_v_net_value;

    +241:     stats.short_exposure = short_exposure

      __pyx_v_stats->short_exposure = __pyx_v_short_exposure;

    +242:     stats.short_value = short_value

      __pyx_v_stats->short_value = __pyx_v_short_value;

    +243:     stats.shorts_count = shorts_count

      __pyx_v_stats->shorts_count = __pyx_v_shorts_count;

     244:

     245:

    +246: cpdef minute_annual_volatility(np.ndarray[np.int64_t] date_labels,

    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(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*/
    static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_minute_annual_volatility(PyArrayObject *__pyx_v_date_labels, PyArrayObject *__pyx_v_minute_returns, PyArrayObject *__pyx_v_daily_returns, CYTHON_UNUSED int __pyx_skip_dispatch) {
      PyArrayObject *__pyx_v_out = 0;
      __pyx_t_5numpy_int64_t __pyx_v_previous_date;
      __pyx_t_5numpy_int64_t __pyx_v_day_ix;
      __pyx_t_5numpy_float64_t __pyx_v_daily_sum;
      __pyx_t_5numpy_float64_t __pyx_v_todays_prod;
      __pyx_t_5numpy_float64_t __pyx_v_annualization_factor;
      __pyx_t_5numpy_float64_t __pyx_v_intermediate_sum;
      __pyx_t_5numpy_float64_t __pyx_v_mean;
      __pyx_t_5numpy_float64_t __pyx_v_variance;
      Py_ssize_t __pyx_v_ix;
      __pyx_t_5numpy_float64_t __pyx_v_this_minute_returns;
      PyObject *__pyx_v_date = NULL;
      PyObject *__pyx_v_demeaned_old = NULL;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_daily_returns;
      __Pyx_Buffer __pyx_pybuffer_daily_returns;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_date_labels;
      __Pyx_Buffer __pyx_pybuffer_date_labels;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_minute_returns;
      __Pyx_Buffer __pyx_pybuffer_minute_returns;
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[56]))
      __Pyx_TraceStartFunc("minute_annual_volatility", __pyx_f[0], 246, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 246, __pyx_L1_error));
      __pyx_pybuffer_date_labels.pybuffer.buf = NULL;
      __pyx_pybuffer_date_labels.refcount = 0;
      __pyx_pybuffernd_date_labels.data = NULL;
      __pyx_pybuffernd_date_labels.rcbuffer = &__pyx_pybuffer_date_labels;
      __pyx_pybuffer_minute_returns.pybuffer.buf = NULL;
      __pyx_pybuffer_minute_returns.refcount = 0;
      __pyx_pybuffernd_minute_returns.data = NULL;
      __pyx_pybuffernd_minute_returns.rcbuffer = &__pyx_pybuffer_minute_returns;
      __pyx_pybuffer_daily_returns.pybuffer.buf = NULL;
      __pyx_pybuffer_daily_returns.refcount = 0;
      __pyx_pybuffernd_daily_returns.data = NULL;
      __pyx_pybuffernd_daily_returns.rcbuffer = &__pyx_pybuffer_daily_returns;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_date_labels, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_date_labels.diminfo[0].strides = __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_date_labels.diminfo[0].shape = __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer, (PyObject*)__pyx_v_minute_returns, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_minute_returns.diminfo[0].strides = __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_minute_returns.diminfo[0].shape = __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer, (PyObject*)__pyx_v_daily_returns, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_daily_returns.diminfo[0].strides = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_daily_returns.diminfo[0].shape = __pyx_pybuffernd_daily_returns.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_daily_returns.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.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, 246, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_out);
      __Pyx_XDECREF(__pyx_v_date);
      __Pyx_XDECREF(__pyx_v_demeaned_old);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_PyMonitoring_ExitScope(0);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(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_7finance_12_finance_ext_4minute_annual_volatility, "Pre-compute the minute cumulative volatility field.\n    ");
    static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_5minute_annual_volatility = {"minute_annual_volatility", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility};
    static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(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_date_labels = 0;
      PyArrayObject *__pyx_v_minute_returns = 0;
      PyArrayObject *__pyx_v_daily_returns = 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("minute_annual_volatility (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_date_labels,&__pyx_mstate_global->__pyx_n_u_minute_returns,&__pyx_mstate_global->__pyx_n_u_daily_returns,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, 246, __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, 246, __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, 246, __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, 246, __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_annual_volatility", 0) < (0)) __PYX_ERR(0, 246, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, i); __PYX_ERR(0, 246, __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, 246, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 246, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 246, __pyx_L3_error)
        }
        __pyx_v_date_labels = ((PyArrayObject *)values[0]);
        __pyx_v_minute_returns = ((PyArrayObject *)values[1]);
        __pyx_v_daily_returns = ((PyArrayObject *)values[2]);
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 246, __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.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_date_labels), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "date_labels", 0))) __PYX_ERR(0, 246, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_minute_returns), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "minute_returns", 0))) __PYX_ERR(0, 247, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_daily_returns), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "daily_returns", 0))) __PYX_ERR(0, 248, __pyx_L1_error)
      __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_4minute_annual_volatility(__pyx_self, __pyx_v_date_labels, __pyx_v_minute_returns, __pyx_v_daily_returns);
      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_7finance_12_finance_ext_4minute_annual_volatility(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_date_labels, PyArrayObject *__pyx_v_minute_returns, PyArrayObject *__pyx_v_daily_returns) {
      __Pyx_LocalBuf_ND __pyx_pybuffernd_daily_returns;
      __Pyx_Buffer __pyx_pybuffer_daily_returns;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_date_labels;
      __Pyx_Buffer __pyx_pybuffer_date_labels;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_minute_returns;
      __Pyx_Buffer __pyx_pybuffer_minute_returns;
      PyObject *__pyx_r = NULL;
      __Pyx_TraceDeclarationsFunc
      __Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[56]))
      __Pyx_TraceStartFunc("minute_annual_volatility (wrapper)", __pyx_f[0], 246, 0, 0, 0, __PYX_ERR(0, 246, __pyx_L1_error));
      __pyx_pybuffer_date_labels.pybuffer.buf = NULL;
      __pyx_pybuffer_date_labels.refcount = 0;
      __pyx_pybuffernd_date_labels.data = NULL;
      __pyx_pybuffernd_date_labels.rcbuffer = &__pyx_pybuffer_date_labels;
      __pyx_pybuffer_minute_returns.pybuffer.buf = NULL;
      __pyx_pybuffer_minute_returns.refcount = 0;
      __pyx_pybuffernd_minute_returns.data = NULL;
      __pyx_pybuffernd_minute_returns.rcbuffer = &__pyx_pybuffer_minute_returns;
      __pyx_pybuffer_daily_returns.pybuffer.buf = NULL;
      __pyx_pybuffer_daily_returns.refcount = 0;
      __pyx_pybuffernd_daily_returns.data = NULL;
      __pyx_pybuffernd_daily_returns.rcbuffer = &__pyx_pybuffer_daily_returns;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer, (PyObject*)__pyx_v_date_labels, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_date_labels.diminfo[0].strides = __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_date_labels.diminfo[0].shape = __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer, (PyObject*)__pyx_v_minute_returns, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_minute_returns.diminfo[0].strides = __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_minute_returns.diminfo[0].shape = __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer, (PyObject*)__pyx_v_daily_returns, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 246, __pyx_L1_error)
      }
      __pyx_pybuffernd_daily_returns.diminfo[0].strides = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_daily_returns.diminfo[0].shape = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.shape[0];
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_minute_annual_volatility(__pyx_v_date_labels, __pyx_v_minute_returns, __pyx_v_daily_returns, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 246, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      { 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_daily_returns.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.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, 246, __pyx_L1_error));
      #endif
      __Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.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_7finance_12_finance_ext_5minute_annual_volatility, 0, __pyx_mstate_global->__pyx_n_u_minute_annual_volatility, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[56])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_minute_annual_volatility, __pyx_t_3) < (0)) __PYX_ERR(0, 246, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     247:                                np.ndarray[np.float64_t] minute_returns,

     248:                                np.ndarray[np.float64_t] daily_returns):

     249:     """Pre-compute the minute cumulative volatility field.

     250:     """

    +251:     cdef np.ndarray out = np.empty_like(minute_returns)

      __pyx_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_empty_like); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = 1;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        assert(__pyx_t_2);
        PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx__function);
        __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
        __pyx_t_5 = 0;
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, ((PyObject *)__pyx_v_minute_returns)};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 251, __pyx_L1_error)
      __pyx_v_out = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +252:     cdef np.int64_t previous_date = date_labels[0]

      __pyx_t_6 = 0;
      __pyx_t_7 = -1;
      if (__pyx_t_6 < 0) {
        __pyx_t_6 += __pyx_pybuffernd_date_labels.diminfo[0].shape;
        if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
      } else if (unlikely(__pyx_t_6 >= __pyx_pybuffernd_date_labels.diminfo[0].shape)) __pyx_t_7 = 0;
      if (unlikely(__pyx_t_7 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_7);
        __PYX_ERR(0, 252, __pyx_L1_error)
      }
      __pyx_v_previous_date = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_date_labels.diminfo[0].strides));

    +253:     cdef np.int64_t day_ix = 0

      __pyx_v_day_ix = 0;

    +254:     cdef np.float64_t daily_sum = 0

      __pyx_v_daily_sum = 0.0;

    +255:     cdef np.float64_t todays_prod = 1

      __pyx_v_todays_prod = 1.0;

    +256:     cdef np.float64_t annualization_factor = sqrt(252.0)

      __pyx_v_annualization_factor = sqrt(252.0);

     257:

     258:     cdef np.float64_t tmp

     259:     cdef np.float64_t intermediate_sum

     260:     cdef np.float64_t mean

     261:     cdef np.float64_t variance

     262:

     263:     cdef Py_ssize_t ix

     264:     cdef Py_ssize_t variance_ix

     265:     cdef np.int64_t date_label

     266:     cdef np.float64_t this_minute_returns

     267:

     268:

    +269:     for ix in range(len(minute_returns)):

      __pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_minute_returns)); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 269, __pyx_L1_error)
      __pyx_t_9 = __pyx_t_8;
      for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
        __pyx_v_ix = __pyx_t_10;

     270:         with cython.boundscheck(False), cython.wraparound(False):

    +271:             date = date_labels[ix]

        __pyx_t_6 = __pyx_v_ix;
        __pyx_t_1 = __Pyx_PyLong_From_npy_int64((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_date_labels.diminfo[0].strides))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 271, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_XDECREF_SET(__pyx_v_date, __pyx_t_1);
        __pyx_t_1 = 0;

    +272:             this_minute_returns = minute_returns[ix]

        __pyx_t_6 = __pyx_v_ix;
        __pyx_v_this_minute_returns = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_minute_returns.diminfo[0].strides));

     273:

    +274:         if date != previous_date:

        __pyx_t_1 = __Pyx_PyLong_From_npy_int64(__pyx_v_previous_date); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = PyObject_RichCompare(__pyx_v_date, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 274, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__pyx_t_11) {
    /* … */
        }

    +275:             previous_date = date

          __pyx_t_12 = __Pyx_PyLong_As_npy_int64(__pyx_v_date); if (unlikely((__pyx_t_12 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 275, __pyx_L1_error)
          __pyx_v_previous_date = __pyx_t_12;

    +276:             daily_sum += daily_returns[day_ix]

          __pyx_t_12 = __pyx_v_day_ix;
          __pyx_t_7 = -1;
          if (__pyx_t_12 < 0) {
            __pyx_t_12 += __pyx_pybuffernd_daily_returns.diminfo[0].shape;
            if (unlikely(__pyx_t_12 < 0)) __pyx_t_7 = 0;
          } else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_daily_returns.diminfo[0].shape)) __pyx_t_7 = 0;
          if (unlikely(__pyx_t_7 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_7);
            __PYX_ERR(0, 276, __pyx_L1_error)
          }
          __pyx_v_daily_sum = (__pyx_v_daily_sum + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_daily_returns.diminfo[0].strides)));

    +277:             day_ix += 1

          __pyx_v_day_ix = (__pyx_v_day_ix + 1);

    +278:             todays_prod = 1

          __pyx_v_todays_prod = 1.0;

     279:

    +280:         if day_ix < 1:

        __pyx_t_11 = (__pyx_v_day_ix < 1);
        if (__pyx_t_11) {
    /* … */
          goto __pyx_L6;
        }

    +281:             variance = np.nan

          __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_nan); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_13 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_13 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_v_variance = __pyx_t_13;

     282:         else:

    +283:             todays_prod *= 1 + this_minute_returns

        /*else*/ {
          __pyx_v_todays_prod = (__pyx_v_todays_prod * (1.0 + __pyx_v_this_minute_returns));

     284:

    +285:             intermediate_sum = daily_sum + todays_prod - 1

          __pyx_v_intermediate_sum = ((__pyx_v_daily_sum + __pyx_v_todays_prod) - 1.0);

    +286:             mean = intermediate_sum / (day_ix + 1)

          __pyx_t_12 = (__pyx_v_day_ix + 1);
          if (unlikely(__pyx_t_12 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 286, __pyx_L1_error)
          }
          __pyx_v_mean = (__pyx_v_intermediate_sum / ((__pyx_t_5numpy_float64_t)__pyx_t_12));

     287:

    +288:             variance = todays_prod - 1 - mean

          __pyx_v_variance = ((__pyx_v_todays_prod - 1.0) - __pyx_v_mean);

    +289:             variance *= variance  # squared

          __pyx_v_variance = (__pyx_v_variance * __pyx_v_variance);

     290:

    +291:             demeaned_old = daily_returns[:day_ix] - mean

          __pyx_t_1 = __Pyx_PyLong_From_npy_int64(__pyx_v_day_ix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_4 = PySlice_New(Py_None, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 291, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_daily_returns), __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = PyFloat_FromDouble(__pyx_v_mean); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 291, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF_SET(__pyx_v_demeaned_old, __pyx_t_2);
          __pyx_t_2 = 0;

    +292:             variance += demeaned_old.dot(demeaned_old)

          __pyx_t_2 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = __pyx_v_demeaned_old;
          __Pyx_INCREF(__pyx_t_1);
          __pyx_t_5 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_demeaned_old};
            __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_dot, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 292, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
          }
          __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_13 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_13 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_v_variance = __pyx_t_13;

     293:

    +294:             variance /= day_ix  # day_count - 1 for ddof=1

          if (unlikely(__pyx_v_day_ix == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 294, __pyx_L1_error)
          }
          __pyx_v_variance = (__pyx_v_variance / __pyx_v_day_ix);
        }
        __pyx_L6:;

     295:

     296:         with cython.boundscheck(False), cython.wraparound(False):

    +297:             out[ix] = sqrt(variance) * annualization_factor

        __pyx_t_1 = PyFloat_FromDouble((sqrt(__pyx_v_variance) * __pyx_v_annualization_factor)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_out), __pyx_v_ix, __pyx_t_1, Py_ssize_t, 1, PyLong_FromSsize_t, 0, 0, 0, 1) < 0))) __PYX_ERR(0, 297, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }

     298:

    +299:     return out

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF((PyObject *)__pyx_v_out);
      __pyx_r = ((PyObject *)__pyx_v_out);
      __Pyx_TraceReturnValue(__pyx_r, 101, 0, __PYX_ERR(0, 299, __pyx_L1_error));
      goto __pyx_L0;