Tmovavg

Description

This function is for calculating triangular moving averages. In fact, this function equals to using function Movavg twice with $n_1=\left \lfloor n/2 \right \rfloor$ backward and 0 forward. Thus, at point = i, the triangular moving average value is:

$T_i = \frac{1}{n_1}\sum_{j=1}^{n_1}S_{j-n_1+i-1},\; \textup{if} \; i >2n_1,$

where $S_j = \frac{1}{n_1}\sum_{k=1}^{n_1}x_{k-n_1+j-1},\; \textup{if} \; j>n1$ and $n_1=\left \lfloor n/2 \right \rfloor$.

Syntax

vector tmovavg(vector vd, int n)

Parameters

vd

The data vector is used to calculate triangular moving average.

n

is the timeperiod.

Return

Return the triangular moving average vector.

Example

// Col(2) will be filled with triangular moving average value at each point,
//with stating point = 9.

for(ii=1;ii<=30;ii++) col(1)[ii] = ii;
col(2)=tmovavg(col(1),9);