Search code examples
kdb+

How do I calculate the autocorrelation using KDB .ml.ts?


I'm trying to learn how to use .ml.ts.acfPlot[]. Every time I try to create a plot though, I get a single wide bar and nothing else.

I've deliberately used sin[x] here in order to produce some meaningful output.

What am I doing wrong?

\l ml/ml.q
.ml.loadfile`:init.q
\l ../utils/util.q
\l ../utils/graphics.q

x: til 1000
z: sin 0.1 * x
.ml.ts.acfPlot[z;10;0.8]

enter image description here


Solution

  • I have raised a pull request against the project as this looks to be a bug https://github.com/KxSystems/ml/pull/100

    n:til n has been added to create a plot per lag

    You can test it yourself:

    \d .ml
    ts.acfPlot:{[data;n;width]
      acf:ts.i.autoCorrFunction[data;]each n:til n;
      ts.i.plotFunction[data;acf;n;width;"AutoCorrelation"];
      }
    \d .
    

    Fix for acfPlot in jupyter notebook