Help in construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)

For questions regarding programming in the EViews programming language.

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

sudesh
Posts: 51
Joined: Fri Nov 03, 2017 7:30 pm

Help in construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)

Postby sudesh » Fri Nov 03, 2017 8:12 pm

Hi,
For simplicity, suppose I’m working with a time series having data in two columns.
The first column contains weekly dates(D) whereas the second column contains value (V) for each corresponding date.
I’m trying to construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)
Therefore, for each date, it’s look for the value of V and the lag(-1)(I) and based on certain conditions assign a value to (I).
I have 14 conditions as listed below. I have also attached in Excel the time series and expected value of I.
I tried to write the codes but unfortunately it’s not working.
I just starting using Eviews , any help will be greatly appreciated.
My working file is as follows:
'Open working file
wfcreate(wf=QuestionLoop, page=week) w 1999-10-08 @now

'Import data from Excel

import U:\echangeu\DEVISES\Backtesting\Sudesh\Eviews\DataLoop.xlsx range=Data colhead=1 namepos=first na="#N/A" @freq W 1999-10-08 @smpl @all


'Code for the signal
for {code}
series temp = @recode(V}<>na,@trend,na)+1
scalar first = @min(temp)
scalar last = @max(temp)
firstdate=@otod(first)
lastdate=@otod(last)
smpl {firstdate} {lastdate}
series I = 0

' (1) if V >= 2 then signal = -1
SMPL IF V >=2
series I =-1
' (2) if V lies between 1.5 and 2 and signal(-1) > -1 then -0.5

SMPL IF V<2 and V>=1.5 and and I(-1)> -1
series I = -0.5

' (3) if V lies between 1.5 and 2 and signal(-1) = -1 then -1
SMPL IF V<2 and V>=1.5 and I(-1)= -1
series I = -1

' (4) if V lies between 0.5 and 1.5 and signal(-1)=-1 then signal = -1

SMPL IF V<1.5 and V>0.5 and I(-1)=-1
series I = -1

' (5) if V lies between 0.5 and 1.5 and signal(-1)= -0.5 then signal = -0.5

SMPL IF V<1.5 and V>0.5 and I(-1)=-0.5
series I = -0.5

' (6) if V lies between 0.5 and 1.5 and signal(-1)>= 0 then signal = -0.5

SMPL IF V<1.5 and V>0.5 and I(-1)>=0
series I = -0.5

' (7) if V lies between -0.5 and 0.5

SMPL IF V<0.5 and V>-0.5
series I = 0

' (8) if V lies between -1.5 and -0.5 and signal(-1)=1 then signal = 1

SMPL IF V>-1.5 and V<-0.5 and I(-1)=1
series I = 1

' (9) if V lies between -1.5 and -0.5 and signal(-1)= 0.5 then signal =0.5

SMPL IF V>-1.5 and V<-0.5 and I(-1)=0.5
series I = 0.5

' (10) if V lies between -1.5 and -0.5 and signal(-1)<=0 then signal =0.5

SMPL IF V>-1.5 and V<-0.5 and I(-1)<=0.5
series I = 0.5

'(11) if V lies between -2 and -1.5 and and signal(-1) = 1 then 1

SMPL IF V>-2 and V<=-1.5 and I(-1)=1
series I = 1

'(12) if V lies between -2 and -1.5 and and signal(-1) = 0.5 then 0.5

SMPL IF V>-2 and V<=-1.5 and I(-1)=0.5
series I = 0.5

'(13) if V lies between -2 and -1.5 and and signal(-1) <= 0 then 0.5

SMPL IF V>-2 and V<=-1.5 and I(-1)=0.5
series I = 0.5

'(14) if V <= -2 then signal =1

SMPL IF V <=-2
series I = 1

for !horizon=1 to 300

smpl 1970w1 1999w2+!horizon

next
smpl 1970w1 @now
next
Attachments
DataLoop.xlsx
(1.11 MiB) Downloaded 25 times

EViews Matt
EViews Developer
Posts: 313
Joined: Thu Apr 25, 2013 7:48 pm

Re: Help in construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)

Postby EViews Matt » Mon Nov 06, 2017 11:06 am

Hello,

There are several syntax errors in your program. When you're new to EViews, I suggest that you write your program incrementally and in small steps, i.e., write a few lines, run it, and see if it's working correctly. It's much easier to find problems when only a few lines have changed.

Independent of the syntax problems, I believe your program's overall strategy of using samples to separate the different indicator cases isn't going to work because of the dependence on the lagged indicator. I believe you'll find it easier to work with a simple loop containing your cases in if statements. For example, after importing the data from the Excel file,

Code: Select all

smpl if V <> na
I = 0
for !j = 2 to @obssmpl
   if V(!j) >= 2 then
      I(!j) = -1
   else if V(!j) < 2 and V(!j) >= 1.5 and I(!j - 1) > -1 then
      I(!j) = -0.5
   else if V(!j) < 2 and V(!j) >= 1.5 and I(!j - 1) = -1 then
      I(!j) = -1
   else
      ' More cases
   endif
   endif
   endif
   endif
next

sudesh
Posts: 51
Joined: Fri Nov 03, 2017 7:30 pm

Re: Help in construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)

Postby sudesh » Mon Nov 06, 2017 11:17 am

Thanks your for your reply. I will follow your advice.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 44 guests