I am having trouble initializing portfolios with the Blotter Package in R.
I am cycling through a list of variables that I want to initialize, and when I initialize with a single symbol, it works fine.
But when I try to do it with a list of symbols, it throws up the error:
Error in portfolio$symbols[[instrument]] <- new.env(hash = TRUE) : wrong arguments for environment subassignment
Here is my code:
for (i in strategies) {
temp_symbol_list <- as.list(c(portfolio_txns %>%
filter(strategy == i) %>%
select(symbol)))
# temp_symbol_list <- as.list(temp_symbol_list)
print (i)
print (temp_symbol_list)
initPortf(i, temp_symbol_list,initDate = earliest_date, currency = "CAD")
}
When there is only one symbol in the intialize function, it works fine. But if there are two symbols, I get the error.
I have tried many different ways of creating the symbol list, but I think it is expecting something that I am not able to create.
For example, if I do the following:
initPortf("strategy",c("symbol 1","symbol 2"), initDate = earliest_date,
currency = "CAD")
it works fine.
Somehow, my list is the problem.