@@ -227,46 +227,46 @@ cdef class CSAverageAdjustedSecurityValueHolder(CrossSectionValueHolder):
227
227
228
228
229
229
cdef class CSZScoreSecurityValueHolder(CrossSectionValueHolder):
230
- def __init__ (self , innerValue ):
231
- super (CSZScoreSecurityValueHolder, self ).__init__(innerValue)
230
+ def __init__ (self , innerValue , groups = None ):
231
+ super (CSZScoreSecurityValueHolder, self ).__init__(innerValue, groups )
232
232
233
- @property
234
- def value ( self ):
233
+ cdef _cal_impl( self ):
234
+ cdef SeriesValues raw_values = self ._inner.value
235
235
236
- cdef SeriesValues raw_values
236
+ if self ._group:
237
+ self .cached = raw_values.zscore(self ._group.value)
238
+ else :
239
+ self .cached = raw_values.zscore()
240
+ self .updated = 1
237
241
242
+ @property
243
+ def value (self ):
238
244
if self .updated:
239
245
return self .cached
240
246
else :
241
- raw_values = self ._inner.value
242
- self .cached = raw_values.zscore()
243
- self .updated = 1
247
+ self ._cal_impl()
244
248
return self .cached
245
249
246
- @ cython.cdivision (True )
247
250
cpdef double value_by_name(self , name):
248
-
249
- cdef SeriesValues raw_values
250
-
251
251
if self .updated:
252
252
return self .cached[name]
253
253
else :
254
- raw_values = self ._inner.value
255
- self .cached = raw_values.zscore()
256
- self .updated = 1
254
+ self ._cal_impl()
257
255
return self .cached[name]
258
256
259
- @ cython.cdivision (True )
260
257
cpdef SeriesValues value_by_names(self , list names):
261
-
262
- cdef SeriesValues raw_values
263
-
264
- raw_values = self ._inner.value_by_names(names)
265
- raw_values = raw_values.zscore()
266
- return raw_values[names]
258
+ cdef SeriesValues raw_values = self ._inner.value_by_names(names)
259
+ if self ._group:
260
+ raw_values = raw_values.zscore( self ._group.value_by_names(names))
261
+ else :
262
+ raw_values = raw_values.zscore()
263
+ return raw_values
267
264
268
265
def __str__ (self ):
269
- return " \mathrm{{CSZScore}}({0})" .format(str (self ._inner))
266
+ if self ._group:
267
+ return " \mathrm{{CSZscore}}({0}, groups={1})" .format(str (self ._inner), str (self ._group))
268
+ else :
269
+ return " \mathrm{{CSZscore}}({0})" .format(str (self ._inner))
270
270
271
271
272
272
cdef class CSResidueSecurityValueHolder(SecurityValueHolder):
0 commit comments