I am trying to pull historical data for several securities over a single date range. I am able to get the data I want using the code below but the resulting list produces a date column for every security. I would like to see the date in the first, left-most column and then the security field data (px_last, etc) for every security in my list in the columns to the right. I know in BBG with excel I can use an override (dts = H) to hide the date field but I want the left-most column in my list to populate the date,
sec <- c("SPX Index","SX5E Index")
lb <- 5
startdate <- Sys.Date() - lb
opt <- c("periodicitySelection"="DAILY","nonTradingDayFillOption"="NON_TRADING_WEEKDAYS","nonTradingDayFillMethod"="PREVIOUS_VALUE")
dat <- bdh(sec,fields="px_last",start.date = startdate,options=opt)
Returns:
$`SPX Index`
date px_last
1 2016-12-19 2262.53
2 2016-12-20 2270.76
3 2016-12-21 2265.18
4 2016-12-22 2261.03
$`SX5E Index`
date px_last
1 2016-12-19 3257.85
2 2016-12-20 3279.41
3 2016-12-21 3270.75
4 2016-12-22 3262.11
I would like to see three columns instead of four. Col1 is date, Col2 is SPX Index px_last, Col3 is SX5E Index px_last. Thank you
You just merge by hand afterwards.
Start by redoing your code:
We see that we have a list of
data.frame
types. We will make that a list ofxts
object (which is why we loaded that package above), then merge the list elements and set column names: