Monday, 14 March 2016
Asymmetric filters on time series data in JavaScript
I recently made a change to the ssci.smooth.filter() function in the ssci.js JavaScript library. Here is a lengthier explanation of the change.
One of the changes I’ve made is to add the ability to use asymmetric filters with this function. This is achieved via a setter function that defines the start and end index of the points to apply the filter with reference to the point being adjusted.
To give a concrete example, if we call the point being adjusted ‘n’ and the start is two points before this and the end is two points after then we would set this via:
var example = ssci.smooth.filter()
.data(data)
.filter([0.2,0.2,0.2,0.2,0.2])
.limits([-2,2]);
This is still a symmetric filter and is the default if you don’t use the limits() setter function given the filter used in the example.
However if you had quarterly data and wanted to take a moving average over the year you can now do this via the method used above. This time you will need to use:
var example = ssci.smooth.filter()
.data(data)
.filter([0.25,0.25,0.25,0.25])
.limits([-3,0]);
You can also difference the data using this method:
var example = ssci.smooth.filter()
.data(data)
.filter([-1,1])
.limits([-1,0]);
This is just taking the current point, multiplying it by 1 and subtracting the point before from it.
An explanation of the function can be found here. The source code is here.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment