Advertisement
Guest User

Untitled

a guest
Apr 26th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.58 KB | None | 0 0
  1. rm(list=ls())
  2. options(digits=14)
  3. library(xts)
  4. library(chron)
  5.  
  6. f <- function(d,t)
  7. {
  8.     #as.chron(paste(as.Date(chron(d)),t))
  9.     as.POSIXct(paste(d,t), format="%Y%m%d %H:%M")
  10. }
  11. setwd("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt")
  12. #d <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/SPY_1Oct_31Dec_2012.csv", header=T, sep=',')
  13. spy.prices <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/dec_2012.csv", header=T, sep=',')
  14. #spy.prices <- read.csv("C:/Users/vtomar/Documents/GitHub/Data/TAQ/SPY/SPY_txt/tobedel.txt", header=T, sep=',')
  15. #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=',' )
  16. drops <- c("SYMBOL")
  17. spy.prices<- spy.prices[, !(names(spy.prices) %in% drops)]
  18. spy.prices$DateTime <- strptime(paste(spy.prices$DATE, spy.prices$TIME), "%Y%m%d %H:%M:%S")
  19. drops <- c("DATE", "TIME")
  20. spy.prices<- spy.prices[, !(names(spy.prices) %in% drops)]
  21. #spy.prices <- as.zoo(spy.prices)
  22. spy.prices <- xts(spy.prices$PRICE, order.by=spy.prices$DateTime)
  23. head(spy.prices)
  24. spy.prices <- to.minutes5(spy.prices)
  25. head(spy.prices)
  26. write.zoo(as.zoo(spy.prices), file="5min_prices_dec.csv", index.name="DateTime", col.names=TRUE, sep=",")
  27.  
  28.  
  29. spy.prices.5min <- read.csv("5min_prices_dec.csv", sep=",", header=T)
  30. spy.prices.5min$DateTime = as.POSIXct(spy.prices.5min$DateTime)
  31. spy.prices.5min <- xts(spy.prices.5min[,-1], order.by = spy.prices.5min$DateTime)
  32. #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