Generated by Cython 3.0.12
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: _finance_ext.c
+001: cimport cython
__pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
002: from cpython cimport PyObject
003: from libc.math cimport sqrt
004:
005: cimport numpy as np
+006: import numpy as np
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+007: import pandas as pd
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_pandas, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
008:
009: from zipline._protocol cimport InnerPosition
010: from zipline.assets._assets cimport Future
011:
012:
+013: cpdef update_position_last_sale_prices(positions, get_price, dt):
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt, CYTHON_UNUSED int __pyx_skip_dispatch) { struct __pyx_obj_7zipline_9_protocol_InnerPosition *__pyx_v_inner_position = 0; __pyx_t_5numpy_float64_t __pyx_v_last_sale_price; __pyx_t_5numpy_float64_t __pyx_v_last_open_price; PyObject *__pyx_v_outer_position = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceFrameInit(__pyx_codeobj__3) __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, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_update_position_last_sale_prices, "Update the positions' last sale prices.\n\n Parameters\n ----------\n positions : OrderedDict\n The positions to update.\n get_price : callable[Asset, float]\n The function to retrieve the price for the asset.\n dt : pd.Timestamp\n The dt to set as the last sale date if the price is not nan.\n "); static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices = {"update_position_last_sale_prices", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_update_position_last_sale_prices}; static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_positions = 0; PyObject *__pyx_v_get_price = 0; PyObject *__pyx_v_dt = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("update_position_last_sale_prices (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_positions,&__pyx_n_s_get_price,&__pyx_n_s_dt,0}; PyObject* values[3] = {0,0,0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_positions)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_get_price)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) 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_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_dt)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, 2); __PYX_ERR(0, 13, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "update_position_last_sale_prices") < 0)) __PYX_ERR(0, 13, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 3)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); } __pyx_v_positions = values[0]; __pyx_v_get_price = values[1]; __pyx_v_dt = values[2]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 13, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(__pyx_self, __pyx_v_positions, __pyx_v_get_price, __pyx_v_dt); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceFrameInit(__pyx_codeobj__3) __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; } /* … */ __pyx_tuple__13 = PyTuple_Pack(3, __pyx_n_s_positions, __pyx_n_s_get_price, __pyx_n_s_dt); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13); /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, 0, __pyx_n_s_update_position_last_sale_prices, NULL, __pyx_n_s_zipline_finance__finance_ext, __pyx_d, ((PyObject *)__pyx_codeobj__3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_update_position_last_sale_prices, __pyx_t_2) < 0) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_finance__finance_ext, __pyx_n_s_update_position_last_sale_prices, 13, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) __PYX_ERR(0, 13, __pyx_L1_error)
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: cdef np.float64_t last_open_price
028:
+029: 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, 29, __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, 29, __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, 29, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_5); __pyx_t_5 = 0;
+030: 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, 30, __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, 30, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_inner_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_5)); __pyx_t_5 = 0;
031:
+032: 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; __pyx_t_9 = 0; #if CYTHON_UNPACK_METHODS if (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_9 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_8, ((PyObject *)__pyx_v_inner_position->asset)}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_10 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_last_sale_price = __pyx_t_10;
033: # !346 #113 for current bar backtesting
034: # In order to calculate the initial value of stock positions considering
035: # `ex-rights`, an opening price field(`last_open_price`) needs to be added
036: # to the class `Position`.
+037: last_open_price = get_price(inner_position.asset, field='open_price')
__pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF((PyObject *)__pyx_v_inner_position->asset); __Pyx_GIVEREF((PyObject *)__pyx_v_inner_position->asset); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_inner_position->asset))) __PYX_ERR(0, 37, __pyx_L1_error); __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_field, __pyx_n_u_open_price) < 0) __PYX_ERR(0, 37, __pyx_L1_error) __pyx_t_8 = __Pyx_PyObject_Call(__pyx_v_get_price, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_10 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_last_open_price = __pyx_t_10;
038:
039: # inline ~isnan because this gets called once per position per minute
+040: if last_sale_price == last_sale_price:
__pyx_t_11 = (__pyx_v_last_sale_price == __pyx_v_last_sale_price); if (__pyx_t_11) { /* … */ }
+041: inner_position.last_sale_price = last_sale_price
__pyx_v_inner_position->last_sale_price = __pyx_v_last_sale_price;
+042: 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;
043:
044: # !346 #113 for current bar backtesting
+045: if last_open_price == last_open_price:
__pyx_t_11 = (__pyx_v_last_open_price == __pyx_v_last_open_price);
if (__pyx_t_11) {
/* … */
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+046: inner_position.last_open_price = last_open_price
__pyx_v_inner_position->last_open_price = __pyx_v_last_open_price;
047:
048:
049: @cython.final
+050: 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 start_long_value; __pyx_t_5numpy_float64_t net_exposure; __pyx_t_5numpy_float64_t net_value; __pyx_t_5numpy_float64_t start_net_value; __pyx_t_5numpy_float64_t short_exposure; __pyx_t_5numpy_float64_t short_value; __pyx_t_5numpy_float64_t start_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; };
051: """Computed values from the current positions.
052:
053: Attributes
054: ----------
055: gross_exposure : float64
056: The gross position exposure.
057: gross_value : float64
058: The gross position value.
059: long_exposure : float64
060: The exposure of just the long positions.
061: long_value : float64
062: The value of just the long positions.
063: net_exposure : float64
064: The net position exposure.
065: net_value : float64
066: The net position value.
067: short_exposure : float64
068: The exposure of just the short positions.
069: short_value : float64
070: The value of just the short positions.
071: longs_count : int64
072: The number of long positions.
073: shorts_count : int64
074: The number of short positions.
075: position_exposure_array : np.ndarray[float64]
076: The exposure of each position in the same order as
077: ``position_tracker.positions``.
078: position_exposure_series : pd.Series[float64]
079: The exposure of each position in the same order as
080: ``position_tracker.positions``. The index is the numeric sid of each
081: asset.
082:
083: Notes
084: -----
085: ``position_exposure_array`` and ``position_exposure_series`` share the same
086: underlying memory. The array interface should be preferred if you are doing
087: access each minute for better performance.
088:
089: ``position_exposure_array`` and ``position_exposure_series`` may be mutated
090: when the position tracker next updates the stats. Do not rely on these
091: objects being preserved across accesses to ``stats``. If you need to freeze
092: the values, you must take a copy.
093: """
+094: cdef readonly np.float64_t gross_exposure
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 94, 0, __PYX_ERR(0, 94, __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, 94, __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; }
+095: cdef readonly np.float64_t gross_value
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 95, 0, __PYX_ERR(0, 95, __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, 95, __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; }
+096: cdef readonly np.float64_t long_exposure
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 96, 0, __PYX_ERR(0, 96, __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, 96, __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; }
+097: cdef readonly np.float64_t long_value
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 97, 0, __PYX_ERR(0, 97, __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, 97, __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; }
+098: cdef readonly np.float64_t start_long_value # !346 #113 for current bar backtesting
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_16start_long_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_16start_long_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_16start_long_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_16start_long_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 98, 0, __PYX_ERR(0, 98, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->start_long_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __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.start_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; }
+099: cdef readonly np.float64_t net_exposure
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 99, 0, __PYX_ERR(0, 99, __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, 99, __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; }
+100: cdef readonly np.float64_t net_value
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 100, 0, __PYX_ERR(0, 100, __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, 100, __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; }
+101: cdef readonly np.float64_t start_net_value # !346 #113 for current bar backtesting
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_15start_net_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_15start_net_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_15start_net_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_15start_net_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 101, 0, __PYX_ERR(0, 101, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->start_net_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __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.start_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; }
+102: cdef readonly np.float64_t short_exposure
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 102, 0, __PYX_ERR(0, 102, __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, 102, __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; }
+103: cdef readonly np.float64_t short_value
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 103, 0, __PYX_ERR(0, 103, __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, 103, __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; }
+104: cdef readonly np.float64_t start_short_value # !346 #113 for current bar backtesting
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_17start_short_value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_17start_short_value_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_17start_short_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_17start_short_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 104, 0, __PYX_ERR(0, 104, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->start_short_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __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.start_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; }
+105: cdef readonly np.uint64_t longs_count
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 105, 0, __PYX_ERR(0, 105, __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, 105, __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; }
+106: cdef readonly np.uint64_t shorts_count
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 106, 0, __PYX_ERR(0, 106, __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, 106, __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; }
+107: cdef readonly object position_exposure_array
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 107, 0, __PYX_ERR(0, 107, __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; }
+108: cdef readonly object position_exposure_series
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceCall("__get__", __pyx_f[0], 108, 0, __PYX_ERR(0, 108, __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; }
109:
110: # These are the same memory exposed through ``position_exposure_array``
111: # and ``position_exposure_series``. These are hidden from Python.
112: cdef object underlying_value_array
113: cdef object underlying_index_array
114:
+115: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new = {"new", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("new (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("new", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "new", 0))) return NULL; __pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(((PyTypeObject*)__pyx_v_cls)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(PyTypeObject *__pyx_v_cls) { struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self = 0; PyObject *__pyx_v_es = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceFrameInit(__pyx_codeobj__4) __Pyx_TraceCall("new", __pyx_f[0], 115, 0, __PYX_ERR(0, 115, __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_tuple__14 = PyTuple_Pack(3, __pyx_n_s_cls, __pyx_n_s_self, __pyx_n_s_es); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_PositionStats_new, NULL, __pyx_n_s_zipline_finance__finance_ext, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_n_s_new_2, __pyx_t_2) < 0) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats); __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_n_s_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_n_s_new_2, __pyx_t_3) < 0) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats); __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_finance__finance_ext, __pyx_n_s_new_2, 115, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 115, __pyx_L1_error)
116: def new(cls):
+117: cdef PositionStats self = cls()
__pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_v_cls)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __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, 117, __pyx_L1_error) __pyx_v_self = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_t_1); __pyx_t_1 = 0;
+118: self.position_exposure_series = es = pd.Series(
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __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, 118, __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, 118, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_5); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5)) __PYX_ERR(0, 118, __pyx_L1_error); __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, 118, __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;
+119: np.array([], dtype='float64'),
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __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, 119, __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, 119, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 119, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __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, 119, __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, 119, __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;
+120: index=np.array([], dtype='int64'),
__pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 120, __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, 120, __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, 120, __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, 120, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 120, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4)) __PYX_ERR(0, 120, __pyx_L1_error); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 120, __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, 120, __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, 120, __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, 120, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
121: )
+122: 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, 122, __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;
+123: 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, 123, __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, 123, __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;
+124: return self
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_self); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0;
125:
126:
+127: cpdef calculate_position_tracker_stats(positions, PositionStats stats):
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_calculate_position_tracker_stats(PyObject *__pyx_v_positions, struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats, CYTHON_UNUSED int __pyx_skip_dispatch) { Py_ssize_t __pyx_v_npos; PyArrayObject *__pyx_v_index = 0; PyArrayObject *__pyx_v_position_exposure = 0; PyArrayObject *__pyx_v_old_index = 0; PyArrayObject *__pyx_v_old_position_exposure = 0; __pyx_t_5numpy_float64_t __pyx_v_value; __pyx_t_5numpy_float64_t __pyx_v_exposure; __pyx_t_5numpy_float64_t __pyx_v_start_value; __pyx_t_5numpy_float64_t __pyx_v_net_value; __pyx_t_5numpy_float64_t __pyx_v_start_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_start_long_value; __pyx_t_5numpy_float64_t __pyx_v_short_value; __pyx_t_5numpy_float64_t __pyx_v_start_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_TraceFrameInit(__pyx_codeobj__7) __Pyx_TraceCall("calculate_position_tracker_stats", __pyx_f[0], 127, 0, __PYX_ERR(0, 127, __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, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats, "Calculate various stats about the current positions.\n\n Parameters\n ----------\n positions : OrderedDict\n The ordered dictionary of positions.\n\n Returns\n -------\n position_stats : PositionStats\n The computed statistics.\n "); static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats = {"calculate_position_tracker_stats", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats}; static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_positions = 0; struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("calculate_position_tracker_stats (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_positions,&__pyx_n_s_stats,0}; PyObject* values[2] = {0,0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_positions)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 127, __pyx_L3_error) else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stats)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 127, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, 1); __PYX_ERR(0, 127, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_position_tracker_stats") < 0)) __PYX_ERR(0, 127, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 2)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); } __pyx_v_positions = values[0]; __pyx_v_stats = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)values[1]); } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 127, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stats), __pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, 1, "stats", 0))) __PYX_ERR(0, 127, __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:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __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_TraceFrameInit(__pyx_codeobj__7) __Pyx_TraceCall("calculate_position_tracker_stats (wrapper)", __pyx_f[0], 127, 0, __PYX_ERR(0, 127, __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, 127, __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; } /* … */ __pyx_tuple__17 = PyTuple_Pack(2, __pyx_n_s_positions, __pyx_n_s_stats); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__17); __Pyx_GIVEREF(__pyx_tuple__17); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, 0, __pyx_n_s_calculate_position_tracker_stats, NULL, __pyx_n_s_zipline_finance__finance_ext, __pyx_d, ((PyObject *)__pyx_codeobj__7)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_position_tracker_stats, __pyx_t_3) < 0) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_finance__finance_ext, __pyx_n_s_calculate_position_tracker_stats, 127, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 127, __pyx_L1_error)
128: """Calculate various stats about the current positions.
129:
130: Parameters
131: ----------
132: positions : OrderedDict
133: The ordered dictionary of positions.
134:
135: Returns
136: -------
137: position_stats : PositionStats
138: The computed statistics.
139: """
+140: 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, 140, __pyx_L1_error) __pyx_v_npos = __pyx_t_1;
141: cdef np.ndarray[np.int64_t] index
142: cdef np.ndarray[np.float64_t] position_exposure
143:
+144: 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, 144, __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, 144, __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;
145: cdef np.ndarray[np.float64_t] old_position_exposure = (
+146: 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, 146, __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, 145, __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;
147: )
148:
149: cdef np.float64_t value
150: cdef np.float64_t exposure
151: cdef np.float64_t start_value
152:
153: cdef np.float64_t net_value
154: cdef np.float64_t start_net_value # !346 #113 for current bar backtesting
155: cdef np.float64_t gross_value
+156: cdef np.float64_t long_value = 0.0
__pyx_v_long_value = 0.0;
+157: cdef np.float64_t start_long_value = 0.0 # !346 #113 for current bar backtesting
__pyx_v_start_long_value = 0.0;
+158: cdef np.float64_t short_value = 0.0
__pyx_v_short_value = 0.0;
+159: cdef np.float64_t start_short_value = 0.0 # !346 #113 for current bar backtesting
__pyx_v_start_short_value = 0.0;
160:
161: cdef np.float64_t net_exposure
162: cdef np.float64_t gross_exposure
+163: cdef np.float64_t long_exposure = 0.0
__pyx_v_long_exposure = 0.0;
+164: cdef np.float64_t short_exposure = 0.0
__pyx_v_short_exposure = 0.0;
165:
+166: cdef np.uint64_t longs_count = 0
__pyx_v_longs_count = 0;
+167: cdef np.uint64_t shorts_count = 0
__pyx_v_shorts_count = 0;
168:
169: # attempt to reuse the memory of the old exposure series
+170: 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, 170, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 < __pyx_v_npos); if (__pyx_t_3) { /* … */ goto __pyx_L3; }
171: # we don't have enough space in the cached buffer, allocate a new
172: # array
+173: 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, 173, __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, 173, __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, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2)) __PYX_ERR(0, 173, __pyx_L1_error); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __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, 173, __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, 173, __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, 173, __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, 173, __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;
+174: 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, 174, __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, 174, __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, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_6); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6)) __PYX_ERR(0, 174, __pyx_L1_error); __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, 174, __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, 174, __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, 174, __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;
+175: npos,
__pyx_t_6 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6);
+176: dtype='float64',
__pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 176, __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, 176, __pyx_L1_error)
177: )
178:
+179: 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);
180: # create a new series to expose the arrays
+181: stats.position_exposure_series = pd.Series(
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 181, __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, 181, __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, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF((PyObject *)__pyx_v_position_exposure); __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_position_exposure))) __PYX_ERR(0, 181, __pyx_L1_error); /* … */ __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __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;
182: position_exposure,
+183: index=index,
__pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 183, __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, 183, __pyx_L1_error)
184: )
+185: 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, 185, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 > __pyx_v_npos); if (__pyx_t_3) { /* … */ goto __pyx_L3; }
186: # we have more space than needed, slice off the extra but leave it
187: # available
+188: index = old_index[:npos]
__pyx_t_2 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __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, 188, __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, 188, __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, 188, __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, 188, __pyx_L1_error) } __pyx_t_7 = 0; __pyx_v_index = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+189: position_exposure = old_position_exposure[:npos]
__pyx_t_2 = PyInt_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __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, 189, __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, 189, __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, 189, __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, 189, __pyx_L1_error) } __pyx_t_12 = 0; __pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
190:
+191: 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);
192: # create a new series with the sliced arrays
+193: stats.position_exposure_series = pd.Series(
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __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, 193, __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, 193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF((PyObject *)__pyx_v_position_exposure); __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_position_exposure))) __PYX_ERR(0, 193, __pyx_L1_error); /* … */ __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 193, __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;
194: position_exposure,
+195: index=index,
__pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __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, 195, __pyx_L1_error)
196: )
197: else:
198: # we have exactly the right amount of space, no slicing or allocation
199: # needed
+200: 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, 200, __pyx_L1_error) } __Pyx_INCREF((PyObject *)__pyx_v_old_index); __pyx_v_index = ((PyArrayObject *)__pyx_v_old_index);
+201: 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, 201, __pyx_L1_error) } __Pyx_INCREF((PyObject *)__pyx_v_old_position_exposure); __pyx_v_position_exposure = ((PyArrayObject *)__pyx_v_old_position_exposure);
202:
+203: 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);
+204: stats.position_exposure_series = pd.Series(
__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pd); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __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, 204, __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, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF((PyObject *)__pyx_v_position_exposure); __Pyx_GIVEREF((PyObject *)__pyx_v_position_exposure); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_position_exposure))) __PYX_ERR(0, 204, __pyx_L1_error); /* … */ __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 204, __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:;
205: position_exposure,
+206: index=index,
__pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 206, __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, 206, __pyx_L1_error)
207: )
208:
209: cdef InnerPosition position
+210: cdef Py_ssize_t ix = 0
__pyx_v_ix = 0;
211:
+212: 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, 212, __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, 212, __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, 212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_2); __pyx_t_2 = 0;
+213: 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, 213, __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, 213, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_2)); __pyx_t_2 = 0;
214:
215: # NOTE: this loop does a lot of stuff!
216: # we call this function every time the portfolio value is needed,
217: # which is at least once per simulation day, so let's not iterate
218: # through every single position multiple times.
+219: exposure = position.amount * position.last_sale_price
__pyx_v_exposure = (__pyx_v_position->amount * __pyx_v_position->last_sale_price);
220:
+221: 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)); if (__pyx_t_3) { /* … */ goto __pyx_L6; }
222: # Futures don't have an inherent position value.
+223: value = 0
__pyx_v_value = 0.0;
224:
225: # unchecked cast, this is safe because we do a type check above
+226: exposure *= position.asset.price_multiplier
__pyx_v_exposure = (__pyx_v_exposure * __pyx_v_position->asset->price_multiplier);
227: else:
+228: value = exposure
/*else*/ { __pyx_v_value = __pyx_v_exposure; } __pyx_L6:;
229:
+230: if exposure > 0:
__pyx_t_3 = (__pyx_v_exposure > 0.0); if (__pyx_t_3) { /* … */ goto __pyx_L7; }
+231: longs_count += 1
__pyx_v_longs_count = (__pyx_v_longs_count + 1);
+232: long_value += value
__pyx_v_long_value = (__pyx_v_long_value + __pyx_v_value);
+233: long_exposure += exposure
__pyx_v_long_exposure = (__pyx_v_long_exposure + __pyx_v_exposure);
+234: elif exposure < 0:
__pyx_t_3 = (__pyx_v_exposure < 0.0); if (__pyx_t_3) { /* … */ } __pyx_L7:;
+235: shorts_count += 1
__pyx_v_shorts_count = (__pyx_v_shorts_count + 1);
+236: short_value += value
__pyx_v_short_value = (__pyx_v_short_value + __pyx_v_value);
+237: short_exposure += exposure
__pyx_v_short_exposure = (__pyx_v_short_exposure + __pyx_v_exposure);
238:
239: # !346 #113 for current bar backtesting
+240: start_value = position.amount * position.last_open_price
__pyx_v_start_value = (__pyx_v_position->amount * __pyx_v_position->last_open_price);
241:
+242: if start_value > 0:
__pyx_t_3 = (__pyx_v_start_value > 0.0); if (__pyx_t_3) { /* … */ goto __pyx_L8; }
+243: start_long_value += start_value
__pyx_v_start_long_value = (__pyx_v_start_long_value + __pyx_v_start_value);
+244: elif start_value < 0:
__pyx_t_3 = (__pyx_v_start_value < 0.0); if (__pyx_t_3) { /* … */ } __pyx_L8:;
+245: start_short_value += start_value
__pyx_v_start_short_value = (__pyx_v_start_short_value + __pyx_v_start_value);
246:
247: with cython.boundscheck(False), cython.wraparound(False):
+248: index[ix] = position.asset.sid
__pyx_t_15 = __pyx_v_position->asset->sid; __pyx_t_16 = __pyx_v_ix; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_index.diminfo[0].strides) = __pyx_t_15;
+249: position_exposure[ix] = exposure
__pyx_t_16 = __pyx_v_ix; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_position_exposure.diminfo[0].strides) = __pyx_v_exposure;
250:
+251: ix += 1
__pyx_v_ix = (__pyx_v_ix + 1);
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
252:
+253: net_value = long_value + short_value
__pyx_v_net_value = (__pyx_v_long_value + __pyx_v_short_value);
254:
255: # !346 #113 for current bar backtesting
+256: start_net_value = start_long_value + start_short_value
__pyx_v_start_net_value = (__pyx_v_start_long_value + __pyx_v_start_short_value);
257:
+258: gross_value = long_value - short_value
__pyx_v_gross_value = (__pyx_v_long_value - __pyx_v_short_value);
259:
+260: net_exposure = long_exposure + short_exposure
__pyx_v_net_exposure = (__pyx_v_long_exposure + __pyx_v_short_exposure);
+261: gross_exposure = long_exposure - short_exposure
__pyx_v_gross_exposure = (__pyx_v_long_exposure - __pyx_v_short_exposure);
262:
+263: stats.gross_exposure = gross_exposure
__pyx_v_stats->gross_exposure = __pyx_v_gross_exposure;
+264: stats.gross_value = gross_value
__pyx_v_stats->gross_value = __pyx_v_gross_value;
+265: stats.long_exposure = long_exposure
__pyx_v_stats->long_exposure = __pyx_v_long_exposure;
+266: stats.long_value = long_value
__pyx_v_stats->long_value = __pyx_v_long_value;
+267: stats.longs_count = longs_count
__pyx_v_stats->longs_count = __pyx_v_longs_count;
+268: stats.net_exposure = net_exposure
__pyx_v_stats->net_exposure = __pyx_v_net_exposure;
+269: stats.net_value = net_value
__pyx_v_stats->net_value = __pyx_v_net_value;
270:
271: # !346 #113 for current bar backtesting
272: # see also:
273: # class: zipline.finance.ledger.PositionTracker
274: # func: sync_last_sale_price
+275: stats.start_net_value = start_net_value
__pyx_v_stats->start_net_value = __pyx_v_start_net_value;
276:
+277: stats.short_exposure = short_exposure
__pyx_v_stats->short_exposure = __pyx_v_short_exposure;
+278: stats.short_value = short_value
__pyx_v_stats->short_value = __pyx_v_short_value;
+279: stats.shorts_count = shorts_count
__pyx_v_stats->shorts_count = __pyx_v_shorts_count;
280:
281:
+282: cpdef minute_annual_volatility(np.ndarray[np.int64_t] date_labels,
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_minute_annual_volatility(PyArrayObject *__pyx_v_date_labels, PyArrayObject *__pyx_v_minute_returns, PyArrayObject *__pyx_v_daily_returns, CYTHON_UNUSED int __pyx_skip_dispatch) { PyArrayObject *__pyx_v_out = 0; __pyx_t_5numpy_int64_t __pyx_v_previous_date; __pyx_t_5numpy_int64_t __pyx_v_day_ix; __pyx_t_5numpy_float64_t __pyx_v_daily_sum; __pyx_t_5numpy_float64_t __pyx_v_todays_prod; __pyx_t_5numpy_float64_t __pyx_v_annualization_factor; __pyx_t_5numpy_float64_t __pyx_v_intermediate_sum; __pyx_t_5numpy_float64_t __pyx_v_mean; __pyx_t_5numpy_float64_t __pyx_v_variance; Py_ssize_t __pyx_v_ix; __pyx_t_5numpy_float64_t __pyx_v_this_minute_returns; PyObject *__pyx_v_date = NULL; PyObject *__pyx_v_demeaned_old = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_daily_returns; __Pyx_Buffer __pyx_pybuffer_daily_returns; __Pyx_LocalBuf_ND __pyx_pybuffernd_date_labels; __Pyx_Buffer __pyx_pybuffer_date_labels; __Pyx_LocalBuf_ND __pyx_pybuffernd_minute_returns; __Pyx_Buffer __pyx_pybuffer_minute_returns; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_TraceFrameInit(__pyx_codeobj__8) __Pyx_TraceCall("minute_annual_volatility", __pyx_f[0], 282, 0, __PYX_ERR(0, 282, __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, 282, __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, 282, __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, 282, __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_13); { 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, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility, "Pre-compute the minute cumulative volatility field.\n "); static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_5minute_annual_volatility = {"minute_annual_volatility", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility}; static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyArrayObject *__pyx_v_date_labels = 0; PyArrayObject *__pyx_v_minute_returns = 0; PyArrayObject *__pyx_v_daily_returns = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("minute_annual_volatility (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__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 (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_date_labels)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L3_error) else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_minute_returns)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, 1); __PYX_ERR(0, 282, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_daily_returns)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 282, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, 2); __PYX_ERR(0, 282, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "minute_annual_volatility") < 0)) __PYX_ERR(0, 282, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 3)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); values[2] = __Pyx_Arg_FASTCALL(__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_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 282, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_date_labels), __pyx_ptype_5numpy_ndarray, 1, "date_labels", 0))) __PYX_ERR(0, 282, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_minute_returns), __pyx_ptype_5numpy_ndarray, 1, "minute_returns", 0))) __PYX_ERR(0, 283, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_daily_returns), __pyx_ptype_5numpy_ndarray, 1, "daily_returns", 0))) __PYX_ERR(0, 284, __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:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __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_TraceFrameInit(__pyx_codeobj__8) __Pyx_TraceCall("minute_annual_volatility (wrapper)", __pyx_f[0], 282, 0, __PYX_ERR(0, 282, __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, 282, __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, 282, __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, 282, __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, 282, __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; } /* … */ __pyx_tuple__18 = PyTuple_Pack(3, __pyx_n_s_date_labels, __pyx_n_s_minute_returns, __pyx_n_s_daily_returns); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__18); __Pyx_GIVEREF(__pyx_tuple__18); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_5minute_annual_volatility, 0, __pyx_n_s_minute_annual_volatility, NULL, __pyx_n_s_zipline_finance__finance_ext, __pyx_d, ((PyObject *)__pyx_codeobj__8)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_minute_annual_volatility, __pyx_t_3) < 0) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_zipline_finance__finance_ext, __pyx_n_s_minute_annual_volatility, 282, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 282, __pyx_L1_error)
283: np.ndarray[np.float64_t] minute_returns,
284: np.ndarray[np.float64_t] daily_returns):
285: """Pre-compute the minute cumulative volatility field.
286: """
+287: 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, 287, __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, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (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_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, ((PyObject *)__pyx_v_minute_returns)}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __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, 287, __pyx_L1_error) __pyx_v_out = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
+288: cdef np.int64_t previous_date = date_labels[0]
__pyx_t_5 = 0; __pyx_t_6 = -1; if (__pyx_t_5 < 0) { __pyx_t_5 += __pyx_pybuffernd_date_labels.diminfo[0].shape; if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0; } else if (unlikely(__pyx_t_5 >= __pyx_pybuffernd_date_labels.diminfo[0].shape)) __pyx_t_6 = 0; if (unlikely(__pyx_t_6 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_6); __PYX_ERR(0, 288, __pyx_L1_error) } __pyx_v_previous_date = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_date_labels.diminfo[0].strides));
+289: cdef np.int64_t day_ix = 0
__pyx_v_day_ix = 0;
+290: cdef np.float64_t daily_sum = 0
__pyx_v_daily_sum = 0.0;
+291: cdef np.float64_t todays_prod = 1
__pyx_v_todays_prod = 1.0;
+292: cdef np.float64_t annualization_factor = sqrt(252.0)
__pyx_v_annualization_factor = sqrt(252.0);
293:
294: cdef np.float64_t tmp
295: cdef np.float64_t intermediate_sum
296: cdef np.float64_t mean
297: cdef np.float64_t variance
298:
299: cdef Py_ssize_t ix
300: cdef Py_ssize_t variance_ix
301: cdef np.int64_t date_label
302: cdef np.float64_t this_minute_returns
303:
304:
+305: for ix in range(len(minute_returns)):
__pyx_t_7 = PyObject_Length(((PyObject *)__pyx_v_minute_returns)); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 305, __pyx_L1_error) __pyx_t_8 = __pyx_t_7; for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_ix = __pyx_t_9;
306: with cython.boundscheck(False), cython.wraparound(False):
+307: date = date_labels[ix]
__pyx_t_5 = __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_5, __pyx_pybuffernd_date_labels.diminfo[0].strides))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_date, __pyx_t_1); __pyx_t_1 = 0;
+308: this_minute_returns = minute_returns[ix]
__pyx_t_5 = __pyx_v_ix; __pyx_v_this_minute_returns = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_minute_returns.diminfo[0].strides));
309:
+310: if date != previous_date:
__pyx_t_1 = __Pyx_PyInt_From_npy_int64(__pyx_v_previous_date); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __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, 310, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 310, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_10) { /* … */ }
+311: previous_date = date
__pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_v_date); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 311, __pyx_L1_error) __pyx_v_previous_date = __pyx_t_11;
+312: daily_sum += daily_returns[day_ix]
__pyx_t_11 = __pyx_v_day_ix; __pyx_t_6 = -1; if (__pyx_t_11 < 0) { __pyx_t_11 += __pyx_pybuffernd_daily_returns.diminfo[0].shape; if (unlikely(__pyx_t_11 < 0)) __pyx_t_6 = 0; } else if (unlikely(__pyx_t_11 >= __pyx_pybuffernd_daily_returns.diminfo[0].shape)) __pyx_t_6 = 0; if (unlikely(__pyx_t_6 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_6); __PYX_ERR(0, 312, __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_11, __pyx_pybuffernd_daily_returns.diminfo[0].strides)));
+313: day_ix += 1
__pyx_v_day_ix = (__pyx_v_day_ix + 1);
+314: todays_prod = 1
__pyx_v_todays_prod = 1.0;
315:
+316: if day_ix < 1:
__pyx_t_10 = (__pyx_v_day_ix < 1); if (__pyx_t_10) { /* … */ goto __pyx_L6; }
+317: variance = np.nan
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __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, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_12 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_variance = __pyx_t_12;
318: else:
+319: todays_prod *= 1 + this_minute_returns
/*else*/ { __pyx_v_todays_prod = (__pyx_v_todays_prod * (1.0 + __pyx_v_this_minute_returns));
320:
+321: intermediate_sum = daily_sum + todays_prod - 1
__pyx_v_intermediate_sum = ((__pyx_v_daily_sum + __pyx_v_todays_prod) - 1.0);
+322: mean = intermediate_sum / (day_ix + 1)
__pyx_t_11 = (__pyx_v_day_ix + 1); if (unlikely(__pyx_t_11 == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 322, __pyx_L1_error) } __pyx_v_mean = (__pyx_v_intermediate_sum / ((__pyx_t_5numpy_float64_t)__pyx_t_11));
323:
+324: variance = todays_prod - 1 - mean
__pyx_v_variance = ((__pyx_v_todays_prod - 1.0) - __pyx_v_mean);
+325: variance *= variance # squared
__pyx_v_variance = (__pyx_v_variance * __pyx_v_variance);
326:
+327: 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, 327, __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, 327, __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, 327, __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, 327, __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, 327, __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;
+328: variance += demeaned_old.dot(demeaned_old)
__pyx_t_2 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __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, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_13 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_v_demeaned_old}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 328, __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, 328, __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_12 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_12 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_variance = __pyx_t_12;
329:
+330: 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, 330, __pyx_L1_error) } __pyx_v_variance = (__pyx_v_variance / __pyx_v_day_ix); } __pyx_L6:;
331:
332: with cython.boundscheck(False), cython.wraparound(False):
+333: 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, 333, __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, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; }
334:
+335: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_out); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;