Generated by Cython 0.29.35

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_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 002: from cpython cimport PyObject
 003: from libc.math cimport sqrt
 004: 
 005: cimport numpy as np
+006: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+007: import pandas as pd
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_pandas, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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, PyObject *__pyx_args, PyObject *__pyx_kwds); /*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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("update_position_last_sale_prices", 0);
  __Pyx_TraceCall("update_position_last_sale_prices", __pyx_f[0], 13, 0, __PYX_ERR(0, 13, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  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_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_TraceReturn(__pyx_r, 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, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __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 PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_positions = 0;
  PyObject *__pyx_v_get_price = 0;
  PyObject *__pyx_v_dt = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("update_position_last_sale_prices (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_positions,&__pyx_n_s_get_price,&__pyx_n_s_dt,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_get_price)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, 1); __PYX_ERR(0, 13, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dt)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, 2); __PYX_ERR(0, 13, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "update_position_last_sale_prices") < 0)) __PYX_ERR(0, 13, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_positions = values[0];
    __pyx_v_get_price = values[1];
    __pyx_v_dt = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 13, __pyx_L3_error)
  __pyx_L3_error:;
  __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 */
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("update_position_last_sale_prices", 0);
  __Pyx_TraceCall("update_position_last_sale_prices (wrapper)", __pyx_f[0], 13, 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, 0); 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_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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 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_n_s_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_n_s_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_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_INCREF(__pyx_v_get_price);
    __pyx_t_7 = __pyx_v_get_price; __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, ((PyObject *)__pyx_v_inner_position->asset)) : __Pyx_PyObject_CallOneArg(__pyx_t_7, ((PyObject *)__pyx_v_inner_position->asset));
    __Pyx_XDECREF(__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_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_9 == ((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_9;
 032: 
 033:         # inline ~isnan because this gets called once per position per minute
+034:         if last_sale_price == last_sale_price:
    __pyx_t_10 = ((__pyx_v_last_sale_price == __pyx_v_last_sale_price) != 0);
    if (__pyx_t_10) {
/* … */
    }
  }
  __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
+040: cdef class PositionStats:
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;
};


 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 84, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 85, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 86, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 87, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 88, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 89, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 90, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 91, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 92, 0, __PYX_ERR(0, 92, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 93, 0, __PYX_ERR(0, 93, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 94, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __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_TraceReturn(__pyx_r, 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) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 95, 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;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __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_TraceReturn(__pyx_r, 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
  __pyx_t_2 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats->tp_dict, __pyx_n_s_new_2, __pyx_t_2) < 0) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats);
+103:     def new(cls):
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("new (wrapper)", 0);
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("new", 0);
  __Pyx_TraceCall("new", __pyx_f[0], 103, 0, __PYX_ERR(0, 103, __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_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_n_s_new_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
+104:         cdef PositionStats self = cls()
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_v_cls)); 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_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_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Series); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* … */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
/* … */
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __Pyx_GOTREF(__pyx_v_self->position_exposure_series);
  __Pyx_DECREF(__pyx_v_self->position_exposure_series);
  __pyx_v_self->position_exposure_series = __pyx_t_7;
  __Pyx_INCREF(__pyx_t_7);
  __pyx_v_es = __pyx_t_7;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+106:             np.array([], dtype='float64'),
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_n_u_float64) < 0) __PYX_ERR(0, 106, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+107:             index=np.array([], dtype='int64'),
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_n_u_int64) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_index, __pyx_t_7) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 108:         )
+109:         self.underlying_value_array = self.position_exposure_array = es.values
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_es, __pyx_n_s_values); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __Pyx_GOTREF(__pyx_v_self->underlying_value_array);
  __Pyx_DECREF(__pyx_v_self->underlying_value_array);
  __pyx_v_self->underlying_value_array = __pyx_t_7;
  __Pyx_INCREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __Pyx_GOTREF(__pyx_v_self->position_exposure_array);
  __Pyx_DECREF(__pyx_v_self->position_exposure_array);
  __pyx_v_self->position_exposure_array = __pyx_t_7;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+110:         self.underlying_index_array = es.index.values
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_es, __pyx_n_s_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 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);
  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, PyObject *__pyx_args, PyObject *__pyx_kwds); /*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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_position_tracker_stats", 0);
  __Pyx_TraceCall("calculate_position_tracker_stats", __pyx_f[0], 114, 0, __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);
  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);
  { 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_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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __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 PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_positions = 0;
  struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_position_tracker_stats (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_positions,&__pyx_n_s_stats,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stats)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, 1); __PYX_ERR(0, 114, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calculate_position_tracker_stats") < 0)) __PYX_ERR(0, 114, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_positions = values[0];
    __pyx_v_stats = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 114, __pyx_L3_error)
  __pyx_L3_error:;
  __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_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;
  __pyx_L0:;
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_position_tracker_stats", 0);
  __Pyx_TraceCall("calculate_position_tracker_stats (wrapper)", __pyx_f[0], 114, 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, 0); 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_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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 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
  if (!(likely(((__pyx_v_stats->underlying_index_array) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_stats->underlying_index_array, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 131, __pyx_L1_error)
  __pyx_t_2 = __pyx_v_stats->underlying_index_array;
  __Pyx_INCREF(__pyx_t_2);
  {
    __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
  if (!(likely(((__pyx_v_stats->underlying_value_array) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_stats->underlying_value_array, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 133, __pyx_L1_error)
  __pyx_t_2 = __pyx_v_stats->underlying_value_array;
  __Pyx_INCREF(__pyx_t_2);
  {
    __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) != 0);
  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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_n_u_int64) < 0) __PYX_ERR(0, 156, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_GOTREF(__pyx_v_stats->underlying_index_array);
    __Pyx_DECREF(__pyx_v_stats->underlying_index_array);
    __pyx_v_stats->underlying_index_array = __pyx_t_6;
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        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_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
        __pyx_t_9 = __pyx_t_10 = __pyx_t_11 = 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_8 < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
    }
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_t_6);
    __pyx_v_index = ((PyArrayObject *)__pyx_t_6);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+157:         stats.underlying_value_array = position_exposure = np.empty(
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
/* … */
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __pyx_t_6 = 0;
/* … */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_v_stats->underlying_value_array);
    __Pyx_DECREF(__pyx_v_stats->underlying_value_array);
    __pyx_v_stats->underlying_value_array = __pyx_t_4;
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        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_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
        __pyx_t_11 = __pyx_t_10 = __pyx_t_9 = 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_8 < 0)) __PYX_ERR(0, 157, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+158:             npos,
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
+159:             dtype='float64',
    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_n_u_float64) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_Series); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* … */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_v_position_exposure));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_position_exposure));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_position_exposure));
/* … */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_index, ((PyObject *)__pyx_v_index)) < 0) __PYX_ERR(0, 166, __pyx_L1_error)
 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) != 0);
  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 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_index), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 171, __pyx_L1_error)
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        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_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
        __pyx_t_9 = __pyx_t_10 = __pyx_t_11 = 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_8 < 0)) __PYX_ERR(0, 171, __pyx_L1_error)
    }
    __pyx_t_7 = 0;
    __pyx_v_index = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;
+172:         position_exposure = old_position_exposure[:npos]
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_position_exposure), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 172, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        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_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
        __pyx_t_11 = __pyx_t_10 = __pyx_t_9 = 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_8 < 0)) __PYX_ERR(0, 172, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Series); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* … */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_position_exposure));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_position_exposure));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_position_exposure));
/* … */
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
    __Pyx_DECREF(__pyx_v_stats->position_exposure_series);
    __pyx_v_stats->position_exposure_series = __pyx_t_6;
    __pyx_t_6 = 0;
 177:             position_exposure,
+178:             index=index,
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_index, ((PyObject *)__pyx_v_index)) < 0) __PYX_ERR(0, 178, __pyx_L1_error)
 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_8 = __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_8 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        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_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
        __pyx_t_9 = __pyx_t_10 = __pyx_t_11 = 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_8 < 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_8 = __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_8 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        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_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
        __pyx_t_11 = __pyx_t_10 = __pyx_t_9 = 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_8 < 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_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pd); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Series); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
/* … */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(((PyObject *)__pyx_v_position_exposure));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_position_exposure));
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_position_exposure));
/* … */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
    __Pyx_DECREF(__pyx_v_stats->position_exposure_series);
    __pyx_v_stats->position_exposure_series = __pyx_t_5;
    __pyx_t_5 = 0;
  }
  __pyx_L3:;
 188:             position_exposure,
+189:             index=index,
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_index, ((PyObject *)__pyx_v_index)) < 0) __PYX_ERR(0, 189, __pyx_L1_error)
 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_2 = __Pyx_dict_iterator(__pyx_v_positions, 0, __pyx_n_s_values, (&__pyx_t_13), (&__pyx_t_8)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __pyx_t_5 = __pyx_t_2;
  __pyx_t_2 = 0;
  while (1) {
    __pyx_t_14 = __Pyx_dict_iter_next(__pyx_t_5, __pyx_t_13, &__pyx_t_1, NULL, &__pyx_t_2, NULL, __pyx_t_8);
    if (unlikely(__pyx_t_14 == 0)) break;
    if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_2);
    __pyx_t_2 = 0;
+196:         position = outer_position.inner_position
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_outer_position, __pyx_n_s_inner_position); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __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_2));
    __pyx_t_2 = 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_ptype_7zipline_6assets_7_assets_Future));
    __pyx_t_15 = (__pyx_t_3 != 0);
    if (__pyx_t_15) {
/* … */
      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_15 = ((__pyx_v_exposure > 0.0) != 0);
    if (__pyx_t_15) {
/* … */
      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_15 = ((__pyx_v_exposure < 0.0) != 0);
    if (__pyx_t_15) {
/* … */
    }
    __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_16 = __pyx_v_position->asset->sid;
    __pyx_t_17 = __pyx_v_ix;
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_index.diminfo[0].strides) = __pyx_t_16;
+224:             position_exposure[ix] = exposure
    __pyx_t_17 = __pyx_v_ix;
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.buf, __pyx_t_17, __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_5); __pyx_t_5 = 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, PyObject *__pyx_args, PyObject *__pyx_kwds); /*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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minute_annual_volatility", 0);
  __Pyx_TraceCall("minute_annual_volatility", __pyx_f[0], 246, 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];
/* … */
  /* 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_12);
  { 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_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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility[] = "Pre-compute the minute cumulative volatility field.\n    ";
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_date_labels = 0;
  PyArrayObject *__pyx_v_minute_returns = 0;
  PyArrayObject *__pyx_v_daily_returns = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minute_annual_volatility (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_date_labels,&__pyx_n_s_minute_returns,&__pyx_n_s_daily_returns,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_date_labels)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minute_returns)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, 1); __PYX_ERR(0, 246, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_daily_returns)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, 2); __PYX_ERR(0, 246, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "minute_annual_volatility") < 0)) __PYX_ERR(0, 246, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_date_labels = ((PyArrayObject *)values[0]);
    __pyx_v_minute_returns = ((PyArrayObject *)values[1]);
    __pyx_v_daily_returns = ((PyArrayObject *)values[2]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 246, __pyx_L3_error)
  __pyx_L3_error:;
  __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_ptype_5numpy_ndarray, 1, "date_labels", 0))) __PYX_ERR(0, 246, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_minute_returns), __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_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;
  __pyx_L0:;
  __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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minute_annual_volatility", 0);
  __Pyx_TraceCall("minute_annual_volatility (wrapper)", __pyx_f[0], 246, 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, 0); 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_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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 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_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty_like); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, ((PyObject *)__pyx_v_minute_returns)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_minute_returns));
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __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_4 = 0;
  __pyx_t_5 = -1;
  if (__pyx_t_4 < 0) {
    __pyx_t_4 += __pyx_pybuffernd_date_labels.diminfo[0].shape;
    if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0;
  } else if (unlikely(__pyx_t_4 >= __pyx_pybuffernd_date_labels.diminfo[0].shape)) __pyx_t_5 = 0;
  if (unlikely(__pyx_t_5 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_5);
    __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_4, __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_6 = PyObject_Length(((PyObject *)__pyx_v_minute_returns)); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 269, __pyx_L1_error)
  __pyx_t_7 = __pyx_t_6;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_ix = __pyx_t_8;
 270:         with cython.boundscheck(False), cython.wraparound(False):
+271:             date = date_labels[ix]
    __pyx_t_4 = __pyx_v_ix;
    __pyx_t_1 = __Pyx_PyInt_From_npy_int64((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_4, __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_4 = __pyx_v_ix;
    __pyx_v_this_minute_returns = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_minute_returns.diminfo[0].strides));
 273: 
+274:         if date != previous_date:
    __pyx_t_1 = __Pyx_PyInt_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_3 = PyObject_RichCompare(__pyx_v_date, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 274, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_9) {
/* … */
    }
+275:             previous_date = date
      __pyx_t_10 = __Pyx_PyInt_As_npy_int64(__pyx_v_date); if (unlikely((__pyx_t_10 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 275, __pyx_L1_error)
      __pyx_v_previous_date = __pyx_t_10;
+276:             daily_sum += daily_returns[day_ix]
      __pyx_t_10 = __pyx_v_day_ix;
      __pyx_t_5 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_pybuffernd_daily_returns.diminfo[0].shape;
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_5 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_pybuffernd_daily_returns.diminfo[0].shape)) __pyx_t_5 = 0;
      if (unlikely(__pyx_t_5 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_5);
        __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_10, __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_9 = ((__pyx_v_day_ix < 1) != 0);
    if (__pyx_t_9) {
/* … */
      goto __pyx_L6;
    }
+281:             variance = np.nan
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_nan); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_11 == ((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_11;
 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_10 = (__pyx_v_day_ix + 1);
      if (unlikely(__pyx_t_10 == 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_10));
 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_PyInt_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_3 = PySlice_New(Py_None, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_daily_returns), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyFloat_FromDouble(__pyx_v_mean); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_3); 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_3); __pyx_t_3 = 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_PyObject_GetAttrStr(__pyx_v_demeaned_old, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_12, __pyx_v_demeaned_old) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_demeaned_old);
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_3); 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_3); __pyx_t_3 = 0;
      __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_11 == ((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_11;
 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, PyInt_FromSsize_t, 0, 0, 0) < 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);
  goto __pyx_L0;