3.5.2.54 Wmovavg

Description

This function is for calculating weighted moving averages. At point = i, the weighted moving average value is:

W_i = \frac{\sum_{j=1}^n w_j x_{i-n+j}}{\sum_{j=1}^n w_j},\; \textup{if} \; i \geq n, where w_j, (j=1,\cdots , n ) is the weighted value and n is the length of vector vw.

Syntax

dataset wmovavg(dataset vd, dataset vw[, int method])

Parameters

vd

The data vector is used to calculate weighted moving average.

vw

The weight vector is used to weighted the data of interest.

method(2025b)

Optional. Determine which method to use.
  • method = 0 the fast method, old behavior.
  • method = 1 the robust method sorts data in a special way then applies the sum-divide algorithm.


Return

Return the weighted moving average vector.

Example

// Col(3) will be filled with weighted moving average value at each point, 
//with stating point = 10. 

for(ii=1;ii<=30;ii++) col(1)[ii] = ii;  //data vector
for(ii=1;ii<=10;ii++) col(2)[ii] = ii/10; //weight vector
col(3)=wmovavg(col(1),col(2));