title: # Quantstrat Mistakenly? Warns An Existing Instrument Is Missing
body: <p>We developed our original backtester using a kluge of base R, MATLAB, SAS and spreadsheets but are exploring moving just to quantstrat.  Although we had some questions as to the results which we were trying to understand prior to this post, I just updated R to v3.6.0 and the code stopped working, warning that:  "In getInstrument(symbol) : instrument Cityso.xts not found, please create it first." In fact, "Cityso.xts" is present and used to initialize the portfolio.</p>
  
  <p>I've searched for answers online including: <a href="https://stackoverflow.com/questions/26062096/warning-in-quantstrat">Warning in quantstrat</a>, but this post addresses a slightly different point. Other returns for my search are 
  even less on point.  </p>
  
  <pre><code>getSymbols("C", from = "2017-04-17", to = "2017-05-11", src = "yahoo", adjust = TRUE)
  C &lt;- round (C, 2) # rounding
  C &lt;- C[ , -5:-6] # eliminate columns not used
  l.ent &lt;- c(0,1,0,0,0,0,0,1,1,1,0,0,1,0,0,0,0,0) # five long entry positions
  l.exit &lt;- c(0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,1,0,0) # corresponding five long exit positions (3 day lag)
  Cityso.xts &lt;- merge(C,l.ent,l.exit) # merge indicators in last columns to the right
  make.index.unique(Cityso.xts)  # source of code:  https://github.com/braverock/blotter/issues/51
  
  initdate &lt;- "1999-01-01"
  from &lt;- "2017-04-17"
  to &lt;- "2017-05-11"
  Sys.setenv(TZ="UTC")
  currency("USD")
  stock("C.xts", currency = "USD") # Use stock() to initialize Cityso.xts and 
  </code></pre>
  
  <p>For now, we define trade size and initial equity small and simple to aid in understanding output (which, although there were questions as to output, the code ran without warnings):</p>
  
  <pre><code>tradesize &lt;- 1
  initeq &lt;- 1
  strategy.st &lt;- "firststrat"
  portfolio.st &lt;- "firststrat"
  account.st &lt;- "firststrat"
  rm.strat(strategy.st) # Remove the existing strategy if it exists
  initPortf(portfolio.st, symbols = "Cityso.xts", initDate = initdate, currency = "USD") 
  initAcct(account.st, portfolios = portfolio.st, initDate = initdate, currency = "USD", initEq = initeq)
  initOrders(portfolio.st, initDate = initdate)
  strategy(strategy.st, store = TRUE)
  add.signal(strategy.st, name = "sigThreshold", 
         arguments = list(column = "l.ent", # l.ent column contains indicators added external to quantstrat
            threshold = 0,
            relationship = "gt",
            cross = FALSE),
         label = "l.open.th")
  
  add.signal(strategy.st, name = "sigThreshold", 
         arguments = list(column = "l.exit", # l.ent column contains indicators added external to quantstrat
            threshold = 0,
            relationship = "gt", 
            cross = FALSE), 
         label = "l.end.th")
  test_init &lt;- applyIndicators(strategy.st, mktdata = Cityso.xts)
  test &lt;- applySignals(strategy = strategy.st, mktdata = test_init)
  add.rule(strategy.st, name = "ruleSignal", 
        arguments = list(sigcol = "l.open.th", 
                         sigval = TRUE, 
                         orderqty = 1,
                         ordertype = "market", 
                         orderside = "long", 
                         replace = FALSE, 
                         prefer = "Open"), 
        type = "enter")
  add.rule(strategy.st, name = "ruleSignal", 
        arguments = list(sigcol = "l.end.th",
                         sigval = TRUE, 
                         orderqty = "all",
                         ordertype = "market", 
                         orderside = "long",
                         replace = FALSE, 
                         prefer = "Open"), 
        type = "exit")
  add.rule(strategy = strategy.st, name = "ruleSignal",
        arguments = list(sigcol = "l.open.th", sigval = TRUE, ordertype = "market",
                         orderside = "long", replace = FALSE, prefer = "Open",
                         osFUN = osMaxDollar,
                         tradeSize = tradesize,
                         maxSize = tradesize),
        type = "enter")
  out &lt;- applyStrategy(strategy = strategy.st, portfolios = portfolio.st, debug = TRUE)
  </code></pre>
  
  <p>[The trades show here]</p>
  
  <pre><code>There were 17 warnings (use warnings() to see them)
  warnings()
  1: In getInstrument(symbol) : instrument Cityso.xts not found, please create it first.
  2: In getInstrument(Symbol) :  instrument Cityso.xts not found, please create it first.
  3: In addTxn(Portfolio = portfolio, Symbol = symbol, TxnDate = txntime,  ... :  Instrument Cityso.xts  not found, using contract multiplier of 1
  </code></pre>
  
  <p>Of course, later code does not work, insisting that Cityso.xts is not present, when it is.<br>
    Why did this code stop working when I moved to R version 3.6.0?</p>