1

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.

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
Kevin Muir
  • 21
  • 3

1 Answers1

1

I figured it out.

I was created the variable to send to the initPortf as a "list". I changed it to a string and it worked.

Specifically, this is the new line

temp_symbol_list <- toString(temp_symbol_list)

I was confused as the documentation for the Blotter package said it was expecting a list, but I probably don't understand the different types of data storage properly.

I'm leaving this up in case someone else has the same problem.

Big thanks to the folks who wrote these packages btw.

Kevin Muir
  • 21
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 13 '23 at 18:03