5

When using the function initPortf to initialize portfolio in package blotter in R, we can initialize a portfolio, such as:

currency("USD")
stock("SPY",currency="USD",multiplier=1)
b.strategy <- "bFaber"
initPortf(b.strategy,'SPY', initDate='1997-12-31') 

But when we want to initialize the portfolio again, we must delete the portfolio b.strategy first:

initPortf(b.strategy, "SPY", initDate = "1997-12-31") : 
Portfolio bFaber already exists, use updatePortf() or addPortfInstr() to update it.

the rm() could not be used here, when I need to delete it, I have to clear all of the workspace. Is there any function to delete it?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
PepsiCo
  • 1,399
  • 4
  • 13
  • 18

1 Answers1

4

All of the quantstrat demo scripts do something like this:

suppressWarnings(rm("account.bFaber","portfolio.bFaber",pos=.blotter))
suppressWarnings(rm("order_book.bFaber",pos=.strategy))
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418