OPEN-SOURCE SCRIPT

Multivariate Kalman Filter

71
🙏🏻 I see no1 ever posted an open source Multivariate Kalman filter on TV, so here it is, for you. Tested and mathematically correct implementation, with numerical safeties in place that do not affect the final results at all. That’s the main purpose of this drop, just to make the tool available here. Linear algebra everywhere, Neo would approve 4 sure.

...

Personally I haven't found any real use case of it for myself, aside from a very specific one I will explain later, but others usually do…

Almost every1 in the quant industry who uses Kalman is in fact misusing it, because by its real definition, it should be applied to Not the exact known values (e.g as real ticks provided by transparent audited regulated exchange), but “measurements” of those ‘with errors’.

If your measurements don’t have errors or you have real precise data, by its internal formulas Kalman will output the exact inputs. So most who use it come up with some imaginary errors of sorts, like from some kind of imaginary fair price etc. The important easy to miss point, the errors of your measurements have to be symmetric around its mean ‘at least’, if errors are biased, Kalman won’t provide.

For most tasks there are better tools, including other state space models, but still Multivariate Kalman is a very powerful instrument, you can make it do all kinds of stuff. Also as a state space model it can also provide confidence & prediction intervals without explicit calculations of dem.

...

In this script I included 2 example use cases, the first one is the classic tho perfectly working misuse, the second one is what I do with it:


One
Naive, estimates “hidden” adaptive moving regression endpoint. The result you can see on the chart above. You can imagine that your real datapoints are in fact non perfect measures of some hidden state, and by defining measurement noise and process noise, and by constructing the input matrixes in certain ways, you can express what that state should be.

Two
Upscaling tick lattice, aka modelling prices as if native tick size would’ve been lower. Kinda very specific task, mostly needed in HFT or just for analytical purposes. Some like ZN have huge tick sizes, they are traded a lot but barely do more than 20 ticks range in a session. The idea is to model raw data as AR2 process, learn the phi1 and phi2, make one point forecasts based on dem, and the process noise would be the variance of errors from these forecasts. The measurement noise here is legit, it’s quantization noise based on tick size, no need in olympic gold in mental gymnastics xd

لقطة
^^ artificially upscaling ZN futures tick lattice

...

I really made it available there so You guys can take it and some crazy ish with it, just let state space models abduct your conciseness and never look back






إخلاء المسؤولية

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.