Page 1 of 2
Series Name Challenge ("_" Starting Character Issue)
Posted: Sun Mar 28, 2021 1:29 pm
by kcaron
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)
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Sun Mar 28, 2021 6:17 pm
by EViews Gareth
Did you try the p= option on the fetch command?
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Sun Mar 28, 2021 6:31 pm
by kcaron
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 11:14 am
by kcaron
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)"
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 11:24 am
by EViews Gareth
If you don't like the "_" could you replace it after the fetch using @replace?
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 11:28 am
by kcaron
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 11:55 am
by kcaron
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"
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 12:54 pm
by EViews Gareth
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 1:55 pm
by kcaron
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Mon Mar 29, 2021 4:06 pm
by EViews Gareth
Code: Select all
%listof_vars = @wlookup("_*", "series")
for %j {%listof_vars}
%name = "a" + @mid(%j,2)
rename {%j} {%name}
next
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Tue Mar 30, 2021 3:48 am
by kcaron
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Tue Mar 30, 2021 4:21 am
by kcaron
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
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Tue Mar 30, 2021 7:17 am
by EViews Gareth
is functionally the same as isnumber
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Tue Mar 30, 2021 12:05 pm
by kcaron
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"
Re: Series Name Challenge ("_" Starting Character Issue)
Posted: Tue Mar 30, 2021 12:10 pm
by kcaron
Wait! I figured it out!
I need to remove the {} from {%i}!
:-)
KC