Max of Series up to and including n lags

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Argh!Views
Posts: 2
Joined: Tue Mar 25, 2014 9:17 am

Max of Series up to and including n lags

Postby Argh!Views » Tue Mar 25, 2014 9:35 am

Hi

I have daily share data in a pool workfile and am trying to find the maximum and minimum values of share prices over a variable number of days.

For example, if I choose 5 days for my maximum and am looking at share AAA, then I want to calculate a series AAA_maxpr_5 = maximum (AAA_price, AAA_price(-1), AAA_price(-2), AAA_price(-3), AAA_price(-4)).

I am having a lot of difficulty in getting this to work correctly in eViews.

Here's a snippet of the program in which I've tried doing this:

Code: Select all

for %share {%top60} 'create and calculate maxPr and minPr series genr {%share}_maxPr_{!entrance} = {%share}_p genr {%share}_minPr_{!exit} = {%share}_p 'set NA values to 0 {%share}_maxPr_{!entrance} = @recode({%share}_maxPr_{!entrance}=na,0,{%share}_maxPr_{!entrance}) {%share}_maxPr_{!exit} = @recode({%share}_maxPr_{!exit}=na,0,{%share}_maxPr_{!exit}) for !i = 1 to !entrance 'handle NA values in lagged price series by setting them equal to the price series {%share}_p_lagged_{!i} = @recode({%share}_p_lagged_{!i}=na, {%share}_p, {%share}_p_lagged_{!i}) 'X=@(X=na,0,X) 'must also handle NA values for shares not in existence yet / missing data... -> best approach? 'have set to 0 for now, this is probably NOT the best approach {%share}_p_lagged_{!i} = @recode({%share}_p_lagged_{!i}=na, 0, {%share}_p_lagged_{!i}) if ( {%share}_maxPr_{!entrance} < {%share}_p_lagged_{!i} ) then {%share}_maxPr_{!entrance} = {%share}_p_lagged_{!i} else'do nothing - no change to {%share}_maxPr_{!entrance} endif next for !i = 1 to !exit 'NA cases handles above if {%share}_minPr_{!exit} > {%share}_p_lagged_{!i} then {%share}_minPr_{!exit} = {%share}_p_lagged_{!i} 'reducing if greater -> min else'do nothing - no change to {%share}_minPr_{!exit} endif next price.add {%share}_p dailyreturns.add {%share}_return maxPr_{!entrance}.add {%share}_maxPr_{!entrance} minPr_{!exit}.add {%share}_minPr_{!exit} next
In particular, I believe it's this part that needs to be changed (but am not sure how):

Code: Select all

if ( {%share}_maxPr_{!entrance} < {%share}_p_lagged_{!i} ) then {%share}_maxPr_{!entrance} = {%share}_p_lagged_{!i} else'do nothing - no change to {%share}_maxPr_{!entrance} endif
Can anyone help?

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

Re: Max of Series up to and including n lags

Postby EViews Gareth » Tue Mar 25, 2014 9:44 am

Have you tried the @movmax function?

Argh!Views
Posts: 2
Joined: Tue Mar 25, 2014 9:17 am

Re: Max of Series up to and including n lags

Postby Argh!Views » Tue Mar 25, 2014 10:16 am

Thanks very much, that works.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests