title: Calculate Days Under Contract from Table of Contract Start and End Dates
body: <p>I have a <code>pandas</code> dataframe of contracts for specific assets (A, B,...). Each contract has a start date, end date (both inclusive), and a dayrate (contracts cannot overlap). I would like to generate a table that shows how many total days during a specified period (i.e. a date range, in this case a quarter), each asset was under contract. I would then like to calculate total revenues (dayrate * days under contract) for each asset.</p>
  
  <p>I started by generating a list of end dates for the quarterly periods, but am not sure how to continue:</p>
  
  <pre><code>pd.date_range(start='9/30/2019',end='12/31/2020',freq='Q').tolist()
  </code></pre>
  
  <p>Here is my sample data:</p>
  
  <pre><code>pd.DataFrame([['A', pd.to_datetime('07/30/2019'), pd.to_datetime('08/25/2019'), 5], ['B', pd.to_datetime('08/30/2022'), pd.to_datetime('09/30/2019'), 10], ['A',pd.to_datetime('09/30/2019'),pd.to_datetime('10/31/2019'), 2]], columns=['Asset', 'start', 'end', 'dayrate']).set_index('Asset')
  
      start   end dayrate
  Asset           
  A   2019-07-30  2019-08-25  5
  B   2022-08-30  2019-09-30  10
  A   2019-09-30  2019-10-31  2
  </code></pre>