You may pad the result with the value of your choice

padding is a keyword argument

  • if you assign e.g. padding = missing, the result will be padfirst
  • you may pad using any defined value and all types except Nothing
  • example pads(missing, 0, nothing, NaN, 'โˆ…', AbstractString)
using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Ž = [1, 2, 3, 4, 5]
๐น๐‘ข๐‘›๐‘ = sum
๐‘†๐‘๐‘Ž๐‘› = 3

result = rolling(๐น๐‘ข๐‘›๐‘, ๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›; padding = missing);
#=
julia> result
5-element Vector{Union{Missing, Int64}}:
   missing
   missing
  6
  9
 12
=#
 
result = rolling(๐น๐‘ข๐‘›๐‘, ๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›; padding = zero(eltype(๐ท๐‘Ž๐‘ก๐‘Ž));
#=
julia> result
5-element Vector{Int64}:
  0
  0
  6
  9
 12
=#

Give me the real values first, pad to the end.

result = rolling(๐น๐‘ข๐‘›๐‘, ๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›; padding = missing, atend=true);
#=
julia> result
5-element Vector{Union{Missing,Int64}}:
  6
  9
 12
  missing
  missing
=#

technical aside: this is not the same as reverse(rolling(๐น๐‘ข๐‘›๐‘,๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›; padding = zero(eltype(๐ท๐‘Ž๐‘ก๐‘Ž)).

padding matrices

using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Žโ‚ = [1, 2, 3, 4, 5] ๐ท๐‘Ž๐‘ก๐‘Žโ‚‚ = [5, 4, 3, 2, 1] ๐ท๐‘Ž๐‘ก๐‘Žโ‚ƒ = [1, 2, 3, 2, 1]

๐‘€ = hcat(๐ท๐‘Ž๐‘ก๐‘Žโ‚,๐ท๐‘Ž๐‘ก๐‘Žโ‚‚,๐ท๐‘Ž๐‘ก๐‘Žโ‚ƒ) #= 5ร—3 Matrix{Int64}: 1 5 1 2 4 2 3 3 3 4 2 2 5 1 1 =#

๐น๐‘ข๐‘›๐‘ = sum ๐‘†๐‘๐‘Ž๐‘› = 3

result = rolling(๐น๐‘ข๐‘›๐‘, ๐‘€, ๐‘†๐‘๐‘Ž๐‘›; padding=missing) #= 5ร—3 Matrix{Union{Missing,Int64}}: missing missing missing missing missing missing 6 12 6 9 9 7 12 6 6 =#

Give me the real values first, pad to the end.

result = rolling(๐น๐‘ข๐‘›๐‘, ๐‘€, ๐‘†๐‘๐‘Ž๐‘›; padding = missing, atend=true) #= 5ร—3 Matrix{Union{Missing,Int64}}: 6 12 6 9 9 7 12 6 6 missing missing missing missing missing missing =#

multicolumn padding

You may pad the result with the value of your choice

padding is a keyword argument

  • if you assign e.g. padding = missing, the result will be padfirst
  • you may pad using any defined value and all types except Nothing
  • example pads(missing, 0, nothing, NaN, 'โˆ…', AbstractString)
using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Žโ‚ = [1, 2, 3, 4, 5]
๐ท๐‘Ž๐‘ก๐‘Žโ‚‚ = [5, 4, 3, 2, 1]

๐น๐‘ข๐‘›๐‘ = cov
๐‘†๐‘๐‘Ž๐‘› = 3

result = rolling(๐น๐‘ข๐‘›๐‘, ๐ท๐‘Ž๐‘ก๐‘Žโ‚, ๐ท๐‘Ž๐‘ก๐‘Žโ‚‚, ๐‘†๐‘๐‘Ž๐‘›; padding = zero(eltype(๐‘€)))

#=
julia> result
5 element Vector {Float64}:
  0.0
  0.0
 -1.0
 -1.0
 -1.0
=#

Give me the real values first, pad to the end.

result = rolling(๐น๐‘ข๐‘›๐‘, ๐ท๐‘Ž๐‘ก๐‘Žโ‚, ๐ท๐‘Ž๐‘ก๐‘Žโ‚‚, ๐‘†๐‘๐‘Ž๐‘›; padding = missing, atend=true)

#=
5 element Vector {Float64}:
 -1.0
 -1.0
 -1.0
  missing
  missing
=#