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

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

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

Re: Weighted moving Average

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   nextsmpl @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

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
Contact:

Re: Weighted moving Average

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)

WN

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

Re: Weighted moving Average

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.

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

Thank You

Cheers