[R-SIG-Finance] Problem with RBloomberg retval argument

Sergey Goriatchev sergeyg at gmail.com
Tue Jan 20 09:04:20 CET 2009


Dear Ana, Dirk, and Michael

Thank you for your replies, I appreciate that!

Now, let me take is point by point:

1) Ana, I tried retval="data.frame" with just one ticker and that did
not work either. In this particular case I need to load 16 variables
from Bloomberg, and merging them all (given retval="data.frame" were
working) would be quite a hassle. Even though I love to mess about
with R code, this time I am trying to avoid any unneccessary work. :-)

2) Dirk, I tried the same retrieval with retval set to matrix, zoo,
and raw, and it always worked. In fact, in this particular case, like
I mentioned above, I am retrieving 16 instruments from Bloomberg, 20
years of data for each. With zoo it works without a hitch. I am quite
familiar with zoo package, well, I worked with it extensively, but
some of the characteristics of zoo make me prefer data.frame, probably
because I am not a real expert user when it comes to handling zoo
objects.

3) Michael, I have already extensively explored the Bloomberg-Excel-R
route, pulling long histories for about a hundred instruments into
different sheets in an Excel file, then running background VBA code
that prepares the sheet for R, then cleaning, converting, merging
certain variables from different sheets of Excel file in R. I played
around with zoo objects while doing that. Wrote a long piece of code
to massage the data into specific format for use with
PerformanceAnalytics (lovely package, btw, but timestamp handling was
a beatch for me, can't wait when the guys improve that package!). I am
quite proud of the code I wrote, though for experienced R users it
will most likely seem crude and verbose. That is why I am trying to
avoid any unnecessary steps and want to load data into R directly from
Bloomberg.

With respect to zoo object I have a question. When I load data from
Bloomberg into a zoo object (called bldata, for example), I can do
head(bldata) and I see first rows of the array, with timestamps and
column names. I tried to save bldata and open it on a different
machine running R, and though bldata is still a zoo object, doing
head(bldata) only brings up first few rows of the first column (like a
vector) without timestamps and colname. I tried to save bldata as a
.RData file, and I tried to save the whole workspace and then move it
to another R machine - same result. This is the problem with
timestamps, as far as I understand. If I do something like
attributes(bldata)[[2]] <- dates, where dates is a previously saved
column of the timestamps (in character format), then head(bldata)
works normal again. I wonder if there is any way to transfer bldata
between machines without loosing the formating?

Finally, thank you for your explanation of 1899 timestart. For some
reason, I always thought 01-01-1970 was the day from which count
begins in R.

Regards,
Sergey

On Mon, Jan 19, 2009 at 18:30, Michael Sankowski
<michael.sankowski at gmail.com> wrote:
> For very large data pulls with Bloomberg, I found it easier to pull into
> excel and then use read.table to get into R.   Like Dirk said, for some
> reason, Bloomberg does not like it when are greedy with data pulls.
> I pulled fundamental data across the Russell 3000 for a long time period
> into excel and then loaded into xts.  It was easier to check if the data was
> all there visually, then push into R.
> I used this code to create the xts objects from the flat files.
> f.import_data <- function(datamatrixfile) {
> #11/01/08
> jj.holder <- read.table(datamatrixfile, header = TRUE, row.names = 1, sep =
> '\t')
> xts.datamatrix <- xts(jj.holder, as.Date(rownames(jj.holder), format =
> '%m/%d/%Y'))
> return(xts.datamatrix)
> }
> HTH
>
> On Mon, Jan 19, 2009 at 11:04 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
>>
>> On 19 January 2009 at 17:24, Sergey Goriatchev wrote:
>> | Hello everyone,
>> |
>> | I have two issues that I want to ask.
>> |
>> | 1)
>> | I have problems with loading data with RBloomberg.
>> | More precisely, I do not seem to be able to load data into a data.frame.
>> | I get an error message:
>> |
>> | start.date    <- as.chron("1990-01-19")
>> | end.date      <- as.chron("2009-01-19")
>> |
>> | conn <- blpConnect(show.days="week", na.action="na",
>> periodicity="daily")
>> |
>> | > bldata <- blpGetData(conn, c("ED4 Comdty", "ED12 Comdty"), "PX_LAST",
>> start=start.date, end=end.date, retval="data.frame")
>> | Error in if (typ[n] == "character") { : argument is of length zero
>> |
>> | What does that error message mean and what can I do to avoid this error
>> message?
>>
>> Your problem is not really in the assignment to bldata. Your problme is
>> indicated by the 'argument is of length zero': you didn't get any data
>> from
>> Bloomberg.  You need to fix that first.  As a first guess, try a less
>> 'greedy' retrieval.  You are unlikely to get 20 years of daily data in one
>> request.
>>
>> | 2)
>> | If I load data from Bloomberg in matrix format, the date is converted
>> | to a number. For example:
>> |
>> | > bldata <- blpGetData(conn, "ED4 Comdty", "PX_LAST", start=start.date,
>> end=end.date, retval="matrix")
>> | > head(bldata)
>> |      [DATETIME] PX_LAST
>> | [1,]      32892   91.36
>> | [2,]      32895   91.37
>> | [3,]      32896   91.38
>> | [4,]      32897   91.38
>> | [5,]      32898   91.34
>> | [6,]      32899   91.28
>> |
>> | I tried to convert the number to normal date and by trial and error I
>> | found the following:
>> |
>> | > as.Date(32892, "1899-12-30")
>> | [1] "1990-01-19"
>> |
>> | Is it really true that count starts from December 30th 1899? Why?
>>
>> Different offsets for 'the first known day' between different applications
>> and systems, eg Excel uses something very different from Unix etc.
>>
>> Try return type 'zoo' instead of matrix -- zoo is a class that knows how
>> to
>> deal with dates.  You may need to run    install.packages("zoo")   first.
>>
>> Hope this helps, Dirk
>>
>> --
>> Three out of two people have difficulties with fractions.
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>
>
>
> --
> Michael Sankowski, CFA, CAIA
> 312.404.8717
> michael.sankowski at gmail.com
>



-- 
I'm not young enough to know everything. /Oscar Wilde
Experience is one thing you can't get for nothing. /Oscar Wilde
When you are finished changing, you're finished. /Benjamin Franklin
Tell me and I forget, teach me and I remember, involve me and I learn.
/Benjamin Franklin
Luck is where preparation meets opportunity. /George Patten



More information about the R-SIG-Finance mailing list