Page 1 of 1

Data Manipulation in a series

Posted: Wed Oct 23, 2013 5:24 am
by psingh
Hi,
I am trying to create a series for signals for past 200 days such that if my signal on previous day was -1 ( exit a trade) ,my position becomes 0 today and if it was 1 on previous day (entry) , my position becomes +1 today. My Entry and exit signals comes from different series.

I am trying to code it like :

for !k=1 to 200
smpl @first+!end -200 @first+!end-(200-!k)
if @last(trade_pos(-1))=-1 then
@elem(trade_pos,!k) = 0
endif
if @last(trade_pos(-1))=1 then
@elem(trade_pos,!k) = 1
endif
next

But this doesn't seem to work. Is there a better way to do this ?

Re: Data Manipulation in a series

Posted: Wed Oct 23, 2013 6:23 am
by startz
Hi,
I am trying to create a series for signals for past 200 days such that if my signal on previous day was -1 ( exit a trade) ,my position becomes 0 today and if it was 1 on previous day (entry) , my position becomes +1 today. My Entry and exit signals comes from different series.

I am trying to code it like :

for !k=1 to 200
smpl @first+!end -200 @first+!end-(200-!k)
if @last(trade_pos(-1))=-1 then
@elem(trade_pos,!k) = 0
endif
if @last(trade_pos(-1))=1 then
@elem(trade_pos,!k) = 1
endif
next

But this doesn't seem to work. Is there a better way to do this ?
Something like

Code: Select all

smpl 2 @last trade_pos=@recode(trade_pos(-1)=-1,0,trade_pos) trade_pos=@recode(trade_pos(-1)=1, 1,trade_pos)

Re: Data Manipulation in a series

Posted: Wed Oct 23, 2013 7:04 am
by EViews Glenn
Startz's @recode does what the original code appears to be doing, but from the description of the problem (not the original code) the entry and exit series come from different sources which can make coming up with an equivalent @recode tricky. In this case, it's easy to do this with samples.

Code: Select all

series trade_pos smpl if exit(-1)=-1 trade_pos = 0 smpl if entry(-1)=1 trade_pos = 1
If entry and exit were the same, @recode would be fine, though I would recode into a new series instead of the existing series.