title: Filter xts objects by common dates
body: <p>I am stuck with the following code.</p>
  
  <p>For reference the code it is taken from the following website (<a href="http://gekkoquant.com/2013/01/21/statistical-arbitrage-trading-a-cointegrated-pair/" rel="nofollow">http://gekkoquant.com/2013/01/21/statistical-arbitrage-trading-a-cointegrated-pair/</a>), I am also compiling the code through R Studio.</p>
  
  <pre><code>library("quantmod")
  
  startDate = as.Date("2013-01-01")
  symbolLst&lt;-c("WPL.AX","BHP.AX")
  
  symbolData &lt;- new.env() 
  getSymbols(symbolLst, env = symbolData, src = "yahoo", from = startDate)
  
  stockPair &lt;- list(
     a =coredata(Cl(eval(parse(text=paste("symbolData$\"",symbolLst[1],"\"",sep="")))))
    ,b = coredata(Cl(eval(parse(text=paste("symbolData$\"",symbolLst[2],"\"",sep="")))))
    ,hedgeRatio = 0.70   ,name=title)
  
  spread &lt;- stockPair$a - stockPair$hedgeRatio*stockPair$b
  </code></pre>
  
  <p>I am getting the following error. </p>
  
  <pre><code>Error in stockPair$a - stockPair$hedgeRatio * stockPair$b : 
        non-conformable arrays
  </code></pre>
  
  <p>The reason these particular series don't match is because "WPL.AX" has an extra value (date:19-05-2014 - the matrix lengths are different) compared to "BHP". How can I solve this issue when loading data?</p>
  
  <p>I have also tested other stock pairs such as "ANZ","WBC" with the source = "google" which produces two of the same length arrays.</p>
  
  <pre><code>&gt; length(stockPair$a)
  [1] 360
  &gt; length(stockPair$b)
  [1] 359
  </code></pre>