title: Python custom function using rolling_apply for pandas
body: <p>I would like to use the <code>pandas.rolling_apply</code> function to apply my own custom function on a rolling window basis.</p>
  
  <p>but my function requires two arguments, and also has two outputs. Is this possible?</p>
  
  <p>Below is a minimum reproducible example...</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import random
  tmp  = pd.DataFrame(np.random.randn(2000,2)/10000, 
                      index=pd.date_range('2001-01-01',periods=2000),
                      columns=['A','B'])
  
  def gm(df,p):
      v =(((df+1).cumprod())-1)*p
      return v.iloc[-1]
  
  # an example output when subsetting for just 2001
  gm(tmp['2001'],5)
  
  
  # the aim is to do it on a rolling basis over a 50 day window
  # whilst also getting both outputs and also allows me to add in the parameter p=5
  # or any other number I want p to be... 
  pd.rolling_apply(tmp,50,gm)
  </code></pre>
  
  <p>which leads to an error...since gm takes two arguments...</p>
  
  <p>any help would be greatly appreciated...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Following Jeff's comment I have progressed, but am still struggling with two  or more column outputs, so if instead i make a new function (below) which just returns two random numbers (unconnected to the previous calculation) instead rather than the last rows of v, I get an error of <code>TypeError: only length-1 arrays can be converted to Python scalars</code>. This function works if</p>
  
  <pre><code>def gm2(df,p):
      df = pd.DataFrame(df)
      v =(((df+1).cumprod())-1)*p
      return np.random.rand(2)
  
  pd.rolling_apply(tmp,50,lambda x: gm2(x,5)).tail(20)
  </code></pre>
  
  <p>This function works if 2 is changed to 1...</p>