fetching data from bloomberg

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

fetching data from bloomberg

Postby cc100 » Thu Jul 23, 2015 4:22 am

Hi - I am fetching some data from bloomberg using the following syntax:
dbopen(type=bloom) curncy
'fetching data
fetch <ticker names>...

I see that it is pulling the data for everyday and leaves the cells blank if there is no data for that day - as such I have time series of equal length but with each having some missing data points. What is the command in the code to say if there is no data for that date take the reading from the day before? I need my time series to be complete (ie a data point for each day) and of equal length

Thanks

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

Re: fetching data from bloomberg

Postby cc100 » Thu Jul 23, 2015 4:47 am

actually in my previous post I need some statement that says if no data is available on any given date then take the last available data point for that date (as opposed to specifying the day before - as there may be no available data for the day before either). Thanks.

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

Re: fetching data from bloomberg

Postby EViews Glenn » Thu Jul 23, 2015 7:52 am

You can't do it on the fetch, but you can do it after the fact. by generating into a new series. I think this should work:

Code: Select all

smpl @all yadj = @recode(y=na, y(-1), y)
[edit] This assumes that the first observation for the original Y is valid.

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

Re: fetching data from bloomberg

Postby cc100 » Thu Jul 23, 2015 11:26 am

Great thanks Glenn - it works with the arguments the other way round. thanks for the help

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

Re: fetching data from bloomberg

Postby EViews Glenn » Thu Jul 23, 2015 1:22 pm

Actually that last one needs to be modified a bit to handle multiple missings in a row

Code: Select all

smpl @first @first series yadj = y smpl @first+1 @last yadj = @recode(y=na, yadj(-1), y)

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

Re: fetching data from bloomberg

Postby cc100 » Thu Jul 23, 2015 1:38 pm

Thanks Glenn! - I will run it tomorrow on my eviews!

Sorry if this is a basic question (am new to programming in eviews). I have a question on the fetch function. I am pulling time series from bloomberg with the following code:

dbopen(type=bloom) currency
fetch "USSA1" "USSA2" "USSA3" etc....

Later I rename the series one at a time as some of the bloomberg names are not intuitive

series _1= USSA1
series _2 =USSA2
....

My question is how is it that command fetch takes in strings but then I can declare series with the names of those strings. Also How can i apply your code over all the series that the fetch returns without having to assign them all to a different variable (ie _1, _2 etc...)

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

Re: fetching data from bloomberg

Postby EViews Gareth » Thu Jul 23, 2015 1:53 pm

The fetch command doesn't really take in strings per se. It takes in the names of the series to be fetched. Not you do not have to enclose those names in quotes generally. However since some database formats allow spaces in the names of their series, which would kill the fetch command in EViews, we allow you to enclose the name in quotes to handle the spaces.

You will have to create a for loop that loops over all the series you have brought in and apply Glenn's code one at a time in the loop.

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

Re: fetching data from bloomberg

Postby cc100 » Thu Jul 23, 2015 2:03 pm

Thanks Gareth - that's a lot clearer now! One more thing, how do i loop over all the series without having to write out all the names. Do i put the series into a group then loop through the series say from i to 10 (if there are 10 series) in the group? Also how do I create the group without typing out all the series names again (I'm pulling in over a 100 series so I am trying to avoiding printing out all the names over and over. Thanks again for all the help - I really appreciate it.

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

Re: fetching data from bloomberg

Postby EViews Gareth » Thu Jul 23, 2015 2:14 pm

You can create the group, that's certainly one way to go. Group creation accepts wildcards, so if the series have a naming pattern, you could use a wildcard.

Or you could use the @wlookup function to return the names of the series in your workfile (again matching a pattern if you wanted).

But, if you're fetching all the series in the same program, you must already have the names of the 100 series in the program some how to begin with.

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

Re: fetching data from bloomberg

Postby cc100 » Sat Jul 25, 2015 1:27 pm

Thanks for all the help

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

Re: fetching data from bloomberg

Postby cc100 » Tue Aug 04, 2015 2:19 am

HI Gareth/Glenn,

The following code you suggested to remove NAs and to fill in the blanks with the data from the day before, deletes the first row of data when i convert the group to a matrix:

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

When i type matrix m1 = @convert(group01) or when I do stom(group01, m1) the matrix has one less row that the length of the series in the group even though cell 1 in each of the series in the group is populated with a value. How can I fix this please?

Thanks

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

Re: fetching data from bloomberg

Postby cc100 » Tue Aug 04, 2015 2:32 am

I understand I just take out the +1 i.e smpl @first @last instead of @first+1 @last. But I am not sure how then to deal with the first value in a series possibly being an NA

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

N/A fix

Postby cc100 » Mon Dec 21, 2015 9:14 am

HI Gareth/Glenn,

I've asked you this before (sorry for asking again)...N/A fixes with data from bloomberg. Sometimes the code work and sometimes it doesn't, is seems my code doesn't clear out an N/A if it appears at the first entry in a series, could you tell me what is wrong with the following please:

'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

Thanks!

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

Re: fetching data from bloomberg

Postby EViews Gareth » Mon Dec 21, 2015 9:21 am

You're replacing NAs with the previous value. If the first value is NA, there is no previous value to replace it with, so it stays an NA.

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

Re: fetching data from bloomberg

Postby cc100 » Tue Dec 22, 2015 4:42 am

yes of course, sorry


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests