Help in construct an indicator(I) based the value of the date and value(V) and the lag value of itself lag(-1)( I)
Posted: 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
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