Page 1 of 1

fetching data from bloomberg

Posted: Thu Jul 23, 2015 4:22 am
by cc100
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

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 4:47 am
by cc100
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.

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 7:52 am
by EViews Glenn
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.

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 11:26 am
by cc100
Great thanks Glenn - it works with the arguments the other way round. thanks for the help

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 1:22 pm
by EViews Glenn
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)

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 1:38 pm
by cc100
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...)

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 1:53 pm
by EViews Gareth
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.

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 2:03 pm
by cc100
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.

Re: fetching data from bloomberg

Posted: Thu Jul 23, 2015 2:14 pm
by EViews Gareth
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.

Re: fetching data from bloomberg

Posted: Sat Jul 25, 2015 1:27 pm
by cc100
Thanks for all the help

Re: fetching data from bloomberg

Posted: Tue Aug 04, 2015 2:19 am
by cc100
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

Re: fetching data from bloomberg

Posted: Tue Aug 04, 2015 2:32 am
by cc100
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

N/A fix

Posted: Mon Dec 21, 2015 9:14 am
by cc100
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!

Re: fetching data from bloomberg

Posted: Mon Dec 21, 2015 9:21 am
by EViews Gareth
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.

Re: fetching data from bloomberg

Posted: Tue Dec 22, 2015 4:42 am
by cc100
yes of course, sorry