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