title: Calculating momentum signal in python using 1 month and 12 month lag
body: <p>I am wanting to calculate a simple momentum signal. The method I am following is 1 month lagged <code>cumret</code> divided by 12 month lagged <code>cumret</code> minus 1. </p>
  
  <p><code>date</code> starts at <code>1/5/14</code> and ends at <code>1/5/16</code>. As a 12 month lag is required, the first <code>mom</code> signal has to start 12 months after the start of <code>date</code>. Hence, why the first <code>mom</code> signal starts at <code>1/5/15</code>.</p>
  
  <p>Here is the data utilized:</p>
  
  <pre><code>import pandas as pd
  
  data = {'date':['1/5/14','1/6/14','1/7/14','1/8/14','1/9/14','1/10/14','1/11/14','1/12/14' .,'1/1/15','1/2/15','1/3/15','1/4/15','1/5/15','1/6/15','1/7/15','1/8/15','1/9/15','1/10/15','1/11/15','1/12/15','1/1/16','1/2/16','1/3/16','1/4/16','1/5/16'],
  'id': ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a' ],
  'ret':[0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25],
  'cumret':[1.01,1.03,    1.06,1.1    ,1.15,1.21,1.28,    1.36,1.45,1.55,1.66,    1.78,1.91,2.05,2.2,2.36,    2.53,2.71,2.9,3.1,3.31,3.53,    3.76,4,4.25]}
  
  df = pd.DataFrame(data).set_index(['date', 'id'])
  </code></pre>
  
  <p>Desired output</p>
  
  <pre><code>           ret  cumret  mom
  date    id          
  1/5/14  a   .01 1.01    
  1/6/14  a   .02 1.03    
  1/7/14  a   .03 1.06    
  1/8/14  a   .04 1.1 
  1/9/14  a   .05 1.15    
  1/10/14 a   .06 1.21    
  1/11/14 a   .07 1.28    
  1/12/14 a   .08 1.36    
  1/1/15  a   .09 1.45    
  1/2/15  a   .1  1.55    
  1/3/15  a   .11 1.66    
  1/4/15  a   .12 1.78    
  1/5/15  a   .13 1.91    .8
  1/6/15  a   .14 2.05    .9
  1/7/15  a   .15 2.2     .9
  1/8/15  a   .16 2.36    1
  1/9/15  a   .17 2.53    1.1
  1/10/15 a   .18 2.71    1.1
  1/11/15 a   .19 2.9     1.1
  1/12/15 a   .2  3.1     1.1
  1/1/16  a   .21 3.31    1.1
  1/2/16  a   .22 3.53    1.1
  1/3/16  a   .23 3.76    1.1
  1/4/16  a   .24 4       1.1
  1/5/16  a   .25 4.25    1.1
  </code></pre>
  
  <p>This is the code tried to calculate <code>mom</code></p>
  
  <pre><code>df['mom'] = ((df['cumret'].shift(-1) / (df['cumret'].shift(-12))) - 1).groupby(level = ['id'])
  </code></pre>
  
  <p>Entire dataset has more <code>id</code> e.g. a, b, c. Just included 1 variable for this example.</p>
  
  <p>Any help would be awesome! :)</p>