#NEWLINE# def create_drawdowns( self , pnl ) : #NEWLINE# #INDENT# '\n        Calculate the largest peak-to-trough drawdown of the PnL curve\n        as well as the duration of the drawdown. Requires that the \n        pnl_returns is a pandas Series.\n        Parameters:\n        pnl - A pandas Series representing period percentage returns.\n        Returns:\n        drawdown, duration - Highest peak-to-trough drawdown and duration.\n        ' #NEWLINE# hwm = [ 0 ] #NEWLINE# idx = pnl . index #NEWLINE# drawdown = pd . Series ( index = idx ) #NEWLINE# duration = pd . Series ( index = idx ) #NEWLINE# for t in range ( 1 , len ( idx ) ) : #NEWLINE# #INDENT# hwm . append ( max ( hwm [ ( t - 1 ) ] , pnl . ix [ t ] ) ) #NEWLINE# drawdown . ix [ t ] = ( hwm [ t ] - duration . ix [ t ] ) #NEWLINE# duration . ix [ t ] = ( 0 if ( drawdown . ix [ t ] == 0 ) else ( duration . ix [ ( t - 1 ) ] + 1 ) ) #NEWLINE# #UNINDENT# return ( drawdown , drawdown . max ( ) , duration . max ( ) )