title: how to construct Time based EWMA
body: <p>I am calculating the time-based EWMA, as defined:</p>
  
  <p><img src="https://latex.codecogs.com/gif.latex?%5Cinline&space;%5Cmu_%7Bn&plus;1%7D&space;=&space;c_%7Bn&plus;1%7D&space;%5Ccdot&space;%5Cmu_n&space;&plus;&space;(1-c_%7Bn&plus;1%7D)%5Ccdot&space;x_%7Bn&plus;1%7D" title="\mu_{n+1} = c_{n+1} \cdot \mu_n + (1-c_{n+1})\cdot x_{n+1}" /></p>
  
  <p>where:</p>
  
  <p><img src="https://latex.codecogs.com/gif.latex?%5Cinline&space;c_%7Bn&plus;1%7D&space;=&space;e%5E%7B-%5Clambda(t_%7Bn&plus;1%7D-t_n)%7D" title="c_{n+1} = e^{-\lambda(t_{n+1}-t_n)}" /></p>
  
  <p>On the following example data frame df:</p>
  
  <pre class="lang-py prettyprint-override"><code>index      time       x
  0          1          5
  1          1.3        4
  2          1.4        8
  3          2.8        3  
  </code></pre>
  
  <p>For example, at time 3:</p>
  
  <p><img src="https://latex.codecogs.com/gif.latex?%5Cinline&space;%5Cmu_3&space;=&space;e%5E%7B-%5Clambda%5Ccdot(2.8-1.4)%7D%5Ccdot%5Cmu_2&space;&plus;&space;(1-e%5E%7B-%5Clambda%5Ccdot(2.8-1.4)%7D)%5Ccdot&space;3" title="\mu_3 = e^{-\lambda\cdot(2.8-1.4)}\cdot\mu_2 + (1-e^{-\lambda\cdot(2.8-1.4)})\cdot 3" /></p>
  
  <p>I know that in python we can use <code>df['ewma'] = df['x'].ewm(alpha = c)</code> to calculate the simple ewma, but here <code>c</code> can only be a fixed float. </p>
  
  <p>My question is: how do I handle changing parameter c? I could iterate through the entire df recursively to get the answers, but it seems really unsophisticated. </p>
  
  <p>Any advice on how I could approach this problem? Thank you in advance!</p>