Generated by Cython 3.1.8
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
Raw output: _finance_ext.c
+001: cimport cython
__pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_3) < (0)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
002: from cpython cimport PyObject
003: from libc.math cimport sqrt
004:
005: cimport numpy as np
+006: import numpy as np
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_np, __pyx_t_2) < (0)) __PYX_ERR(0, 6, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+007: import pandas as pd
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_pandas, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_pd, __pyx_t_2) < (0)) __PYX_ERR(0, 7, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
008:
009: from zipline._protocol cimport InnerPosition
010: from zipline.assets._assets cimport Future
011:
012:
+013: cpdef update_position_last_sale_prices(positions, get_price, dt):
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt, CYTHON_UNUSED int __pyx_skip_dispatch) {
struct __pyx_obj_7zipline_9_protocol_InnerPosition *__pyx_v_inner_position = 0;
__pyx_t_5numpy_float64_t __pyx_v_last_sale_price;
PyObject *__pyx_v_outer_position = NULL;
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55]))
__Pyx_TraceStartFunc("update_position_last_sale_prices", __pyx_f[0], 13, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 13, __pyx_L1_error));
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_inner_position);
__Pyx_XDECREF(__pyx_v_outer_position);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_update_position_last_sale_prices, "Update the positions' last sale prices.\n\n Parameters\n ----------\n positions : OrderedDict\n The positions to update.\n get_price : callable[Asset, float]\n The function to retrieve the price for the asset.\n dt : pd.Timestamp\n The dt to set as the last sale date if the price is not nan.\n ");
static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices = {"update_position_last_sale_prices", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_update_position_last_sale_prices};
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyObject *__pyx_v_positions = 0;
PyObject *__pyx_v_get_price = 0;
PyObject *__pyx_v_dt = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("update_position_last_sale_prices (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_positions,&__pyx_mstate_global->__pyx_n_u_get_price,&__pyx_mstate_global->__pyx_n_u_dt,0};
PyObject* values[3] = {0,0,0};
const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 13, __pyx_L3_error)
if (__pyx_kwds_len > 0) {
switch (__pyx_nargs) {
case 3:
values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 13, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 2:
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 13, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 1:
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 13, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "update_position_last_sale_prices", 0) < (0)) __PYX_ERR(0, 13, __pyx_L3_error)
for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, i); __PYX_ERR(0, 13, __pyx_L3_error) }
}
} else if (unlikely(__pyx_nargs != 3)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 13, __pyx_L3_error)
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 13, __pyx_L3_error)
values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 13, __pyx_L3_error)
}
__pyx_v_positions = values[0];
__pyx_v_get_price = values[1];
__pyx_v_dt = values[2];
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("update_position_last_sale_prices", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 13, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(__pyx_self, __pyx_v_positions, __pyx_v_get_price, __pyx_v_dt);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_positions, PyObject *__pyx_v_get_price, PyObject *__pyx_v_dt) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55]))
__Pyx_TraceStartFunc("update_position_last_sale_prices (wrapper)", __pyx_f[0], 13, 0, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_update_position_last_sale_prices(__pyx_v_positions, __pyx_v_get_price, __pyx_v_dt, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 13, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.update_position_last_sale_prices", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_1update_position_last_sale_prices, 0, __pyx_mstate_global->__pyx_n_u_update_position_last_sale_prices, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[55])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_update_position_last_sale_prices, __pyx_t_2) < (0)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
014: """Update the positions' last sale prices.
015:
016: Parameters
017: ----------
018: positions : OrderedDict
019: The positions to update.
020: get_price : callable[Asset, float]
021: The function to retrieve the price for the asset.
022: dt : pd.Timestamp
023: The dt to set as the last sale date if the price is not nan.
024: """
025: cdef InnerPosition inner_position
026: cdef np.float64_t last_sale_price
027:
+028: for outer_position in positions.values():
__pyx_t_2 = 0;
if (unlikely(__pyx_v_positions == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values");
__PYX_ERR(0, 28, __pyx_L1_error)
}
__pyx_t_5 = __Pyx_dict_iterator(__pyx_v_positions, 0, __pyx_mstate_global->__pyx_n_u_values, (&__pyx_t_3), (&__pyx_t_4)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 28, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_1);
__pyx_t_1 = __pyx_t_5;
__pyx_t_5 = 0;
while (1) {
__pyx_t_6 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_3, &__pyx_t_2, NULL, &__pyx_t_5, NULL, __pyx_t_4);
if (unlikely(__pyx_t_6 == 0)) break;
if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 28, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_5);
__pyx_t_5 = 0;
+029: inner_position = outer_position.inner_position
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_outer_position, __pyx_mstate_global->__pyx_n_u_inner_position); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_mstate_global->__pyx_ptype_7zipline_9_protocol_InnerPosition))))) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_inner_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_5)); __pyx_t_5 = 0;
030:
+031: last_sale_price = get_price(inner_position.asset)
__pyx_t_7 = NULL;
__Pyx_INCREF(__pyx_v_get_price);
__pyx_t_8 = __pyx_v_get_price;
__pyx_t_9 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_8))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
assert(__pyx_t_7);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
__pyx_t_9 = 0;
}
#endif
{
PyObject *__pyx_callargs[2] = {__pyx_t_7, ((PyObject *)__pyx_v_inner_position->asset)};
__pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
}
__pyx_t_10 = __Pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_10 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_v_last_sale_price = __pyx_t_10;
032:
033: # inline ~isnan because this gets called once per position per minute
+034: if last_sale_price == last_sale_price:
__pyx_t_11 = (__pyx_v_last_sale_price == __pyx_v_last_sale_price);
if (__pyx_t_11) {
/* … */
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+035: inner_position.last_sale_price = last_sale_price
__pyx_v_inner_position->last_sale_price = __pyx_v_last_sale_price;
+036: inner_position.last_sale_date = dt
__Pyx_INCREF(__pyx_v_dt); __Pyx_GIVEREF(__pyx_v_dt); __Pyx_GOTREF(__pyx_v_inner_position->last_sale_date); __Pyx_DECREF(__pyx_v_inner_position->last_sale_date); __pyx_v_inner_position->last_sale_date = __pyx_v_dt;
037:
038:
+039: @cython.final
struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats {
PyObject_HEAD
__pyx_t_5numpy_float64_t gross_exposure;
__pyx_t_5numpy_float64_t gross_value;
__pyx_t_5numpy_float64_t long_exposure;
__pyx_t_5numpy_float64_t long_value;
__pyx_t_5numpy_float64_t net_exposure;
__pyx_t_5numpy_float64_t net_value;
__pyx_t_5numpy_float64_t short_exposure;
__pyx_t_5numpy_float64_t short_value;
__pyx_t_5numpy_uint64_t longs_count;
__pyx_t_5numpy_uint64_t shorts_count;
PyObject *position_exposure_array;
PyObject *position_exposure_series;
PyObject *underlying_value_array;
PyObject *underlying_index_array;
};
040: cdef class PositionStats:
041: """Computed values from the current positions.
042:
043: Attributes
044: ----------
045: gross_exposure : float64
046: The gross position exposure.
047: gross_value : float64
048: The gross position value.
049: long_exposure : float64
050: The exposure of just the long positions.
051: long_value : float64
052: The value of just the long positions.
053: net_exposure : float64
054: The net position exposure.
055: net_value : float64
056: The net position value.
057: short_exposure : float64
058: The exposure of just the short positions.
059: short_value : float64
060: The value of just the short positions.
061: longs_count : int64
062: The number of long positions.
063: shorts_count : int64
064: The number of short positions.
065: position_exposure_array : np.ndarray[float64]
066: The exposure of each position in the same order as
067: ``position_tracker.positions``.
068: position_exposure_series : pd.Series[float64]
069: The exposure of each position in the same order as
070: ``position_tracker.positions``. The index is the numeric sid of each
071: asset.
072:
073: Notes
074: -----
075: ``position_exposure_array`` and ``position_exposure_series`` share the same
076: underlying memory. The array interface should be preferred if you are doing
077: access each minute for better performance.
078:
079: ``position_exposure_array`` and ``position_exposure_series`` may be mutated
080: when the position tracker next updates the stats. Do not rely on these
081: objects being preserved across accesses to ``stats``. If you need to freeze
082: the values, you must take a copy.
083: """
+084: cdef readonly np.float64_t gross_exposure
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14gross_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[57]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 84, 0, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->gross_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 84, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.gross_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+085: cdef readonly np.float64_t gross_value
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11gross_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[58]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 85, 0, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->gross_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 85, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.gross_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+086: cdef readonly np.float64_t long_exposure
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_13long_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[59]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 86, 0, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->long_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 86, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.long_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+087: cdef readonly np.float64_t long_value
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_10long_value_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_10long_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[60]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 87, 0, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->long_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 87, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.long_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+088: cdef readonly np.float64_t net_exposure
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12net_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[61]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 88, 0, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->net_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 88, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.net_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+089: cdef readonly np.float64_t net_value
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_9net_value_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_9net_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[62]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 89, 0, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->net_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 89, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.net_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+090: cdef readonly np.float64_t short_exposure
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_14short_exposure___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[63]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 90, 0, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->short_exposure); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 90, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.short_exposure.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+091: cdef readonly np.float64_t short_value
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11short_value_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11short_value___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[64]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 91, 0, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->short_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 91, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.short_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+092: cdef readonly np.uint64_t longs_count
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_11longs_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[65]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 92, 0, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyLong_From_npy_uint64(__pyx_v_self->longs_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 92, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.longs_count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+093: cdef readonly np.uint64_t shorts_count
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_12shorts_count___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[66]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 93, 0, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyLong_From_npy_uint64(__pyx_v_self->shorts_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 93, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.shorts_count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+094: cdef readonly object position_exposure_array
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_23position_exposure_array___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[67]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 94, 0, 0, 0, __PYX_ERR(0, 94, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_self->position_exposure_array);
__pyx_r = __pyx_v_self->position_exposure_array;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 94, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 94, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.position_exposure_array.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+095: cdef readonly object position_exposure_series
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_24position_exposure_series___get__(struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[68]))
__Pyx_TraceStartFunc("__get__", __pyx_f[0], 95, 0, 0, 0, __PYX_ERR(0, 95, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_self->position_exposure_series);
__pyx_r = __pyx_v_self->position_exposure_series;
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 95, __pyx_L1_error));
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 95, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.position_exposure_series.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
096:
097: # These are the same memory exposed through ``position_exposure_array``
098: # and ``position_exposure_series``. These are hidden from Python.
099: cdef object underlying_value_array
100: cdef object underlying_index_array
101:
+102: @classmethod
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new = {"new", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_13PositionStats_1new(PyObject *__pyx_v_cls,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("new (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("new", 1, 0, 0, __pyx_nargs); return NULL; }
const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len < 0)) return NULL;
if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("new", __pyx_kwds); return NULL;}
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(((PyTypeObject*)__pyx_v_cls));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_13PositionStats_new(PyTypeObject *__pyx_v_cls) {
struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_self = 0;
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[56]))
__Pyx_TraceStartFunc("new", __pyx_f[0], 102, 0, 0, 0, __PYX_ERR(0, 102, __pyx_L1_error));
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 102, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.PositionStats.new", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_self);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_13PositionStats_1new, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PositionStats_new, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[56])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2, __pyx_t_2) < (0)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_GetNameInClass(__pyx_t_2, (PyObject*)__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, __pyx_mstate_global->__pyx_n_u_new_2, __pyx_t_3) < (0)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
103: def new(cls):
+104: cdef PositionStats self = cls()
__pyx_t_2 = NULL; __Pyx_INCREF((PyObject *)__pyx_v_cls); __pyx_t_3 = ((PyObject *)__pyx_v_cls); __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats))))) __PYX_ERR(0, 104, __pyx_L1_error) __pyx_v_self = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)__pyx_t_1); __pyx_t_1 = 0;
+105: self.underlying_value_array = self.position_exposure_array = np.array(
__pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->underlying_value_array); __Pyx_DECREF(__pyx_v_self->underlying_value_array); __pyx_v_self->underlying_value_array = __pyx_t_1; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->position_exposure_array); __Pyx_DECREF(__pyx_v_self->position_exposure_array); __pyx_v_self->position_exposure_array = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+106: [], dtype='float64',
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_5, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_3, __pyx_t_2}; __pyx_t_6 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_float64, __pyx_t_6, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 105, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_6); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); }
107: )
+108: self.underlying_index_array = np.array([], dtype='int64')
__pyx_t_5 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); assert(__pyx_t_5); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_2, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, __pyx_t_6}; __pyx_t_3 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_int64, __pyx_t_3, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 108, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_2, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->underlying_index_array); __Pyx_DECREF(__pyx_v_self->underlying_index_array); __pyx_v_self->underlying_index_array = __pyx_t_1; __pyx_t_1 = 0;
+109: self.position_exposure_series = pd.Series(
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->position_exposure_series); __Pyx_DECREF(__pyx_v_self->position_exposure_series); __pyx_v_self->position_exposure_series = __pyx_t_1; __pyx_t_1 = 0;
110: self.underlying_value_array,
111: index=self.underlying_index_array,
+112: copy=False,
__pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_2, __pyx_v_self->underlying_value_array}; __pyx_t_3 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, __pyx_v_self->underlying_index_array, __pyx_t_3, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 109, __pyx_L1_error) if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_3, __pyx_callargs+2, 1) < (0)) __PYX_ERR(0, 109, __pyx_L1_error) __pyx_t_1 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_6, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); }
113: )
+114: return self
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_self); __pyx_r = ((PyObject *)__pyx_v_self); __Pyx_TraceReturnValue(__pyx_r, 34, 0, __PYX_ERR(0, 114, __pyx_L1_error)); goto __pyx_L0;
115:
116:
+117: cpdef calculate_position_tracker_stats(positions, PositionStats stats):
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_calculate_position_tracker_stats(PyObject *__pyx_v_positions, struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats, CYTHON_UNUSED int __pyx_skip_dispatch) {
Py_ssize_t __pyx_v_npos;
PyArrayObject *__pyx_v_index = 0;
PyArrayObject *__pyx_v_position_exposure = 0;
PyArrayObject *__pyx_v_old_index = 0;
PyArrayObject *__pyx_v_old_position_exposure = 0;
__pyx_t_5numpy_float64_t __pyx_v_value;
__pyx_t_5numpy_float64_t __pyx_v_exposure;
__pyx_t_5numpy_float64_t __pyx_v_net_value;
__pyx_t_5numpy_float64_t __pyx_v_gross_value;
__pyx_t_5numpy_float64_t __pyx_v_long_value;
__pyx_t_5numpy_float64_t __pyx_v_short_value;
__pyx_t_5numpy_float64_t __pyx_v_net_exposure;
__pyx_t_5numpy_float64_t __pyx_v_gross_exposure;
__pyx_t_5numpy_float64_t __pyx_v_long_exposure;
__pyx_t_5numpy_float64_t __pyx_v_short_exposure;
__pyx_t_5numpy_uint64_t __pyx_v_longs_count;
__pyx_t_5numpy_uint64_t __pyx_v_shorts_count;
struct __pyx_obj_7zipline_9_protocol_InnerPosition *__pyx_v_position = 0;
Py_ssize_t __pyx_v_ix;
PyObject *__pyx_v_outer_position = NULL;
__Pyx_LocalBuf_ND __pyx_pybuffernd_index;
__Pyx_Buffer __pyx_pybuffer_index;
__Pyx_LocalBuf_ND __pyx_pybuffernd_old_index;
__Pyx_Buffer __pyx_pybuffer_old_index;
__Pyx_LocalBuf_ND __pyx_pybuffernd_old_position_exposure;
__Pyx_Buffer __pyx_pybuffer_old_position_exposure;
__Pyx_LocalBuf_ND __pyx_pybuffernd_position_exposure;
__Pyx_Buffer __pyx_pybuffer_position_exposure;
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[71]))
__Pyx_TraceStartFunc("calculate_position_tracker_stats", __pyx_f[0], 117, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 117, __pyx_L1_error));
__pyx_pybuffer_index.pybuffer.buf = NULL;
__pyx_pybuffer_index.refcount = 0;
__pyx_pybuffernd_index.data = NULL;
__pyx_pybuffernd_index.rcbuffer = &__pyx_pybuffer_index;
__pyx_pybuffer_position_exposure.pybuffer.buf = NULL;
__pyx_pybuffer_position_exposure.refcount = 0;
__pyx_pybuffernd_position_exposure.data = NULL;
__pyx_pybuffernd_position_exposure.rcbuffer = &__pyx_pybuffer_position_exposure;
__pyx_pybuffer_old_index.pybuffer.buf = NULL;
__pyx_pybuffer_old_index.refcount = 0;
__pyx_pybuffernd_old_index.data = NULL;
__pyx_pybuffernd_old_index.rcbuffer = &__pyx_pybuffer_old_index;
__pyx_pybuffer_old_position_exposure.pybuffer.buf = NULL;
__pyx_pybuffer_old_position_exposure.refcount = 0;
__pyx_pybuffernd_old_position_exposure.data = NULL;
__pyx_pybuffernd_old_position_exposure.rcbuffer = &__pyx_pybuffer_old_position_exposure;
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
__Pyx_TraceReturnValue(__pyx_r, 0, 0, __PYX_ERR(0, 117, __pyx_L1_error));
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_8);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 117, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XDECREF((PyObject *)__pyx_v_index);
__Pyx_XDECREF((PyObject *)__pyx_v_position_exposure);
__Pyx_XDECREF((PyObject *)__pyx_v_old_index);
__Pyx_XDECREF((PyObject *)__pyx_v_old_position_exposure);
__Pyx_XDECREF((PyObject *)__pyx_v_position);
__Pyx_XDECREF(__pyx_v_outer_position);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats, "Calculate various stats about the current positions.\n\n Parameters\n ----------\n positions : OrderedDict\n The ordered dictionary of positions.\n\n Returns\n -------\n position_stats : PositionStats\n The computed statistics.\n ");
static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats = {"calculate_position_tracker_stats", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats};
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyObject *__pyx_v_positions = 0;
struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("calculate_position_tracker_stats (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_positions,&__pyx_mstate_global->__pyx_n_u_stats,0};
PyObject* values[2] = {0,0};
const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 117, __pyx_L3_error)
if (__pyx_kwds_len > 0) {
switch (__pyx_nargs) {
case 2:
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 117, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 1:
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 117, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "calculate_position_tracker_stats", 0) < (0)) __PYX_ERR(0, 117, __pyx_L3_error)
for (Py_ssize_t i = __pyx_nargs; i < 2; i++) {
if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, i); __PYX_ERR(0, 117, __pyx_L3_error) }
}
} else if (unlikely(__pyx_nargs != 2)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 117, __pyx_L3_error)
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 117, __pyx_L3_error)
}
__pyx_v_positions = values[0];
__pyx_v_stats = ((struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *)values[1]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("calculate_position_tracker_stats", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 117, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stats), __pyx_mstate_global->__pyx_ptype_7zipline_7finance_12_finance_ext_PositionStats, 1, "stats", 0))) __PYX_ERR(0, 117, __pyx_L1_error)
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats(__pyx_self, __pyx_v_positions, __pyx_v_stats);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
goto __pyx_L7_cleaned_up;
__pyx_L0:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__pyx_L7_cleaned_up:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_2calculate_position_tracker_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_positions, struct __pyx_obj_7zipline_7finance_12_finance_ext_PositionStats *__pyx_v_stats) {
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[71]))
__Pyx_TraceStartFunc("calculate_position_tracker_stats (wrapper)", __pyx_f[0], 117, 0, 0, 0, __PYX_ERR(0, 117, __pyx_L1_error));
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_calculate_position_tracker_stats(__pyx_v_positions, __pyx_v_stats, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 117, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.calculate_position_tracker_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_3calculate_position_tracker_stats, 0, __pyx_mstate_global->__pyx_n_u_calculate_position_tracker_stats, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[71])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_calculate_position_tracker_stats, __pyx_t_3) < (0)) __PYX_ERR(0, 117, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
118: """Calculate various stats about the current positions.
119:
120: Parameters
121: ----------
122: positions : OrderedDict
123: The ordered dictionary of positions.
124:
125: Returns
126: -------
127: position_stats : PositionStats
128: The computed statistics.
129: """
+130: 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, 130, __pyx_L1_error) __pyx_v_npos = __pyx_t_1;
131: cdef np.ndarray[np.int64_t] index
132: cdef np.ndarray[np.float64_t] position_exposure
133:
+134: cdef np.ndarray[np.int64_t] old_index = stats.underlying_index_array
__pyx_t_2 = __pyx_v_stats->underlying_index_array; __Pyx_INCREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 134, __pyx_L1_error) { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_old_index = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_old_index.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 134, __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;
135: cdef np.ndarray[np.float64_t] old_position_exposure = (
+136: stats.underlying_value_array
__pyx_t_2 = __pyx_v_stats->underlying_value_array; __Pyx_INCREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 136, __pyx_L1_error) { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_old_position_exposure = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_old_position_exposure.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 135, __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;
137: )
138:
139: cdef np.float64_t value
140: cdef np.float64_t exposure
141:
142: cdef np.float64_t net_value
143: cdef np.float64_t gross_value
+144: cdef np.float64_t long_value = 0.0
__pyx_v_long_value = 0.0;
+145: cdef np.float64_t short_value = 0.0
__pyx_v_short_value = 0.0;
146:
147: cdef np.float64_t net_exposure
148: cdef np.float64_t gross_exposure
+149: cdef np.float64_t long_exposure = 0.0
__pyx_v_long_exposure = 0.0;
+150: cdef np.float64_t short_exposure = 0.0
__pyx_v_short_exposure = 0.0;
151:
+152: cdef np.uint64_t longs_count = 0
__pyx_v_longs_count = 0;
+153: cdef np.uint64_t shorts_count = 0
__pyx_v_shorts_count = 0;
154:
155: # attempt to reuse the memory of the old exposure series
+156: 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, 156, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 < __pyx_v_npos); if (__pyx_t_3) { /* … */ goto __pyx_L3; }
157: # we don't have enough space in the cached buffer, allocate a new
158: # array
+159: stats.underlying_index_array = index = np.empty(npos, dtype='int64')
__pyx_t_4 = NULL;
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_7 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
assert(__pyx_t_4);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
__pyx_t_7 = 0;
}
#endif
{
PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_4, __pyx_t_5};
__pyx_t_8 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_int64, __pyx_t_8, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 159, __pyx_L1_error)
__pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_6, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_8);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_INCREF(__pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_v_stats->underlying_index_array);
__Pyx_DECREF(__pyx_v_stats->underlying_index_array);
__pyx_v_stats->underlying_index_array = __pyx_t_2;
__pyx_t_9 = ((PyArrayObject *)__pyx_t_2);
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
__pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
if (unlikely(__pyx_t_10 < 0)) {
PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
__Pyx_RaiseBufferFallbackError();
} else {
PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
}
__pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
}
__pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 159, __pyx_L1_error)
}
__pyx_t_9 = 0;
__Pyx_INCREF(__pyx_t_2);
__pyx_v_index = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+160: stats.underlying_value_array = position_exposure = np.empty(
__pyx_t_6 = NULL;
__Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 160, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 160, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
/* … */
if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 160, __pyx_L1_error)
__Pyx_INCREF(__pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_v_stats->underlying_value_array);
__Pyx_DECREF(__pyx_v_stats->underlying_value_array);
__pyx_v_stats->underlying_value_array = __pyx_t_2;
__pyx_t_14 = ((PyArrayObject *)__pyx_t_2);
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
__pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
if (unlikely(__pyx_t_10 < 0)) {
PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
__Pyx_RaiseBufferFallbackError();
} else {
PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
}
__pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0;
}
__pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0];
if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 160, __pyx_L1_error)
}
__pyx_t_14 = 0;
__Pyx_INCREF(__pyx_t_2);
__pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+161: npos,
__pyx_t_8 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); assert(__pyx_t_6); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_5, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_8}; __pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_dtype, __pyx_mstate_global->__pyx_n_u_float64, __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 160, __pyx_L1_error) __pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); }
162: dtype='float64',
163: )
164:
+165: 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);
166: # create a new series to expose the arrays
+167: stats.position_exposure_series = pd.Series(
__pyx_t_5 = NULL;
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* … */
__Pyx_GIVEREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
__Pyx_DECREF(__pyx_v_stats->position_exposure_series);
__pyx_v_stats->position_exposure_series = __pyx_t_2;
__pyx_t_2 = 0;
168: position_exposure,
169: index=index,
+170: copy=False,
__pyx_t_7 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_8))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
assert(__pyx_t_5);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
__pyx_t_7 = 0;
}
#endif
{
PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_5, ((PyObject *)__pyx_v_position_exposure)};
__pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 167, __pyx_L1_error)
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_4, __pyx_callargs+2, 1) < (0)) __PYX_ERR(0, 167, __pyx_L1_error)
__pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
171: )
+172: 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, 172, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 > __pyx_v_npos); if (__pyx_t_3) { /* … */ goto __pyx_L3; }
173: # we have more space than needed, slice off the extra but leave it
174: # available
+175: index = old_index[:npos]
__pyx_t_2 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_8 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_index), __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 175, __pyx_L1_error) { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer); __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); if (unlikely(__pyx_t_10 < 0)) { PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13); __Pyx_RaiseBufferFallbackError(); } else { PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13); } __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0; } __pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0]; if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 175, __pyx_L1_error) } __pyx_v_index = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+176: position_exposure = old_position_exposure[:npos]
__pyx_t_2 = PyLong_FromSsize_t(__pyx_v_npos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_8 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_old_position_exposure), __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 176, __pyx_L1_error) { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer); __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_2), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); if (unlikely(__pyx_t_10 < 0)) { PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); __Pyx_RaiseBufferFallbackError(); } else { PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11); } __pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0; } __pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0]; if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 176, __pyx_L1_error) } __pyx_v_position_exposure = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
177:
+178: 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);
179: # create a new series with the sliced arrays
+180: stats.position_exposure_series = pd.Series(
__pyx_t_8 = NULL;
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* … */
__Pyx_GIVEREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
__Pyx_DECREF(__pyx_v_stats->position_exposure_series);
__pyx_v_stats->position_exposure_series = __pyx_t_2;
__pyx_t_2 = 0;
181: position_exposure,
182: index=index,
+183: copy=False,
__pyx_t_7 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_5))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
assert(__pyx_t_8);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
__pyx_t_7 = 0;
}
#endif
{
PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_8, ((PyObject *)__pyx_v_position_exposure)};
__pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 180, __pyx_L1_error)
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_4, __pyx_callargs+2, 1) < (0)) __PYX_ERR(0, 180, __pyx_L1_error)
__pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_5, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
184: )
185: else:
186: # we have exactly the right amount of space, no slicing or allocation
187: # needed
+188: index = old_index
/*else*/ {
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_index.rcbuffer->pybuffer);
__pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_old_index), &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
if (unlikely(__pyx_t_10 < 0)) {
PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_index.rcbuffer->pybuffer, (PyObject*)__pyx_v_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
__Pyx_RaiseBufferFallbackError();
} else {
PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
}
__pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
}
__pyx_pybuffernd_index.diminfo[0].strides = __pyx_pybuffernd_index.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_index.diminfo[0].shape = __pyx_pybuffernd_index.rcbuffer->pybuffer.shape[0];
if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 188, __pyx_L1_error)
}
__Pyx_INCREF((PyObject *)__pyx_v_old_index);
__pyx_v_index = ((PyArrayObject *)__pyx_v_old_index);
+189: position_exposure = old_position_exposure
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer);
__pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_old_position_exposure), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
if (unlikely(__pyx_t_10 < 0)) {
PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_position_exposure.rcbuffer->pybuffer, (PyObject*)__pyx_v_position_exposure, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
__Pyx_RaiseBufferFallbackError();
} else {
PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
}
__pyx_t_13 = __pyx_t_12 = __pyx_t_11 = 0;
}
__pyx_pybuffernd_position_exposure.diminfo[0].strides = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_position_exposure.diminfo[0].shape = __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.shape[0];
if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 189, __pyx_L1_error)
}
__Pyx_INCREF((PyObject *)__pyx_v_old_position_exposure);
__pyx_v_position_exposure = ((PyArrayObject *)__pyx_v_old_position_exposure);
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: stats.position_exposure_series = pd.Series(
__pyx_t_5 = NULL;
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_pd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 192, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_Series); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 192, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* … */
__Pyx_GIVEREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_v_stats->position_exposure_series);
__Pyx_DECREF(__pyx_v_stats->position_exposure_series);
__pyx_v_stats->position_exposure_series = __pyx_t_2;
__pyx_t_2 = 0;
}
__pyx_L3:;
193: position_exposure,
194: index=index,
+195: copy=False,
__pyx_t_7 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_8))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
assert(__pyx_t_5);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_8, __pyx__function);
__pyx_t_7 = 0;
}
#endif
{
PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 2 : 0)] = {__pyx_t_5, ((PyObject *)__pyx_v_position_exposure)};
__pyx_t_4 = __Pyx_MakeVectorcallBuilderKwds(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 192, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_index, ((PyObject *)__pyx_v_index), __pyx_t_4, __pyx_callargs+2, 0) < (0)) __PYX_ERR(0, 192, __pyx_L1_error)
if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_copy, Py_False, __pyx_t_4, __pyx_callargs+2, 1) < (0)) __PYX_ERR(0, 192, __pyx_L1_error)
__pyx_t_2 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_4);
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
196: )
197:
198: cdef InnerPosition position
+199: cdef Py_ssize_t ix = 0
__pyx_v_ix = 0;
200:
+201: 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, 201, __pyx_L1_error)
}
__pyx_t_8 = __Pyx_dict_iterator(__pyx_v_positions, 0, __pyx_mstate_global->__pyx_n_u_values, (&__pyx_t_15), (&__pyx_t_10)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_2);
__pyx_t_2 = __pyx_t_8;
__pyx_t_8 = 0;
while (1) {
__pyx_t_16 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_15, &__pyx_t_1, NULL, &__pyx_t_8, NULL, __pyx_t_10);
if (unlikely(__pyx_t_16 == 0)) break;
if (unlikely(__pyx_t_16 == -1)) __PYX_ERR(0, 201, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_XDECREF_SET(__pyx_v_outer_position, __pyx_t_8);
__pyx_t_8 = 0;
+202: position = outer_position.inner_position
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_outer_position, __pyx_mstate_global->__pyx_n_u_inner_position); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 202, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_mstate_global->__pyx_ptype_7zipline_9_protocol_InnerPosition))))) __PYX_ERR(0, 202, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_position, ((struct __pyx_obj_7zipline_9_protocol_InnerPosition *)__pyx_t_8)); __pyx_t_8 = 0;
203:
204: # NOTE: this loop does a lot of stuff!
205: # we call this function every time the portfolio value is needed,
206: # which is at least once per simulation day, so let's not iterate
207: # through every single position multiple times.
+208: exposure = position.amount * position.last_sale_price
__pyx_v_exposure = (__pyx_v_position->amount * __pyx_v_position->last_sale_price);
209:
+210: if type(position.asset) is Future:
__pyx_t_3 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_position->asset))) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_7zipline_6assets_7_assets_Future));
if (__pyx_t_3) {
/* … */
goto __pyx_L6;
}
211: # Futures don't have an inherent position value.
+212: value = 0
__pyx_v_value = 0.0;
213:
214: # unchecked cast, this is safe because we do a type check above
+215: exposure *= position.asset.price_multiplier
__pyx_v_exposure = (__pyx_v_exposure * __pyx_v_position->asset->price_multiplier);
216: else:
+217: value = exposure
/*else*/ {
__pyx_v_value = __pyx_v_exposure;
}
__pyx_L6:;
218:
+219: if exposure > 0:
__pyx_t_3 = (__pyx_v_exposure > 0.0);
if (__pyx_t_3) {
/* … */
goto __pyx_L7;
}
+220: longs_count += 1
__pyx_v_longs_count = (__pyx_v_longs_count + 1);
+221: long_value += value
__pyx_v_long_value = (__pyx_v_long_value + __pyx_v_value);
+222: long_exposure += exposure
__pyx_v_long_exposure = (__pyx_v_long_exposure + __pyx_v_exposure);
+223: elif exposure < 0:
__pyx_t_3 = (__pyx_v_exposure < 0.0);
if (__pyx_t_3) {
/* … */
}
__pyx_L7:;
+224: shorts_count += 1
__pyx_v_shorts_count = (__pyx_v_shorts_count + 1);
+225: short_value += value
__pyx_v_short_value = (__pyx_v_short_value + __pyx_v_value);
+226: short_exposure += exposure
__pyx_v_short_exposure = (__pyx_v_short_exposure + __pyx_v_exposure);
227:
228: with cython.boundscheck(False), cython.wraparound(False):
+229: index[ix] = position.asset.sid
__pyx_t_17 = __pyx_v_position->asset->sid;
__pyx_t_18 = __pyx_v_ix;
*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_index.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_index.diminfo[0].strides) = __pyx_t_17;
+230: position_exposure[ix] = exposure
__pyx_t_18 = __pyx_v_ix;
*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_position_exposure.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_position_exposure.diminfo[0].strides) = __pyx_v_exposure;
231:
+232: ix += 1
__pyx_v_ix = (__pyx_v_ix + 1);
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
233:
+234: net_value = long_value + short_value
__pyx_v_net_value = (__pyx_v_long_value + __pyx_v_short_value);
+235: gross_value = long_value - short_value
__pyx_v_gross_value = (__pyx_v_long_value - __pyx_v_short_value);
236:
+237: net_exposure = long_exposure + short_exposure
__pyx_v_net_exposure = (__pyx_v_long_exposure + __pyx_v_short_exposure);
+238: gross_exposure = long_exposure - short_exposure
__pyx_v_gross_exposure = (__pyx_v_long_exposure - __pyx_v_short_exposure);
239:
+240: stats.gross_exposure = gross_exposure
__pyx_v_stats->gross_exposure = __pyx_v_gross_exposure;
+241: stats.gross_value = gross_value
__pyx_v_stats->gross_value = __pyx_v_gross_value;
+242: stats.long_exposure = long_exposure
__pyx_v_stats->long_exposure = __pyx_v_long_exposure;
+243: stats.long_value = long_value
__pyx_v_stats->long_value = __pyx_v_long_value;
+244: stats.longs_count = longs_count
__pyx_v_stats->longs_count = __pyx_v_longs_count;
+245: stats.net_exposure = net_exposure
__pyx_v_stats->net_exposure = __pyx_v_net_exposure;
+246: stats.net_value = net_value
__pyx_v_stats->net_value = __pyx_v_net_value;
+247: stats.short_exposure = short_exposure
__pyx_v_stats->short_exposure = __pyx_v_short_exposure;
+248: stats.short_value = short_value
__pyx_v_stats->short_value = __pyx_v_short_value;
+249: stats.shorts_count = shorts_count
__pyx_v_stats->shorts_count = __pyx_v_shorts_count;
250:
251:
+252: cpdef minute_annual_volatility(np.ndarray[np.int64_t] date_labels,
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyObject *__pyx_f_7zipline_7finance_12_finance_ext_minute_annual_volatility(PyArrayObject *__pyx_v_date_labels, PyArrayObject *__pyx_v_minute_returns, PyArrayObject *__pyx_v_daily_returns, CYTHON_UNUSED int __pyx_skip_dispatch) {
PyArrayObject *__pyx_v_out = 0;
__pyx_t_5numpy_int64_t __pyx_v_previous_date;
__pyx_t_5numpy_int64_t __pyx_v_day_ix;
__pyx_t_5numpy_float64_t __pyx_v_daily_sum;
__pyx_t_5numpy_float64_t __pyx_v_todays_prod;
__pyx_t_5numpy_float64_t __pyx_v_annualization_factor;
__pyx_t_5numpy_float64_t __pyx_v_intermediate_sum;
__pyx_t_5numpy_float64_t __pyx_v_mean;
__pyx_t_5numpy_float64_t __pyx_v_variance;
Py_ssize_t __pyx_v_ix;
__pyx_t_5numpy_float64_t __pyx_v_this_minute_returns;
PyObject *__pyx_v_date = NULL;
PyObject *__pyx_v_demeaned_old = NULL;
__Pyx_LocalBuf_ND __pyx_pybuffernd_daily_returns;
__Pyx_Buffer __pyx_pybuffer_daily_returns;
__Pyx_LocalBuf_ND __pyx_pybuffernd_date_labels;
__Pyx_Buffer __pyx_pybuffer_date_labels;
__Pyx_LocalBuf_ND __pyx_pybuffernd_minute_returns;
__Pyx_Buffer __pyx_pybuffer_minute_returns;
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[72]))
__Pyx_TraceStartFunc("minute_annual_volatility", __pyx_f[0], 252, 0, 0, __pyx_skip_dispatch, __PYX_ERR(0, 252, __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, 252, __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, 252, __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, 252, __pyx_L1_error)
}
__pyx_pybuffernd_daily_returns.diminfo[0].strides = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_daily_returns.diminfo[0].shape = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.shape[0];
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 252, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF(__pyx_v_date);
__Pyx_XDECREF(__pyx_v_demeaned_old);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility, "Pre-compute the minute cumulative volatility field.\n ");
static PyMethodDef __pyx_mdef_7zipline_7finance_12_finance_ext_5minute_annual_volatility = {"minute_annual_volatility", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7zipline_7finance_12_finance_ext_4minute_annual_volatility};
static PyObject *__pyx_pw_7zipline_7finance_12_finance_ext_5minute_annual_volatility(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyArrayObject *__pyx_v_date_labels = 0;
PyArrayObject *__pyx_v_minute_returns = 0;
PyArrayObject *__pyx_v_daily_returns = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("minute_annual_volatility (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_date_labels,&__pyx_mstate_global->__pyx_n_u_minute_returns,&__pyx_mstate_global->__pyx_n_u_daily_returns,0};
PyObject* values[3] = {0,0,0};
const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 252, __pyx_L3_error)
if (__pyx_kwds_len > 0) {
switch (__pyx_nargs) {
case 3:
values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 252, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 2:
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 252, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 1:
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 252, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "minute_annual_volatility", 0) < (0)) __PYX_ERR(0, 252, __pyx_L3_error)
for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, i); __PYX_ERR(0, 252, __pyx_L3_error) }
}
} else if (unlikely(__pyx_nargs != 3)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 252, __pyx_L3_error)
values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 252, __pyx_L3_error)
values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 252, __pyx_L3_error)
}
__pyx_v_date_labels = ((PyArrayObject *)values[0]);
__pyx_v_minute_returns = ((PyArrayObject *)values[1]);
__pyx_v_daily_returns = ((PyArrayObject *)values[2]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("minute_annual_volatility", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 252, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_date_labels), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "date_labels", 0))) __PYX_ERR(0, 252, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_minute_returns), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "minute_returns", 0))) __PYX_ERR(0, 253, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_daily_returns), __pyx_mstate_global->__pyx_ptype_5numpy_ndarray, 1, "daily_returns", 0))) __PYX_ERR(0, 254, __pyx_L1_error)
__pyx_r = __pyx_pf_7zipline_7finance_12_finance_ext_4minute_annual_volatility(__pyx_self, __pyx_v_date_labels, __pyx_v_minute_returns, __pyx_v_daily_returns);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
goto __pyx_L7_cleaned_up;
__pyx_L0:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__pyx_L7_cleaned_up:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7zipline_7finance_12_finance_ext_4minute_annual_volatility(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_date_labels, PyArrayObject *__pyx_v_minute_returns, PyArrayObject *__pyx_v_daily_returns) {
__Pyx_LocalBuf_ND __pyx_pybuffernd_daily_returns;
__Pyx_Buffer __pyx_pybuffer_daily_returns;
__Pyx_LocalBuf_ND __pyx_pybuffernd_date_labels;
__Pyx_Buffer __pyx_pybuffer_date_labels;
__Pyx_LocalBuf_ND __pyx_pybuffernd_minute_returns;
__Pyx_Buffer __pyx_pybuffer_minute_returns;
PyObject *__pyx_r = NULL;
__Pyx_TraceDeclarationsFunc
__Pyx_TraceFrameInit(((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[72]))
__Pyx_TraceStartFunc("minute_annual_volatility (wrapper)", __pyx_f[0], 252, 0, 0, 0, __PYX_ERR(0, 252, __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, 252, __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, 252, __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, 252, __pyx_L1_error)
}
__pyx_pybuffernd_daily_returns.diminfo[0].strides = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_daily_returns.diminfo[0].shape = __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.shape[0];
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_7zipline_7finance_12_finance_ext_minute_annual_volatility(__pyx_v_date_labels, __pyx_v_minute_returns, __pyx_v_daily_returns, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_TraceException(__pyx_lineno, 0, 0);
#if CYTHON_USE_SYS_MONITORING
__Pyx_TraceExceptionUnwind(0, 0);
#else
__Pyx_TraceReturnValue(NULL, 0, 0, __PYX_ERR(0, 252, __pyx_L1_error));
#endif
__Pyx_AddTraceback("zipline.finance._finance_ext.minute_annual_volatility", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_daily_returns.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_date_labels.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_minute_returns.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_PyMonitoring_ExitScope(0);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_7zipline_7finance_12_finance_ext_5minute_annual_volatility, 0, __pyx_mstate_global->__pyx_n_u_minute_annual_volatility, NULL, __pyx_mstate_global->__pyx_n_u_zipline_finance__finance_ext, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[72])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_minute_annual_volatility, __pyx_t_3) < (0)) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
253: np.ndarray[np.float64_t] minute_returns,
254: np.ndarray[np.float64_t] daily_returns):
255: """Pre-compute the minute cumulative volatility field.
256: """
+257: cdef np.ndarray out = np.empty_like(minute_returns)
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_empty_like); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 257, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, ((PyObject *)__pyx_v_minute_returns)}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 257, __pyx_L1_error) __pyx_v_out = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
+258: cdef np.int64_t previous_date = date_labels[0]
__pyx_t_6 = 0;
__pyx_t_7 = -1;
if (__pyx_t_6 < 0) {
__pyx_t_6 += __pyx_pybuffernd_date_labels.diminfo[0].shape;
if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
} else if (unlikely(__pyx_t_6 >= __pyx_pybuffernd_date_labels.diminfo[0].shape)) __pyx_t_7 = 0;
if (unlikely(__pyx_t_7 != -1)) {
__Pyx_RaiseBufferIndexError(__pyx_t_7);
__PYX_ERR(0, 258, __pyx_L1_error)
}
__pyx_v_previous_date = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_date_labels.diminfo[0].strides));
+259: cdef np.int64_t day_ix = 0
__pyx_v_day_ix = 0;
+260: cdef np.float64_t daily_sum = 0
__pyx_v_daily_sum = 0.0;
+261: cdef np.float64_t todays_prod = 1
__pyx_v_todays_prod = 1.0;
+262: cdef np.float64_t annualization_factor = sqrt(252.0)
__pyx_v_annualization_factor = sqrt(252.0);
263:
264: cdef np.float64_t tmp
265: cdef np.float64_t intermediate_sum
266: cdef np.float64_t mean
267: cdef np.float64_t variance
268:
269: cdef Py_ssize_t ix
270: cdef Py_ssize_t variance_ix
271: cdef np.int64_t date_label
272: cdef np.float64_t this_minute_returns
273:
274:
+275: for ix in range(len(minute_returns)):
__pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_minute_returns)); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 275, __pyx_L1_error) __pyx_t_9 = __pyx_t_8; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_ix = __pyx_t_10;
276: with cython.boundscheck(False), cython.wraparound(False):
+277: date = date_labels[ix]
__pyx_t_6 = __pyx_v_ix;
__pyx_t_1 = __Pyx_PyLong_From_npy_int64((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_date_labels.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_date_labels.diminfo[0].strides))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_date, __pyx_t_1);
__pyx_t_1 = 0;
+278: this_minute_returns = minute_returns[ix]
__pyx_t_6 = __pyx_v_ix;
__pyx_v_this_minute_returns = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_minute_returns.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_minute_returns.diminfo[0].strides));
279:
+280: if date != previous_date:
__pyx_t_1 = __Pyx_PyLong_From_npy_int64(__pyx_v_previous_date); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyObject_RichCompare(__pyx_v_date, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 280, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 280, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_11) { /* … */ }
+281: previous_date = date
__pyx_t_12 = __Pyx_PyLong_As_npy_int64(__pyx_v_date); if (unlikely((__pyx_t_12 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L1_error) __pyx_v_previous_date = __pyx_t_12;
+282: daily_sum += daily_returns[day_ix]
__pyx_t_12 = __pyx_v_day_ix;
__pyx_t_7 = -1;
if (__pyx_t_12 < 0) {
__pyx_t_12 += __pyx_pybuffernd_daily_returns.diminfo[0].shape;
if (unlikely(__pyx_t_12 < 0)) __pyx_t_7 = 0;
} else if (unlikely(__pyx_t_12 >= __pyx_pybuffernd_daily_returns.diminfo[0].shape)) __pyx_t_7 = 0;
if (unlikely(__pyx_t_7 != -1)) {
__Pyx_RaiseBufferIndexError(__pyx_t_7);
__PYX_ERR(0, 282, __pyx_L1_error)
}
__pyx_v_daily_sum = (__pyx_v_daily_sum + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_daily_returns.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_daily_returns.diminfo[0].strides)));
+283: day_ix += 1
__pyx_v_day_ix = (__pyx_v_day_ix + 1);
+284: todays_prod = 1
__pyx_v_todays_prod = 1.0;
285:
+286: if day_ix < 1:
__pyx_t_11 = (__pyx_v_day_ix < 1);
if (__pyx_t_11) {
/* … */
goto __pyx_L6;
}
+287: variance = np.nan
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_nan); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_13 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_13 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_variance = __pyx_t_13;
288: else:
+289: todays_prod *= 1 + this_minute_returns
/*else*/ {
__pyx_v_todays_prod = (__pyx_v_todays_prod * (1.0 + __pyx_v_this_minute_returns));
290:
+291: intermediate_sum = daily_sum + todays_prod - 1
__pyx_v_intermediate_sum = ((__pyx_v_daily_sum + __pyx_v_todays_prod) - 1.0);
+292: mean = intermediate_sum / (day_ix + 1)
__pyx_t_12 = (__pyx_v_day_ix + 1);
if (unlikely(__pyx_t_12 == 0)) {
PyErr_SetString(PyExc_ZeroDivisionError, "float division");
__PYX_ERR(0, 292, __pyx_L1_error)
}
__pyx_v_mean = (__pyx_v_intermediate_sum / ((__pyx_t_5numpy_float64_t)__pyx_t_12));
293:
+294: variance = todays_prod - 1 - mean
__pyx_v_variance = ((__pyx_v_todays_prod - 1.0) - __pyx_v_mean);
+295: variance *= variance # squared
__pyx_v_variance = (__pyx_v_variance * __pyx_v_variance);
296:
+297: demeaned_old = daily_returns[:day_ix] - mean
__pyx_t_1 = __Pyx_PyLong_From_npy_int64(__pyx_v_day_ix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PySlice_New(Py_None, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_daily_returns), __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyFloat_FromDouble(__pyx_v_mean); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_demeaned_old, __pyx_t_2); __pyx_t_2 = 0;
+298: variance += demeaned_old.dot(demeaned_old)
__pyx_t_2 = PyFloat_FromDouble(__pyx_v_variance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_v_demeaned_old; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_demeaned_old}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_dot, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_13 = __Pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_13 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_variance = __pyx_t_13;
299:
+300: 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, 300, __pyx_L1_error)
}
__pyx_v_variance = (__pyx_v_variance / __pyx_v_day_ix);
}
__pyx_L6:;
301:
302: with cython.boundscheck(False), cython.wraparound(False):
+303: 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, 303, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (unlikely((__Pyx_SetItemInt(((PyObject *)__pyx_v_out), __pyx_v_ix, __pyx_t_1, Py_ssize_t, 1, PyLong_FromSsize_t, 0, 0, 0, 1) < 0))) __PYX_ERR(0, 303, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; }
304:
+305: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_out); __pyx_r = ((PyObject *)__pyx_v_out); __Pyx_TraceReturnValue(__pyx_r, 101, 0, __PYX_ERR(0, 305, __pyx_L1_error)); goto __pyx_L0;