title: Algorithm for tracking changes in value over time
body: <p>I am writing a rails app that deals with product inventory. I would like to include the following features, and am struggling with developing an efficient algorithm:</p>
  
  <ul>
  <li>View stock history (how many were in stock on each date)</li>
  <li>Quantity removed from warehouse, and quantity added to warehouse over specific periods of time</li>
  <li>Amount of time the product was out of stock in any given period</li>
  </ul>
  
  <p>My questions are as follows:</p>
  
  <ol>
  <li><p>What is the best way of tracking changes? In addition to my Products
  table, should I create another table called
  HistoricProductQuantities, and insert a new record each time there
  is a change in the quantity?</p></li>
  <li><p>What number should I track? The historic stock quantity (i.e. 50 in
      stock on this day, 24 in stock on that day), or the CHANGE in stock
      quantity i.e. -5 (5 sold) or 15 (15 added to inventory)? Or do I
      track both in separate tables?</p></li>
  </ol>
  
  <p>Thanks for your help.</p>