movprod
Moving product over a sliding window.
Category: Data Import and Analysis > Descriptive Statistics
Syntax
P = movprod(A, wlen)
Product over a window of wlen elements centered on each element.
P = movprod(A, [nb na])
Window of nb elements before and na after the current one, plus the element itself.
Description
At each position movprod multiplies the elements inside the window. At the edges the window is truncated, so the first and last values are products of fewer elements. A typical use is compounding growth factors over a rolling period.
Input arguments
A- Vector or matrix; operates along the first non-singleton dimension.
wlen- Window length. For an even length the window is centered between elements, with one more element before than after.
[nb na]- Elements before and after.
Output arguments
P- Array of the same size as
A.
Example
Product of pairs
movprod([1 2 3 4], 2)
movprod([1 2 3 4], 3)
Output
ans = 1×4
1 2 6 12
ans = 1×4
2 6 24 12