title: Cumputing indicators with a DataFrame in python
body: <p>Can you please help me on calculating indicators for a DataFrame :</p>
  
  <p>The code below works fine for a serie (index dates and one column for returns of the asset) : BUT not for a DataFrame</p>
  
  <p>"" r is the data set i use in the function ( the index are the dates and the columns are the asset's name and returns )</p>
  
  <pre><code>def drawdown(r):
  
      wealth_index = 1000*(1+r).cumprod()
  
      previous_peaks = wealth_index.cummax()
  
      drawdown = (wealth_index - previous_peaks)/previous_peaks
  
      amount_drawdown = wealth_index - previous_peaks
  
      return pd.DataFrame({"Wealth": wealth_index,
  
      "Previous Peak": previous_peaks,
  
      "Max Drawdown in %": drawdown*100,
  
      "Drawdown Amount": amount_drawdown})
  </code></pre>
  
  <p>For DataFrame : i have tried to index the output DataFrame but i have it wrong.</p>
  
  <pre><code>def drawdown(r):
  
      wealth_index = 1000*(1+r).cumprod()
  
      previous_peaks = wealth_index.cummax()
  
      drawdown = (wealth_index - previous_peaks)/previous_peaks
  
      amount_drawdown = wealth_index - previous_peaks
  
      return pd.DataFrame({"Wealth": wealth_index,
  
      "Previous Peak": previous_peaks,
  
      "Max Drawdown in %": drawdown*100,
  
      "Drawdown Amount": amount_drawdown}, index=r.columns)
  </code></pre>
  
  <p>Can you please help...</p>