The trick is that the measurements are only available at irregular intervals. If they were sampled regularly, then the standard mixing trick would work:
mn+1=μmn+(1−μ)xn+1
where m is our current estimate of the mean, xn is the n-th sample and μ determines how much history to use.
With unequal sample times, things become a bit more complicated. If we get lots of measurements all at once, we want to give them nearly equal weight but if we have a long gap, we want to weight the very old samples much less.
In fact, we want to weight old samples according to how old they are with exponentially decreasing weight. If we sample values {x1…xn} at times t1…tn then we want the weighted mean defined by
mn=∑ni=1xie−(tn−ti)/α∑ni=1e−(tn−ti)/α
Here α plays the same role as μ did before, but on a different scale. If the evenly sampled data comes at time intervals Δt then μ=eΔt/α.
Happily, there is a very simple recurrence relationship that allows us to keep only two intermediate values while computing the value of m1…mn in an entirely on-line fashion as the xi values arrive.
To see this, define
πn=e−(tn+1−tn)/αwn+1=n+1∑i=1e−(tn+1−ti)/α=1+e−(tn+1−tn)/αn∑i=1e−(tn−ti)/α=1+πwnsn+1=n+1∑i=1xie−(tn+1−ti)/α=xn+1+e−(tn+1−tn)/αn∑i=1xie−(tn−ti)/α=xn+1+πnsn
Then note that
mn+1=sn+1wn+1
This leads naturally to a procedure that has state consisting of t,w,m which are updated with using new values of tn,xn according to
π=e−(tn−t)/αw=1+πws=xn+πsm=swt=tn
Isn't that a kick!
To do this right, however, we need a test. Here are some data vectors computed for α=5:
t x pi w s m
1 11.35718 1.5992071 1.0000000 1.000000 1.5992071 1.5992071
2 21.54637 -1.3577032 0.1303100 1.130310 -1.1493105 -1.0168100
3 28.91061 -0.3405638 0.2292718 1.259148 -0.6040683 -0.4797436
4 33.03586 0.7048632 0.4382129 1.551775 0.4401527 0.2836447
5 39.57767 0.3020558 0.2702621 1.419386 0.4210124 0.2966159
7 comments:
Ted, pardon my bad math, but I dont understand how you are calculating pi in your example. I can't get to .13031 no matter what I do. ln .13031 is -2 ish, which doesn't seem to come from t1 - t0, which is about 10 - what am I missing?
Thanks,
Nathan
Nathan,
The issue is that I dropped a division by α in the expression for π. For the example, α=5 so for the second line, π=exp−(21.54637−11.35718)5=e−2.04=0.1303101
And, by the way, thanks for noticing that. There was also a missing minus sign on an earlier expression that I found as a result of looking for the problem you spotted.
Let me know if you have any other problems with this.
That worked, thank you much. Your CAPTCHA is nearly impossible, BTW. Or maybe I'm a robot and it is just doing its job. :)
Just as an FYI to anyone ending up here, there's a truly excellent paper with many useful online time-series operators for inhomogeneous data:
http://www.thalesians.com/archive/public/academic/finance/papers/Zumbach_2000.pdf
Excellent paper!
very useful article
thanks
this link
http://www.thalesians.com/archive/public/academic/finance/papers/Zumbach_2000.pdf
is really great, too
thanks
Post a Comment