code: def compute_drawdown_duration_peaks(dd: pd.Series):
      iloc = np.unique(
          np.r_[(dd == 0).values.nonzero()[0], len(dd) - 1]
      )
      iloc = pd.Series(iloc, index=dd.index[iloc])
      df = iloc.to_frame("iloc").assign(prev=iloc.shift())
      df = df[df["iloc"] > df["prev"] + 1].astype(int)
  
      # If no drawdown since no trade, avoid below for pandas sake and return nan series
      if not len(df):
          return (dd.replace(0, np.nan),) * 2
  
      df["duration"] = df["iloc"].map(dd.index.__getitem__) - df[
          "prev"
      ].map(dd.index.__getitem__)
      df["peak_dd"] = df.apply(
          lambda row: dd.iloc[row["prev"] : row["iloc"] + 1].max(),
          axis=1,
      )
      df = df.reindex(dd.index)
      return df["duration"], df["peak_dd"]
  
file_path: backtesting.py/backtesting/_stats.py
imports: from typing import TYPE_CHECKING, List, Union
  import numpy
  import pandas
  from ._util import _data_period
label_desc: Use image node_id 1 for calling a global function with example usage: compute_drawdown_duration_peaks(dd) and returns: df,  df, unknown