def max_drawdown(networth):
 hwm = [0]
 eq_idx = networth.index
 drawdown = pd.Series(index=eq_idx)
 duration = pd.Series(index=eq_idx)
 for t in range(1, len(eq_idx)):
  cur_hwm = max(hwm[(t - 1)], networth[t])
  hwm.append(cur_hwm)
  drawdown[t] = (hwm[t] - networth[t])
  duration[t] = (0 if (drawdown[t] <= 0) else (duration[(t - 1)] + 1))
 return (drawdown.max(), duration.max())

def max_drawdown ( networth ) : hwm = [ 0 ] eq_idx = networth . index drawdown = pd . Series ( index = eq_idx ) duration = pd . Series ( index = eq_idx ) for t in range ( 1 , len ( eq_idx ) ) : cur_hwm = max ( hwm [ ( t - 1 ) ] , networth [ t ] ) hwm . append ( cur_hwm ) drawdown [ t ] = ( hwm [ t ] - networth [ t ] ) duration [ t ] = ( 0 if ( drawdown [ t ] <= 0 ) else ( duration [ ( t - 1 ) ] + 1 ) ) return ( drawdown . max ( ) , duration . max ( ) )
networth: 历史净值 .