[R-SIG-Finance] create a new variable in a loop - Rbbg, RBloomberg

Belgarath marco.cora at googlemail.com
Thu Jun 14 16:35:23 CEST 2012


Hello Everyone, 

I have the following code:

-----
securities <- c("SPGLOB", "SPX Index", "SPE Index", "SPTPX Index",
            "SPTSX60 Index", "AS31 Index", "SPA50 Index", "SPLAC Index")
fields <- c("PX_OPEN", "PX_HIGH", "PX_LOW", "PX_LAST", "PX_VOLUME")
startdate <- as.Date("2005-11-16")
enddate <- as.Date(Sys.Date())
BBGData <- bdh(conn, paste(securities[1],"Index",sep=" "), 
               fields, startdate, enddate,
               option_names = c("nonTradingDayFillOption",
"nonTradingDayFillMethod"), 
               option_values = c("NON_TRADING_WEEKDAYS", "PREVIOUS_VALUE"))
BBGData$date=NULL
BBGData2 <- as.xts(BBGData, order.by =as.Date(rownames(BBGData)))

----

I would like to assign BBGData2 to a new variable with the name as
securities[1] in order to be able to package it in a loop and download all
the info for all the securities and create new variables for each. 

More generally how do I create new r variables in a Loop, sort of:

name(securities[1]) <- BBGData2

Alternatively how do I change a variable name, how to change the name of
BBGData2 into SPGLOB for instance; at the next run of the loop the BBGData2
would be recreated anyway.

Thank you.
Regards,
Marco



--
View this message in context: http://r.789695.n4.nabble.com/create-a-new-variable-in-a-loop-Rbbg-RBloomberg-tp4633384.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list