I'm input the following datafile: three pairs of date-price data (plus column index numb). The problem is that each price has different National holidays, thus UK and US prices eventually misalign. Is there a nice way to push the date into an xts/zoo format and fill with NA
where the price doesn't exist (mkt is closed)?
ColNumb Date1 UK2Y Date2 US2Y Date3 GBPUSD
1 09/07/2012 0.9330 09/07/2012 0.5210 09/07/2012 1.552554
2 10/07/2012 0.9401 10/07/2012 0.5235 10/07/2012 1.551831
3 11/07/2012 0.9122 11/07/2012 0.5003 11/07/2012 1.550388
4 12/07/2012 0.8732 12/07/2012 0.4805 12/07/2012 1.542972
etc
UK2y <- as.xts(data[1:1033,1:2])
US2y <- as.xts(data[,3:4])
GBPUSD <- data[,5:6]
I have tried using {A <- strptime(UK2y$Date1, format = "%d/%m/%Y")}
, but this leads to invalid zoo object. I end up with correct formatted dates in 'A' as POSIX class which fails to cbind
with zoo ("error in structure"):
UK2y <- cbind(UK2y, A)
You see above there in an extra issue in that each paired-column is differing length. Some kind of "date match" function would mitigate, or perhaps there exists a soln in zoo/xts?