Weighted moving Average

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

moni
Posts: 2
Joined: Thu Nov 05, 2009 11:25 pm

Weighted moving Average

Postby moni » Thu Nov 05, 2009 11:53 pm

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

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Weighted moving Average

Postby trubador » Fri Nov 06, 2009 2:42 am

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

moni
Posts: 2
Joined: Thu Nov 05, 2009 11:25 pm

Re: Weighted moving Average

Postby moni » Fri Nov 13, 2009 9:58 pm

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.

w_nawfal
Posts: 69
Joined: Fri Jul 30, 2010 6:58 am
Location: Montreal, Canada
Contact:

Re: Weighted moving Average

Postby w_nawfal » Sun Aug 01, 2010 1:26 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11365
Joined: Tue Sep 16, 2008 5:38 pm

Re: Weighted moving Average

Postby EViews Gareth » Mon Aug 02, 2010 7:07 am

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.
Follow us on Twitter @IHSEViews

w_nawfal
Posts: 69
Joined: Fri Jul 30, 2010 6:58 am
Location: Montreal, Canada
Contact:

Re: Weighted moving Average

Postby w_nawfal » Mon Aug 09, 2010 7:59 am

Thank You

Cheers


Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 1 guest