code: def to_drawdown_series(prices):
      
      # make a copy so that we don't modify original data
      drawdown = prices.copy()
  
      # Fill NaN's with previous values
      drawdown = drawdown.fillna(method='ffill')
  
      # Ignore problems with NaN's in the beginning
      drawdown[np.isnan(drawdown)] = -np.Inf
  
      # Rolling maximum
      roll_max = np.maximum.accumulate(drawdown)
      drawdown = drawdown / roll_max - 1.
      return drawdown
docs: Calculates the `drawdown <https://www.investopedia.com/terms/d/drawdown.asp>`_ series.
  
      This returns a series representing a drawdown.
      When the price is at all time highs, the drawdown
      is 0. However, when prices are below high water marks,
      the drawdown series = current / hwm - 1
  
      The max drawdown can be obtained by simply calling .min()
      on the result (since the drawdown series is negative)
  
      Method ignores all gaps of NaN's in the price series.
  
      Args:
          * prices (Series or DataFrame): Series of prices.