Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rm(list=ls())
- options(digits=14)
- library(xts)
- library(chron)
- f <- function(d,t)
- {
- #as.chron(paste(as.Date(chron(d)),t))
- as.POSIXct(paste(d,t), format="%Y%m%d %H:%M")
- }
- setwd("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt")
- #d <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/SPY_1Oct_31Dec_2012.csv", header=T, sep=',')
- spy.prices <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/dec_2012.csv", header=T, sep=',')
- #spy.prices <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/tobedel.txt", header=T, sep=',')
- #spy.prices <- read.zoo("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/dec_2012.csv", header=T, index=2:3, FUN=f,sep=',' )
- drops <- c("SYMBOL")
- spy.prices<- spy.prices[, !(names(spy.prices) %in% drops)]
- spy.prices$DateTime <- strptime(paste(spy.prices$DATE, spy.prices$TIME), "%Y%m%d %H:%M:%S")
- drops <- c("DATE", "TIME")
- spy.prices<- spy.prices[, !(names(spy.prices) %in% drops)]
- #spy.prices <- as.zoo(spy.prices)
- spy.prices <- xts(spy.prices$PRICE, order.by=spy.prices$DateTime)
- head(spy.prices)
- spy.prices <- to.minutes5(spy.prices)
- head(spy.prices)
- write.zoo(as.zoo(spy.prices), file="5min_prices_dec.csv", index.name="DateTime", col.names=TRUE, sep=",")
- spy.prices.5min <- read.csv("5min_prices_dec.csv", sep=",", header=T)
- spy.prices.5min$DateTime = as.POSIXct(spy.prices.5min$DateTime)
- spy.prices.5min <- xts(spy.prices.5min[,-1], order.by = spy.prices.5min$DateTime)
- #spy.prices.5min <- as.xts(read.zoo("5min_prices_dec.csv", index.column=1, sep=",", header=T), order.by="spy.prices$DateTime")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement