<s> """<STR_LIT>""" <EOL> from pyalgotrade import technical <EOL> class StdDevEventWindow ( technical . EventWindow ) : <EOL> def __init__ ( self , period , ddof ) : <EOL> assert ( period > <NUM_LIT:0> ) <EOL> super ( StdDevEventWindow , self ) . __init__ ( period ) <EOL> self . __ddof = ddof <EOL> def getValue ( self ) : <EOL> ret = None <EOL> if self . windowFull ( ) : <EOL> ret = self . getValues ( ) . std ( ddof = self . __ddof ) <EOL> return ret <EOL> class StdDev ( technical . EventBasedFilter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dataSeries , period , ddof = <NUM_LIT:0> , maxLen = None ) : <EOL> super ( StdDev , self ) . __init__ ( dataSeries , StdDevEventWindow ( period , ddof ) , maxLen ) <EOL> class ZScoreEventWindow ( technical . EventWindow ) : <EOL> def __init__ ( self , period , ddof ) : <EOL> assert ( period > <NUM_LIT:1> ) <EOL> super ( ZScoreEventWindow , self ) . __init__ ( period ) <EOL> self . __ddof = ddof <EOL> def getValue ( self ) : <EOL> ret = None <EOL> if self . windowFull ( ) : <EOL> values = self . getValues ( ) <EOL> lastValue = values [ - <NUM_LIT:1> ] <EOL> mean = values . mean ( ) <EOL> std = values . std ( ddof = self . __ddof ) <EOL> ret = ( lastValue - mean ) / float ( std ) <EOL> return ret <EOL> class ZScore ( technical . EventBasedFilter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dataSeries , period , ddof = <NUM_LIT:0> , maxLen = None ) : <EOL> super ( ZScore , self ) . __init__ ( dataSeries , ZScoreEventWindow ( period , ddof ) , maxLen ) </s>
