ANN: RollingFunctions.jl

Roll a function over data (run a windowed function along data).


(abridged from the README)

exports

windowed functions
roll_minimum, roll_maximum, 
roll_mean, roll_median,
roll_std, roll_var, roll_mad, 
roll_sum, roll_prod, roll_norm
how to fill, if desired
FILL_FIRST, FILL_LAST, FILL_BOTH,     # same value used repeatedly    
TAPER_FIRST, TAPER_LAST, TAPER_BOTH   # smaller windows (to `tapered_size`) used, copies last repeatedly    
                                      # note: `tapered_size = max(2, tapered_size)`, needed for coherence
windowed function construction
rolling

use

This example shows how you may create other running functions.
You do not need to define all of the forms, just the ones you want to use.

import StatsBase: middle
using RollingFunctions

const V=Vector # for this post only 

# Roll a function.
# define it
roll_middle{T}(window::Int, data::V{T}) =
    rolling(middle, window, data)
# use it
rolled = roll_middle(window, data)


# Roll a function filling the first part with NaNs.
# define it
roll_middle{T}(FILL_FIRST, window::Int, fill::T, data::V{T})  =
    rolling(FILL_FIRST, middle, window, filler, data)
# specialize it
roll_middle_NaN{T}(window::Int, data::V{T}) =
    roll_middle(FILL_FIRST, window, (T)NaN, data)
# use it
rolled = roll_middle_NaN(window, data)


# Roll a function over weighted windows.
# define it
roll_middle{T}(window::Int, weights::V{T}, data::V{T}) =
    rolling(middle, window, weights, data)
# use it
rolled_weighted = roll_middle(window, weights, data)

4 Likes