Last active
May 28, 2016 20:53
-
-
Save tomas-rampas/cb60a16584cffe01a4aeb1f7d07f9a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#reads ticks and creates .rda file | |
library(xts) | |
library(zoo) | |
library(blotter) | |
symbol = "GBPJPY" | |
tick.data.dir <- paste0('g:\\JForex\\data\\', symbol) | |
tick.data.outdir <- "g:\\TickData\\" | |
opts <- options(digits.secs = 0) | |
#creates RDA files from csv tick data | |
createRDA <- function(){ | |
filenames=list.files(path=tick.data.dir, pattern = ".csv", full.names=TRUE) | |
for(filename in filenames) { | |
print(paste("Processing:", filename)) | |
ts <- read.csv(filename, header=T) | |
assign(symbol, xts(ts[,2:5], as.POSIXct(ts[,1],format="%Y.%m.%d %H:%M:%OS", tz="UTC"))) | |
rm(ts) | |
saveSymbols.days(symbol, base_dir = tick.data.outdir) | |
rm(list = ls(pattern = symbol)) | |
gc() | |
} | |
} | |
# creates xts object with OHLC candles | |
createCustomCandlesticTimeSeries <- function(unit, fragment , from, to, dir){ | |
.env <- new.env() | |
quote <- get(symbol, .env) | |
x <- cbind(quote$Bid, Volume=1) | |
y <- align.time(to.period(x, unit, fragment,indexAt = 'startof'),n=fragment*60) | |
colnames(y) <- c("Open", "High", "Low", "Close","volume") | |
return(y) | |
} | |
createRDA() | |
# ts contains 15min OHLC data for given symbol, date range, and RDA data source | |
ts <- createCustomCandlesticTimeSeries("minutes",15,"2015-01-01","2015-12-31",tick.data.outdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment