I have an implementation I did.  See below.  I'm not a great programmer in
practice, as my background in CS ended in grad school.  If getSymbols.BB
ended up in quantmod that would be awesome.

requires RBloomberg and FinancialInstrument (it uses the instrument's
setup...an identifier that is mapped to a BBG identifier)


getSymbols.BB <- function(Symbols, env=.GlobalEnv,from,to,...)
{
    importDefaults("getSymbols.OneTick")
    this.env <- environment()

    for (var in names(list(...))) {
        assign(var, list(...)[[var]], this.env)
    }

    if (missing(verbose))
        verbose <- FALSE
    if (missing(auto.assign))
        auto.assign <- TRUE

    if (!("package:RBloomberg" %in% search() || require("RBloomberg",
quietly = TRUE))) {
        stop(paste("package:", dQuote("RBloomberg"), "cannot be loaded"))
    }

    conn <- blpConnect()

    for (i in 1:length(Symbols)) {
        if (verbose) {
            cat(paste("Loading ", Symbols[[i]], paste(rep(".",
                10 - nchar(Symbols[[i]])), collapse = ""), sep = ""))
        }

        myInst = getInstrument(Symbols[i])

        if (missing(from))
            start_date = format(as.Date(myInst$first_traded),"%Y%m%d")
        else
            start_date = format(as.Date(from),"%Y%m%d")

        if (missing(to))
            end_date = format(as.Date(myInst$expires),"%Y%m%d")
        else
            end_date = format(as.Date(to),"%Y%m%d")

        if (as.Date(myInst$expires)>as.Date(Sys.Date()))
            end_date = format(Sys.Date(),"%Y%m%d")

        FLDS <- c("PX_OPEN","PX_HIGH","PX_LOW","PX_LAST")

        rs = bdh(conn,myInst$identifiers$BB,FLDS, start_date = start_date ,
end_date = end_date)

        if (class(rs)!="data.frame") {
            warning(paste(rs[1],rs[2]))
        } else {
            fr <- xts(rs[,-1], order.by=as.POSIXct(rs[,1]), src= "BB",
updated = Sys.time())
            # REORDER TO OHLC columns and rename

            colnames(fr) <- paste(Symbols[[i]], c("Open", "High",
                "Low", "Close"), sep = ".")

            fr = na.omit(fr)
            if (auto.assign)
                assign(Symbols[[i]], fr, env)
            if (verbose)
                cat("done\n")
        }
    }
    blpDisconnect(conn)

    if (auto.assign)
        return(Symbols)
    return(fr)
}

On Wed, Jan 11, 2012 at 10:32 AM, Brian G. Peterson <brian@braverock.com>wrote:

> Yuanhang,
>
> Next time, please start a new thread rather than just replying to
> another post.
>
> Julien is correct that there is no exposed function for
> getSymbols.Bloomberg, and that the RBloomberg package is the right place
> to go to get data out of the Bloomberg terminal.
>
> There is, however, a (start?) of a getSymbols.Bloomberg function in
> quantmod, the code is commented out, and (at best) not completely
> tested, as Jeff (and I right now) don't have easy access to Bloomberg
> terminals.
>
> You can find the code here:
>
>
> https://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/R/getSymbols.R?root=quantmod
>
> see commented lines 93-187
>
> We would of course welcome testing and patches from someone who has
> access to both a Bloomberg terminal and RBloomberg.
>
> Regards,
>
>   - Brian
>
>
> On Wed, 2012-01-11 at 16:03 +0100, julien cuisinier wrote:
> > Hi,
> >
> >
> > As you can see from latest quantmod package doc there is no such
> function, up to the developer to say if they intend to do one.
> >
> > RBloomberg will be your way to access BBG data from R... Then convert
> the data object is uses (I am not familiar with it) into an xts object
> quantmod (& the subsequent tools such as quantstrat) can read / use
> >
> > Thanks to update the list with your findings - especially if I am wrong
> >
> >
> > Rgds,
> > Julien
> >
> >
> >
> > From: yuanhangw.sg@gmail.com
> > Date: Wed, 11 Jan 2012 22:48:59 +0800
> > To: r-sig-finance@r-project.org
> > Subject: Re: [R-SIG-Finance] data manipulation to for quantmod function
> >
> > Hi,
> >
> >     Not sure if this is the right way to seek assistance, but I'm looking
> > for an implementation of getSymbols.bloomberg , could anyone direct me to
> > the right place?
> >
> >
> >
> > Regards,
> > Yuanhang
> >
> > On Wed, Jan 11, 2012 at 5:22 PM, julien cuisinier
> > <j_cuisinier@hotmail.com>wrote:
> >
> > >
> > > Hi,
> > >
> > >
> > > Always nice to have a name on those email.
> > >
> > > quantmod "format" is xts format, you might try as.xts but i guess you
> will
> > > need to give it all the needed columns to fit the XTS object
> > >
> > > OR use quantmod getSymbols function to download the data straight into
> the
> > > right format if possible
> > >
> > >
> > > HTH,
> > > Julien
> > >
> > >
> > >
> > > > From: ktdservices01@gmail.com
> > > > To: r-sig-finance@r-project.org
> > > > Date: Tue, 10 Jan 2012 22:30:33 -0600
> > > > Subject: [R-SIG-Finance] data manipulation to for quantmod function
> > > >
> > > > I need some help with data manipulation so I can use quantmod.
> > > >
> > > > I have a data frame with three columns: time, price, volume.  This
> > > > data frame is all the trades of a product for about 15 days.  What I
> > > > want to do is modify the data so that it is in a format that quantmod
> > > > can read.  Quantmod needs data to be in columns: Open, High, Low,
> > > > Close, and Volume.
> > > >
> > > > I wanted to see if anyone had some suggestions to easily modify the
> > > > data into the quantmod format.
> > > >
> > > > Quantmod: http://www.quantmod.com/
> > > > Data (.csv, 21.67KB) can be downloaded at
> > > http://www.mediafire.com/?fyunce685ekuyo3
> > > >       [[alternative HTML version deleted]]
> > > >
> > > > _______________________________________________
> > > > R-SIG-Finance@r-project.org mailing list
> > > > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > > > -- Subscriber-posting only. If you want to post, subscribe first.
> > > > -- Also note that this is not the r-help list where general R
> questions
> > > should go.
> > >
> > >        [[alternative HTML version deleted]]
> > >
> > > _______________________________________________
> > > R-SIG-Finance@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > > -- Subscriber-posting only. If you want to post, subscribe first.
> > > -- Also note that this is not the r-help list where general R questions
> > > should go.
> > >
> >
> >
> >
> > _______________________________________________
> > R-SIG-Finance@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> should go.
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



-- 
Gei Lin
207 East 30th St, Apt 4H
New York, NY 10016
Cell: (781) 718-8522
Office: (212) 810-8604

Don't quit. Suffer now and live the rest of your life as a champion.

                                                - Muhammad Ali

	[[alternative HTML version deleted]]

