title: Computing time-weighted moving average
body: <p>I have a time series of stock prices and wish to compute the moving average over a ten minute window (see diagram below).  As price ticks occur sporadically (i.e. they are <em>not</em> periodic) it seems fairest to calculate a time-weighted moving average.</p>
  
  <p><img src="https://i.stack.imgur.com/wTDsk.png" alt="Time Series"></p>
  
  <p>In the diagram there are four price changes: A, B, C and D, with the latter three occurring inside the window.  Note that because B only occurs some time into the window (say 3 minutes), the value of A still contributes to the computation.</p>
  
  <p>In fact, as far as I can tell the computation should be solely based on the values of A, B and C (<em>not</em> D) and the durations between them and the next point (or in the case of A: the duration between the start of the time window and B).  Initially D will not have any effect as its time weighting will be zero.  <strong>Is this correct?</strong></p>
  
  <p>Assuming this is correct, my concern is that the moving average will "lag" more than the non-weighted computation (which would account for the value of D immediately), However, the non-weighted computation has its own disadvantages:</p>
  
  <ul>
  <li>"A" would have as much effect on the result as the other prices despite being outside the time window.</li>
  <li>A sudden flurry of fast price ticks would heavily bias the moving average (although perhaps this is desirable?)</li>
  </ul>
  
  <p>Can anyone offer any advice over which approach seems best, or whether there's an alternative (or hybrid) approach worth considering?</p>