Reputation: 1743
Im trying to create a column using the RBLPAPI BDH
StockMove <- function(ticker){
StockMove <- bdh("MSFT Equity", "Chg_Pct_1D", x$Date, x$Date)
colnames(ernmove) <- NULL
ernmove <- ernmove[,2]
}
but I keep getting the error
Error in eval(substitute(expr), envir, enclos) : expecting a single value
Called from: bdh_Impl(con, securities, fields, start.date, end.datee, options, overrides, verbose, identity)
x$Date is a column of historic dates, and I am trying to create a new column and pull BDH data for each row corresponding to the x$Date column in that row. . As a sanity check, I used Sys.Date() in place of the x$Date input and it works correctly.
Thanks for any advice, this is my first question so apologies for any errors.
Upvotes: 1
Views: 1213
Reputation: 1164
You say x$Date is a column of dates. BDH wants a start date and end date. I think that's what the error is telling you. You're giving it a column where it wants a single value.
I haven't written any R in forever so forgive me is this is buggy:
startDate <- min(x$Date)
endDate <-max(x$Date)
bdh("MSFT Equity", "Chg_Pct_1D", startDate, endDate)
BDH is not well suited to retrieving data from a predetermined list of dates. And not even one date at a time, because holidays have empty data unless you use an override to fill them in.
Instead, I always retrieve the full range of dates from start to end with BDH. If I have a column of specific dates that I need, I look them up in that result.
Upvotes: 1