Page 1 of 1

Weighted moving Average

Posted: Thu Nov 05, 2009 11:53 pm
by moni
When I tried to do forcasting for the stoch market return series with Eviews, there was no provision for weighted moving average model (estimation/forecast) as was indicated for the ARCH models. What should I do? Please can someone help me urgently? Rgds

Re: Weighted moving Average

Posted: Fri Nov 06, 2009 2:42 am
by trubador
You can calculate the weighted moving average as shown below. However, please note that it will not work properly if you have NAs in the series.

Code: Select all

call wma(y,10)

subroutine wma(series y,scalar m)
'y is the name of your series
'm is the number that indicates the window size

%name = y.@name
%m = @str(m)
series {%name}_wma_{%m}

  for !i = 0 to @obs({%name})-m
   smpl @first+m-1+!i @first+m-1+!i
    {%name}_wma_{%m} =0
     for !j = 1 to m
      {%name}_wma_{%m} = {%name}_wma_{%m} + (m-!j+1)*{%name}(-!j+1)
     next
  next

smpl @all
{%name}_wma_{%m} = {%name}_wma_{%m}/(m*(m+1)/2)

endsub

Re: Weighted moving Average

Posted: Fri Nov 13, 2009 9:58 pm
by moni
Thank you very much Sir. I am excited and indeed most grateful to you trubador. I still have an issue that am trying to resolve and I shall revert to you shortly on it, if am unable to resolve it. This forum is a wondeful innovation by QMS and a good learning ground. Please do not be weary in assisting learners and software neophytes like us. Rgds and God bless u.

Re: Weighted moving Average

Posted: Sun Aug 01, 2010 1:26 pm
by w_nawfal
Hello

this codes seems to work great but I would like to clarify 2 lines with whomever could help please.

in the line "smpl @first+m-1+!i @first+m-1+!i" why is the first argument repeated?

could anyone clarify this line please " {%name}_wma_{%m} = {%name}_wma_{%m} + (m-!j+1)*{%name}(-!j+1)

Much Appreciated your assistence

WN

Re: Weighted moving Average

Posted: Mon Aug 02, 2010 7:07 am
by EViews Gareth
The smpl command sets the sample. It takes a pair of dates as the arguments, the start date and the end date. Thus if you want the sample to be only one observation, you should use the same date as the start and end date.

That second line is just adding the lagged value of the series to the weighted series.

Re: Weighted moving Average

Posted: Mon Aug 09, 2010 7:59 am
by w_nawfal
Thank You

Cheers