Series Name Challenge ("_" Starting Character Issue)

For questions regarding programming in the EViews programming language.

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

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Sun Mar 28, 2021 1:29 pm

I've got a program that uses stock tickers and, sometimes, CUSIPS as identifiers.

The Tickers work fine, but CUSIPS do not because, when fetching data from Bloomberg, EViews puts a "_" in front of the CUSIP.

The "_" at the start of the CUSIP causes the program to fail.

I'm trying to figure out how to have EViews put an alpha character (any character is fine) other than a "_" when creating a fetched series.

Any and all help would be greatly appreciated!

Kevin

My fetch command:
fetch bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)

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

Re: Series Name Challenge ("_" Starting Character Issue)

Postby EViews Gareth » Sun Mar 28, 2021 6:17 pm

Did you try the p= option on the fetch command?
Follow us on Twitter @IHSEViews

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Sun Mar 28, 2021 6:31 pm

That looks interesting...

How world I use that conditinally? For example, if the symbol/cusip starts with a number then add an “a” as the first character of the created series in n EViews. If the first character is already an “alpha” character then just create the fetched series without adding an “a” to the start of the name of the created series??

Many thanks!

KC

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Mon Mar 29, 2021 11:14 am

I tried putting p=bbrg but I get the following error:

My Code: fetch(p=bbrg_) bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)

Database Error: Bloomberg library error: 'Invalid Security BBRG_ ' in "FETCH(P=BBRG_) BLOOM:: @BDH(MSFT US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)"
Last edited by kcaron on Mon Mar 29, 2021 11:24 am, edited 1 time in total.

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

Re: Series Name Challenge ("_" Starting Character Issue)

Postby EViews Gareth » Mon Mar 29, 2021 11:24 am

If you don't like the "_" could you replace it after the fetch using @replace?
Follow us on Twitter @IHSEViews

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Mon Mar 29, 2021 11:28 am

I tried that yesterday, but couldn't figure out how to write that code.

Any chance you might be able to help?

If it is a cusip (rather than a ticker), I would like to replace the first "_" with a letter value.

KC

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Mon Mar 29, 2021 11:55 am

Here is what I'm trying with Dell's cusip (1683997D)...

When I fetch, EViews creates this series: _1683997D_US_CUR_MKT_CAP

Then, I run this code @replace(_1683997d_us_cur_mkt_cap, "_", "a") to try to replace "_" with "a"... And I get this error:

Non numeric argument in "@REPLACE(_1683997D_US_CUR_MKT_CAP, "_", "A")"


And, what is really causing the issue in the first place is this message which occurs further on down in the code. This is the reason why I think I need to put a letter at the start of the cusips (because this only happens with cusips and not tickers). {%I} is a bunch of tickers and a few cusips that are fed into a loop.

Root Issue:
1683997D_MULT is an illegal or reserved name in "FRML {%I}_MULT = (1683997D_US_CUR_MKT_CAP + (1683997D_US_CUR_MKT_CAP * 1683997D_US_DEBT_TO_MKT_CAP) + 1683997D_US_PREFERRED_EQUITY___MINORITY_INT)/ 1683997D_US_TRAIL_12M_NET_SALES"

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

Re: Series Name Challenge ("_" Starting Character Issue)

Postby EViews Gareth » Mon Mar 29, 2021 12:54 pm

In EViews, object names cannot start with a number, which is why EViews appends the _.

Once the renaming has occurred you cannot refer to the object by its original bbg name since that name doesn’t exist. You have to refer to it by its EViews name.

The first argument to the @replace function must be in quotes
Follow us on Twitter @IHSEViews

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Mon Mar 29, 2021 1:55 pm

Thank you.

I tried putting the reference to the series in quotes, but nothing happens when I run the code.

Series Name: _1683997d_us_cur_mkt_cap
Code: @replace("_1683997d_us_cur_mkt_cap", "_", "a")

Attaching example workfile and program.

I'm thinking that if I can "trick" EViews to stop it from putting "_" in front of CUSIPS (numeric values) and put an alpha character instead, the issue would be solved. The code would need to look at each series fetched; determine if the EViews name begins with a "_"; if yes replace "_" with "a" (or something); otherwise do nothing.

Thanks for your help!

Kevin
Attachments
example_workfile.wf1
(11.87 KiB) Downloaded 135 times
example_program.prg
(48 Bytes) Downloaded 160 times

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

Re: Series Name Challenge ("_" Starting Character Issue)

Postby EViews Gareth » Mon Mar 29, 2021 4:06 pm

Code: Select all

%listof_vars = @wlookup("_*", "series")
for %j {%listof_vars}
   %name = "a" + @mid(%j,2)
   rename {%j} {%name}
next
Follow us on Twitter @IHSEViews

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Tue Mar 30, 2021 3:48 am

Gareth,

Thank you for the code.

Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).

I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.

But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.

K

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Tue Mar 30, 2021 4:21 am

Gareth,

Thank you for the code, but I think there is an even simpler way...

Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).

I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.

But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.

K

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

Re: Series Name Challenge ("_" Starting Character Issue)

Postby EViews Gareth » Tue Mar 30, 2021 7:17 am

Code: Select all

if @val("_") <> NA

is functionally the same as isnumber
Follow us on Twitter @IHSEViews

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Tue Mar 30, 2021 12:05 pm

Ok... Thank you again... I've written this sample code, but get a "is not defined error."
Can you see what I'm doing wrong?

for %i MSFT GE CSCO 1683997D WMT INTC

%cusip = ""

If @val(@left({%i},1)) = 1 then
%cusip = "_"
Endif

next

Error Message: MSFT is not defined in "IF @VAL(@LEFT(MSFT,1)) = 1 THEN"

kcaron
Posts: 88
Joined: Wed Mar 04, 2015 11:46 am

Re: Series Name Challenge ("_" Starting Character Issue)

Postby kcaron » Tue Mar 30, 2021 12:10 pm

Wait! I figured it out!

I need to remove the {} from {%i}!

:-)

KC


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 27 guests