continuous future contracts

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Mon Jan 13, 2014 2:12 pm

I think I had to explain it more clearly, my meaning is that, if instead of considering a number (here we consider 5 observations before expiration), we put a specific date, such as 5th April1984, and this date can be changed for different series
Last edited by d952 on Fri Feb 14, 2014 2:13 am, edited 1 time in total.

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Mon Jan 13, 2014 3:54 pm

You can, on the recode do the test condition for that period. I think I'd code the condition using @dateval for the date in question compared with the @date corresponding to the observation.

You can make the inner %s loop go over pairs of string and datestrings, as in

Code: Select all

for %s %t 1985may10 f 1988may20
...
next

Inside each run through the loop %s and %t will be set using the next two elements of the specified set. You can look up the formats for dateval, but it's going to be something like

Code: Select all

pc_merged = @recode(@date<@dateval(%t, "yyyymondd"), pc_merged, {%name})

where the string inside @dateval corresponds to the format with which you specify the break dates.

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Tue Jan 14, 2014 7:47 am

Thank you very much.

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Tue Feb 04, 2014 10:43 am

Dear Glenn, Im really sorry to ask again but these codes are not working or maybe I dont modify them in the correct way, specially in %name somethings are repeating. is it possible for you that make an example for me?
I really appreciate if you do that. many thanks


EViews Glenn wrote:You can, on the recode do the test condition for that period. I think I'd code the condition using @dateval for the date in question compared with the @date corresponding to the observation.

You can make the inner %s loop go over pairs of string and datestrings, as in

Code: Select all

for %s %t 1985may10 f 1988may20
...
next

Inside each run through the loop %s and %t will be set using the next two elements of the specified set. You can look up the formats for dateval, but it's going to be something like

Code: Select all

pc_merged = @recode(@date<@dateval(%t, "yyyymondd"), pc_merged, {%name})

where the string inside @dateval corresponds to the format with which you specify the break dates.

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Tue Feb 04, 2014 12:58 pm

I'm not sure from your description what isn't working. Can you give an example of what you've done and what the problem is?

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Tue Feb 04, 2014 5:09 pm

EViews Glenn wrote:I'm not sure from your description what isn't working. Can you give an example of what you've done and what the problem is?


I think it would be easier if I define a loop for the merging dates then for a long time series is easier to modify and extend, something like:

series pc_merged = pc_clh1984
for !j = 1984 to 2013
for %s f g h j k m n q u v x z
for %t pc_clf1984(7)<>na to pc_clu2013(7)<>na
%name = "PC_CL" + @upper(%s) + @str(!j)

pc_merged = @recode(?????????, {%name})
next
next
next

I dont know if the way that I defined the loop %t is true or not, then how will be the recode also?

Thanks for the help

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Thu Feb 06, 2014 3:57 pm

You're going to have to be a bit clearer about what you want to do.

Right now, each time through the loop we create a %name of the form "PC_CL" plus the elements of the %s loop plus the string representation of the number.
As in the first three times through the loop you'll have

"PC_CLF1984" "PC_CLS1984" "PC_CLH1984"

Now I'm not sure what the roll of %t is in the comparison to follow. I don't *think* you want it as a nested loop, but that's just a guess. Over what comparison variables are you going to be doing the recode? Is there a pattern to the choice?

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Fri Feb 07, 2014 4:24 am

Thnaks for the reply, I want to make a pattern of replacing, for example: series h replace with seies j if series f(7)<>na and this keep continous for all the series that are more than 500 series. if the order of my series are like this: f g h j k m n q u v x z (repeats from 1984 to 2013). then I write the codes like this:

series pc_merged1=@recode(pc_clf1984(7)<>na, pc_clh1984, pc_clj1984)
series pc_merged2=@recode(pc_clg1984(7)<>na, pc_merged1, pc_clk1984)
series pc_merged3=@recode(pc_clh1984(7)<>na, pc_merged2, pc_clm1984)
series pc_merged4=@recode(pc_clj1984(7)<>na, pc_merged3, pc_cln1984)
series pc_merged5=@recode(pc_clk1984(7)<>na, pc_merged4, pc_clq1984)
series pc_merged6=@recode(pc_clm1984(7)<>na, pc_merged5, pc_clu1984)
series pc_merged7=@recode(pc_cln1984(7)<>na, pc_merged6, pc_clv1984)
series pc_merged8=@recode(pc_clq1984(7)<>na, pc_merged7, pc_clx1984)
series pc_merged9=@recode(pc_clu1984(7)<>na, pc_merged8, pc_clz1984)
series pc_merged10=@recode(pc_clv1984(7)<>na, pc_merged9, pc_clf1985)
series pc_merged11=@recode(pc_clx1984(7)<>na, pc_merged10, pc_clg1985)
..........
and it keep continou until 2013.

in order to make it short I creat loops for that in this way:

for !j = 1984 to 2013
for %i h j k m n q u v x z
for %s j k m n q u v x z
for %t f g h j k m n q u v x z

%name1= "PC_CL" + @upper(%i) + @str(!j)
%name2 = "PC_CL" + @upper(%s) + @str(!j)
%name3 = "PC_CL" + @upper(%t) + @str(!j)

series pc_merged1 = @recode({%name3}(7)<>na, {%name1}, {%name2})
next
next
next
next


according to the above code my merged data series should start from pc_clh1984 and end up at pc_clz2013. and the rules is that each series should replace to the next series if 2 series before that is in 7 observation before its expiration, and this should continou for all the series. but I dont undrestand why these codes (both the long one and the loop one)dont work and generate a series that start from 2007 with lotfs of missing values and mess. if you can help me to correct the codes i would be very thankful.

Looking forward to hear from you



EViews Glenn wrote:You're going to have to be a bit clearer about what you want to do.

Right now, each time through the loop we create a %name of the form "PC_CL" plus the elements of the %s loop plus the string representation of the number.
As in the first three times through the loop you'll have

"PC_CLF1984" "PC_CLS1984" "PC_CLH1984"

Now I'm not sure what the roll of %t is in the comparison to follow. I don't *think* you want it as a nested loop, but that's just a guess. Over what comparison variables are you going to be doing the recode? Is there a pattern to the choice?
Last edited by d952 on Fri Feb 07, 2014 7:31 am, edited 1 time in total.

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Fri Feb 07, 2014 10:41 am

I'm not sure I understand your pattern but I don't think you want to do as much loop nesting.
Here are the first set of replacements that you get. Note that the %name1 variable is constant both the inner and next to inner loops.

Code: Select all

pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLQ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLU1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLV1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLX1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLZ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLK1984)

I don't think this is what you want.

And from your description
series h replace with seies[sic] j if series f(7)<>na

Are you replacing based on three series back in your list?

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Fri Feb 07, 2014 10:41 am

EViews Glenn wrote:I'm not sure I understand your pattern but I don't think you want to do as much loop nesting.
Here are the first set of replacements that you get. Note that the %name1 variable is constant both the inner and next to inner loops.

Code: Select all

pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLQ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLU1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLV1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLX1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLZ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLK1984)

I don't think this is what you want.

And from your description
series h replace with seies[sic] j if series f(7)<>na

Are you replacing based on three series back in your list?


exactly, this is what I want to do!

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Fri Feb 07, 2014 10:45 am

d952 wrote:
EViews Glenn wrote:I'm not sure I understand your pattern but I don't think you want to do as much loop nesting.
Here are the first set of replacements that you get. Note that the %name1 variable is constant both the inner and next to inner loops.

Code: Select all

pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLQ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLU1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLV1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLX1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLZ1984<>na, PC_CLH1984, PC_CLJ1984)
pc_merged1 = @recode(PC_CLF1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLG1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLH1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLJ1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLK1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLM1984<>na, PC_CLH1984, PC_CLK1984)
pc_merged1 = @recode(PC_CLN1984<>na, PC_CLH1984, PC_CLK1984)

I don't think this is what you want.

And from your description
series h replace with seies[sic] j if series f(7)<>na


Are you replacing based on three series back in your list?


exactly, this is what I want to do! I want to replace based on information on 3 series back, up to 3 first lines of the codes it works well, after the third line the merged series start to jump down.

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Fri Feb 07, 2014 10:52 am

Please consider that at the end I want to get one merged series that starts at 1984 and ends at 2013, not several series. The description on the line by line codes is exactly what I ant to do, imagine I have 12 series:
series1 series 2 series3 series4 series5 series6 series7 series8 series9 series10 series11 series12

I start with series3, I want series3 return to series4 when series1(7)<>na and generate a new merged series, that if I call it series merged1
in the next step I want series merged1 return to series5 when series2(7)<>na, as a result it generate a new series that is called series merged2
next step series merged2 return to series6 when series3(7)<>na and generate series merged3
and this keep continou untill the series finish....
I want 500 time series that want to merge them together in this way and at this end generate one single series according to the above method. according to my limited knowledge of programming the codes should be correct, I cant find where is the problem. Im so exhausted with this problem :(

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Fri Feb 07, 2014 12:10 pm

So you do want a single merge across all of the years? What are you using to initialize the merged series?
Last edited by EViews Glenn on Fri Feb 07, 2014 12:34 pm, edited 1 time in total.

d952
Posts: 64
Joined: Tue Nov 22, 2011 6:30 am

Re: Create continuous future contracts

Postby d952 » Fri Feb 07, 2014 12:18 pm

EViews Glenn wrote:Do you want a different single merge name for each year? Or a merge across all of the years? If the latter, what are you using to initialize the merged series.


I want a merge across all of the years, I use pc_clh1984 as the first one.

EViews Glenn
EViews Developer
Posts: 2655
Joined: Wed Oct 15, 2008 9:17 am

Re: Create continuous future contracts

Postby EViews Glenn » Fri Feb 07, 2014 1:59 pm

I think that something like

Code: Select all

series pc_merged = PC_CLH1984
for !j = 1984 to 2013
   %name1 = "PC_CLF" + @str(!j)
   %name2 = "PC_CLG" + @str(!j)
   %name3 = "PC_CLH" + @str(!j)
   ' start with series %3
   for %i j k m n q u v x z
      %name4 = "PC_CL" + @upper(%i) + @str(!j)
      ' return to series %4 when series %1(7)<>na
      pc_merged = @recode({%name1}(7)<>na,{%name4}, pc_merged)
      %name1 = %name2
      %name2 = %name3
      %name3 = %name4
   next
next

should do it. If not, some variation of this should work for you. It's probably worth trying to understand what it's doing as all of the tools you'll need are there.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 12 guests