1
votes

I have worked with daily stock data using quantmod. Quantmod automatically dowloads data from google/yahoo finance sites and convert automatically to a xts object as date as the index.

           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2014-10-01    100.59    100.69    98.70      99.18    51491300      97.09741
2014-10-02     99.27    100.22    98.04      99.90    47757800      97.80230
2014-10-03     99.44    100.21    99.04      99.62    43469600      97.52818
2014-10-06     99.95    100.65    99.42      99.62    37051200      97.52818
2014-10-07     99.43    100.12    98.73      98.75    42094200      96.67644
2014-10-08     98.76    101.11    98.31     100.80    57404700      98.68340
2014-10-09    101.54    102.38   100.61     101.02    77376500      98.89877

Now I am woking with intraday data(csv format) of one minute duration which I converted to a data frame(df) of six column.

      Date     Time Open High  Low Close
1 20150408 09:17:00 7.15 7.15 7.10  7.10
2 20150408 09:18:00 7.15 7.15 7.15  7.15
3 20150408 09:19:00 7.10 7.10 7.10  7.10
4 20150408 09:20:00 7.10 7.10 7.05  7.10
5 20150408 09:21:00 7.10 7.15 7.10  7.10
6 20150408 09:22:00 7.10 7.10 7.05  7.10 

Now how to convert this dataframe to a time series in such a way that I can use it with the default quantmod functions such as Cl(),Op(),OHLC() etc.

1

1 Answers

3
votes

Elementary, dear Watson: combine date and time into a POSIXct, use that.

Untested as you supplied no reproducible data:

pt <- as.POSIXct(paste(X$Date, X$Time), format="%Y%m%d %H:%M:%S")
N <- xts(X[, -(1:2)], order.by=pt)

Here X is your current data.frame, and N is a new xts object formed from the data of X (minus date and time) using pt as the index.