r - To create a regular time series -


how can create regular time series of 5 minute ohlc data volume , number_ticks summed? here's i've tried:

trades <-  structure(list(date = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l), .label = "26-10-2012", class = "factor"), time = structure(1:8, .label = c("09:15", "09:16", "09:17", "09:18", "09:19", "09:20", "09:21", "09:22", "09:23", "09:24", "09:25", "09:26", "09:27", "09:28", "09:29",  "09:30", "09:31", "09:32", "09:33", "09:34", "09:35", "09:36", "09:37", "09:38", "09:39", "09:40", "09:41", "09:42", "09:43", "09:44", "09:45", "09:46", "09:47", "09:48", "09:49", "09:50", "09:51", "09:52", "09:53", "09:54", "09:55", "09:56", "09:57", "09:58", "09:59", "10:00", "10:01", "10:02", "10:03", "10:04", "10:05", "10:06", "10:07", "10:08", "10:09", "10:10", "10:11", "10:12", "10:13", "10:14", "10:15", "10:16", "10:17", "10:18", "10:19", "10:20", "10:21", "10:22", "10:23", "10:24", "10:25",  "10:26", "10:27", "10:28", "10:29", "10:30", "10:31", "10:32", "10:33", "10:34", "10:35", "10:36", "10:37", "10:38", "10:39", "10:40", "10:41", "10:42", "10:43", "10:44", "10:45", "10:46", "10:47", "10:48", "10:49", "10:50", "10:51", "10:52", "10:53", "10:54"), class = "factor"), open = c(5720, 5716, 5720.55, 5718.3, 5720.6, 5722, 5723.8, 5724.1), high = c(5720, 5720, 5721.75, 5720.5, 5722.9, 5727.9, 5726.5, 5725), low = c(5711.25, 5715.85, 5717.05, 5718, 5720.2, 5722, 5723.75, 5721.5), last_price = c(5715.65, 5720, 5718.1, 5720, 5722, 5723.8, 5724.3, 5722.1), number_ticks = c(58l, 57l, 63l, 52l, 54l, 58l, 60l, 59l), volume = c(5146l, 2251l, 2060l, 1368l, 742l, 1771l, 1672l, 1364l)), .names = c("date", "time", "open", "high", "low", "last_price", "number_ticks", "volume"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") dt_tm <-as.posixct(paste(trades[,1], trades[,2],sep=","), format="%d%m%y,%h%m") cable <- xts(trades[,3:8], order.by=dt_tm) to.minutes5(cable, indexat='startof', name=null) #      open high    low close   volume # <na> 5720 6120 5481.2  5917 28089073 

look @ dt_tm object. values na because specified format incorrectly.

dt_tm <- as.posixct(paste(trades[,1], trades[,2]),                     format="%d-%m-%y %h:%m", tz="utc") cable <- xts(trades[,3:8], order.by=dt_tm) colnames(cable)[4] <- "close"  # in case last_price isn't recognized to.minutes5(cable, indexat='startof', name=null) #                     open   high     low  close volume # 2012-10-26 09:15:00 5720 5722.9 5711.25 5722.0  11567 # 2012-10-26 09:20:00 5722 5727.9 5721.50 5722.1   4807 

there's no way sum number of ticks @ same time, can renaming column "volume" , re-running to.minutes5.

cable$volume <- cable$number_ticks to.minutes5(cable, indexat='startof', name=null) #                     open   high     low  close volume # 2012-10-26 09:15:00 5720 5722.9 5711.25 5722.0    284 # 2012-10-26 09:20:00 5722 5727.9 5721.50 5722.1    177 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -