#NEWLINE# def calculate_max_drawdown( self ) : #NEWLINE# #INDENT# if ( len ( self . algorithm_cumulative_returns ) == 0 ) : #NEWLINE# #INDENT# return self . max_drawdown #NEWLINE# #UNINDENT# cur_drawdown = ( 1.0 - ( ( 1.0 + self . algorithm_cumulative_returns [ self . latest_dt_loc ] ) / ( 1.0 + self . current_max ) ) ) #NEWLINE# self . drawdowns [ self . latest_dt_loc ] = cur_drawdown #NEWLINE# if ( self . max_drawdown < self ) : #NEWLINE# #INDENT# return cur_drawdown #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . max_drawdown