[R-SIG-Finance] RBloomberg warning message

Voss, Kent VOSSK at kochind.com
Thu Jul 9 03:53:12 CEST 2009


Sergey,

I used to have this exact same problem as well.  I put it down to
Bloomberg just hiccups sometimes (it's not just Rbloomberg, I've had the
problem with calls to their API from other languages as well).

To work around it, I wrote a script that essentially downloads the data
to a local text file the first time you successfully get the data, and
then it doesn't go back to Bloomberg for that day.  So in the morning I
have a dedicated script that just goes out to Bloomberg to get the data
I need, and I re-run that script until it runs without warnings...ie.
until I have all the data I need.  Then I run my analysis script which I
don't have to worry about data not being there.  I am not a programmer,
so the script may look awful, but it does work.  

Hopefully you can customize it to suit your purpose.  Good luck.

Kent

# Script (also in attached file)
# Standardized function to simplify downloading Bloomberg data
# The essence of this function is to standardize calls (for me at least)
to Bloomberg
# and also to store retrieved data as a flat file.
# Storing the data as a flat file allows you to run a data retrieval
script
# multiple times if necessary to ensure all the data is downloaded,
before running the analytics
# Once a data element (Instrument + Field) has been downloaded for the
day, the script will get the
# downloaded data and not go back to Bloomberg.  This ensures that once
you've gotten the data for
# the day, that your analytic script won't bomb out b/c the Bloomberg
retrieval hiccupped.
getBBData <- function(Instruments, Field, StartDate, EndDate=Sys.Date(),
ShowDays="week", NAaction="na", Periodicity="daily") {
  library(RBloomberg)

  # Set the path and naming convention for files to stor retrieved data
  filename <- paste("c:/blp/data/",Instruments," ",Field,".txt",sep="")

  # Get the file information to see if it exists
  fileinfo <- file.info(filename)
  mdate <- as.Date(strptime(fileinfo$mtime, format="%Y-%m-%d"))

  # If the file exists, move on to the next step to check the datestamp
  if(!is.na(fileinfo$size[1])) {
    if(fileinfo$size[1] > 20) {
      validfile = TRUE
    } else {
      validfile = FALSE
    }
  } else {
    validfile = FALSE
  }
  # If the file exists and the last modified date is today, read it in
  if((length(Instruments) == 1) & validfile & ((Sys.Date() - mdate[1])
== 0)) {
      Data <- read.zoo(file=filename,header=TRUE,format="%Y-%m-%d")
      Name <- strsplit(Instruments," ")[[1]][1]
      Data <- zoo(data.frame(Data = coredata(Data)), time(Data))
      colnames(Data) <- Name
  } else { # If the file doesn't exist, go out to Bloomberg and get the
data

    # Variables used for function testing
  #  Instruments <- c('SPTR Index','MXEA Index','SPGSCITR Index','FNERTR
Index')
  #  Field <- "PX_LAST"
  #  StartDate <- as.Date('2008-1-1', '%Y-%m-%d')
  #  EndDate <- Sys.Date()

    # Convert the EndDate to a datetime object
    EndTime <- as.POSIXct(EndDate)

    # Calculate the length in days to get data
    BBDateLen <- as.numeric(EndDate - StartDate)

    ## Conect to Bloomberg
    conn <- blpConnect(iface="COM", timeout=12000, show.days=ShowDays,
na.action=NAaction, periodicity=Periodicity)

    ## Get the historical data
    Data <- blpGetData(conn, Instruments, Field, start=as.chron(EndTime
- 86400 * BBDateLen))

    ## Disconnect from Bloomberg
    blpDisconnect(conn)

    ## Convert it to a zoo object  with the appropriate time/dates
    Data <- zoo(coredata(Data),as.Date(time(Data),'%m/%d/%y'))

    # Write the data to a file for subsequent retrieval
    if(length(Instruments) == 1) {
      Name <- strsplit(Instruments," ")[[1]][1]
      Data <- zoo(data.frame(Data = coredata(Data)), time(Data))
      colnames(Data) <- Name
      write.zoo(Data, file=filename)
    }
  } # END if(!is.na(fileinfo$size) & ((Sys.Date() - mdate) == 0)) {

  return(Data)

} #END getBBData <- function(Instruments, Field, StartDate,
EndDate=Sys.Date()) (

-----Original Message-----
From: Ana Nelson [mailto:nelson.ana at gmail.com] 
Sent: Tuesday, July 07, 2009 9:51 AM
To: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] RBloomberg warning message

Hi, Sergey,

A matrix can only handle 1 kind of data. Everything has to be a numeric,
or everything has to be a string. Are you trying to combine different
types of data?

It might be better to try retval="data.frame".

Otherwise, can you provide an example script which reproduces the
problem?

Regards,
Ana



On Tue, Jul 7, 2009 at 3:55 PM, Sergey Goriatchev <sergeyg at gmail.com>
wrote:

> Hello, everyone
>
> I have this very long script, where I call blpGetData many times (I 
> get some data, I do some computations, I output results in and Excel 
> file, I call some other data....)
>
> As the code grew, I started to get the same warning message more and 
> more
> often:
>
> "Warning message:
> In as.matrix.BlpCOMReturn(x) NAs are introduced by coersion"
>
> Basically, blpGetData sometimes does not work!
>
> This message comes up in different parts of the code (in different 
> calls to blpGetData), and since script is very long and runs 
> considerable amount of time, one such error completely messes up the 
> end results.
>
> Does anyone know why blpGetData sometimes fails to execute?
>
> Thanks in advance for help!
>
> Best,
> Sergey
>
> _______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



"EMF <kochind.com>" made the following annotations.
------------------------------------------------------------------------------
The information in this e-mail and any attachments is confidential and intended solely for the attention and use of the named addressee(s). It must not be disclosed to any person without proper authority. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorized to and must not disclose, copy, distribute, or retain this message or any part of it.

==============================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getBBData.R
Type: application/octet-stream
Size: 3163 bytes
Desc: getBBData.R
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20090708/c078db69/attachment.obj>


More information about the R-SIG-Finance mailing list