Using @replace and @word and permutations and combinations

For questions regarding programming in the EViews programming language.

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

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Using @replace and @word and permutations and combinations

Postby cc100 » Tue Jan 19, 2016 4:44 am

Hi,

I have a number of time series of rates so I have 1Y, 2Y, 3Y out to 10Y. I would like to define some other time series which are three point combinations of the individual rate time series - for example 1Y2Y3Y= 1Y+3Y - (2*2Y). I have a list of some of the three point combinations - so i have string names of all the combinations I would like - but I would like to know how to use the @replace or @right and @left functions to write the formula R1YR2YR3Y = R1+R3-(2*R2) (where R1 = the time series for the first rate, R2= the time series for the second rate and R3 = the third rate time series). Please could you help. I was trying to use the @replace function to replace all the Ys with spaces and then use the left function to take everything to the left of the first space etc....but it's not working and i am really am stuck on how to do this. In excel I am doing it by using the ssplit function (but can also be done with mid/left and right).

So trying first with only 2 three point combinations....
svector(2) sfly
sfly(1) = 1Y2Y3Y
sfly(2)=2Y5Y10Y

group g_fly

For !i = 1 to 2
%name = "_"+sfly(!i)
series{%name} = @replace({%name}, "Y", " ")...***then i am very stuck****
.....
g_fly.add{%name}
next i

Also I am going to work out all the three point combinations in excel as I don't know how to program such a thing in eviews. My time series of rates are in a matrix, the first column is the time series for rate1, the second column is the time series for rate 2 etc....the three point combinations are such that rate1<rate2<rate3. So you cannot have 5Y10Y2Y, it must be 2Y5Y10Y..Could you give me some pointers on how to do this in eviews. Ie how to work out all the possible combinations and spit out the names which can then be fed into the above function which will compute each 3point combination....

Thanks

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: Using @replace and @word and permutations and combinatio

Postby cc100 » Tue Jan 19, 2016 5:41 am

I just need pointers or pointers to examples for the permutation/combination problem. What i really would appreciate help with is the first part using the @replace and @left/@right functions in eviews.

Thank you in advance!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Using @replace and @word and permutations and combinatio

Postby EViews Gareth » Tue Jan 19, 2016 6:49 am

I don't really understand what you're trying to do.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: Using @replace and @word and permutations and combinatio

Postby cc100 » Tue Jan 19, 2016 7:21 am

HI Gareth,

Sorry if i wasn't clear - I shall rephrase.

I have time series of interest rates...1Y, 2Y, 3Y, 4Y, 5Y, 6Y, 7Y, 8Y, 9Y,10Y which are in a matrix. So my matrix has 10 columns and multiple rows depending on how far back in time i am looking. Column 1 is the time series for the 1Y rate, column 2 is the time series for the 2Y rate etc...

I want to compute butterfly trades (fly) - which are combinations of three interest rates - so a 1Y2Y3Y butterfly = (1Y*1)+(3Y*1)-(2Y*2). There are other ways to weight such trades, but I am starting with the 1:2:1 weighting - which is 1 of each of the extreme rates and 2 lots of the middle rate. So if the butterfly is R1R2R3, where R1, R2 and R3 are time series of rates, then the calculation is always (R1+R3) - (2*R2). So the butterfly is itself a time series and is a linear combination of R1, R2 and R3.

I have a string vector in eviews of all the butterfly trades i want to compute. Lets for simplicity assume the vector has only two elements which are "1Y2Y3Y" and "2Y5Y10Y". I want to put a loop around this vector where I say look at the first element of the vector which is of the form R1R2R3 and split it into (R1,R2,R3) and then do (R1+R3) - (2*R2) where R1 is column 1 of my matrix, R2 is column 2 and R3 is column 3. Which means I need to extract the column positions for the three individual time series from the first string in the vector to compute the fly.

Worked example:
So lets suppose the string vector has two flies in it "1Y2Y3Y" and "2Y5Y10Y". I want it to 'see' the first element 1Y2Y3Y in the vector and then split this into (1,2,3) - ie remove the Y, and then using this do butterfly 1Y2Y3Y = col(1)+col(3) - 2*col(2). And then add the 1Y2Y3Y fly to a group and then go onto the next element in the vector. The next element is "2Y5Y10Y" - I want it to be split into (2,5,10) and then compute the 2Y5Y10Y fly = col(2)+col(10)-2*col(5) and add this to the butterfly group.

So my issue is how to extract the 3 numbers which are each to the left of the Ys. I have simplified the example. I have more than 10 rates, so the numbers to the left of the Y could be single of double digits. In excel I take the string 1Y2Y3Y and i use the ssplit function to get (1,2,3). I would like to know how to do this in eviews.

Please let me know if this is still not clear and I shall rephrase.

Thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Using @replace and @word and permutations and combinatio

Postby EViews Gareth » Tue Jan 19, 2016 7:43 am

Something like:

Code: Select all

create u 10 string a = "2Y3Y5Y" %b = @replace(a, "Y", " ") scalar val1 = @val(@word(%b,1)) scalar val2 = @val(@word(%b,2)) scalar val3 = @val(@word(%b,3))

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: Using @replace and @word and permutations and combinatio

Postby cc100 » Tue Jan 19, 2016 9:55 am

Thank you very much Gareth - just what I wanted.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: Using @replace and @word

Postby cc100 » Wed Jan 20, 2016 2:22 am

Hi Gareth,

Thanks for the answer above, I have another question please. When i run the following code (below) I get this error message (Test01@col is not defined or is an illegal command in test01@col(1) = mktrates.@col(val1)+mktrates@col(val3) - (2*mktrates@col(val2)). Why does the second to last line in the program fail but 'vector vec = test01.@col(1)' works?
thanks,
--------------------------------

create d5 31/07/2003 18/01/2016

'Download currency data from Bloomberg
dbopen(type=bloom) curncy
fetch "USSW1" "USSW2" "USSW3"

'renaming series
series _1Y = USSW1
series _2Y = USSW2
series _3Y = USSW3

group group01 _1Y _2Y _3Y

'NA fix
for !i=1 to group01.@count
smpl @first @first
%name =group01.@seriesname(!i)
smpl @first @last
{%name} = @recode({%name}=na, {%name}(-1), {%name})
next i

stom(group01, mktrates)

svector(2) fly
fly(1) = "1Y2Y3Y"
fly(2) = "2Y5Y10Y"

string str
matrix(@rows(mktrates), 2) test01
vector vec = test01.@col(1)
group g_DV01F

For !i=1 to 2

string a = fly(!i)
%b = @replace(a,"Y"," ")
scalar val1 = @val(@word(%b,1))
scalar val2 = @val(@word(%b,2))
scalar val3 = @val(@word (%b,3))

test01@col(!i) = mktrates.@col(val1)+mktrates.@col(val3) - (2*mktrates.@col(val2))

Next i

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Using @replace and @word and permutations and combinatio

Postby EViews Gareth » Wed Jan 20, 2016 9:09 am

You can't assign using .@col, you can only retrieve.

You'll need to use the colplace command.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: Using @replace and @word and permutations and combinatio

Postby cc100 » Thu Jan 21, 2016 4:54 am

Thank you!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests