title: Python dynamic datetime periods
body: <p>I'm working on coding a HAR-RV volatility model where I regress daily, weekly, and monthly data to predict tomorrow's daily volatility.  I have 6 years of daily data that I would like to backtest against.  At first, I thought this would be quite simple - I used pandas asfreq to transform my daily data to weekly and monthly to calculate daily, weekly, and monthly pct_change to begin the analysis.  The issue is that I am trying to find a function in python that will allow me to calculate a monthly and weekly pct_change for each daily data point so that on 1/24/15 I will have week beginning 1/17/2015 (-7 days) and month beginning 12/25/2014 (-30 days) and for daily data point 1/23/15 I will have week beginning 1/16/2015 (-7 days) and month beginning 12/24/2014 (-30 days), etc.</p>
  
  <p>However, by using asfreq('W') and asfreq('M') I am getting 31 daily data points for each month (OK) 1 monthly data point for each month (not OK) and 4 weekly data points for each month (not OK).  I need 31 daily points, 31 weekly points, and 31 monthly points for each month.</p>
  
  <p>Any guidance on how I can achieve corresponding weekly and monthly pct_change for each daily datetime?  Here is the code that I am currently using:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from zipline.data.loader import load_bars_from_yahoo
  start = pd.Timestamp('2009-07-26')
  end = pd.Timestamp('2015-01-18')
  data = zp.utils.factory.load_from_yahoo(
      stocks=['USO'],
      start=start,
      end=end,
      )
  daily = data
  weekly = daily.asfreq('W-FRI')
  monthly = daily.asfreq('M')`
  </code></pre>