[R-SIG-Finance] How to change the way R format his output ?
pierre8r-list at yahoo.fr
pierre8r-list at yahoo.fr
Fri Aug 1 10:10:07 CEST 2008
Hi,
I try to :
Load 1 minute quotes from http://www.metaquotes.net/ into R.
Compute 15 mns quotes, 1 hour, daily quotes, etc. with R from 1 mn quotes.
Write to files these quotes.
Compare quotes from http://www.metaquotes.net/ with quotes from R, with Winmerge ( http://winmerge.org/ ), I compare directories.
How to change the way R format his output, and than Winmerge will not show any difference between the two files ?
Datas 15 minutes from http://www.metaquotes.net/ :
--------------------------------------------------
2008.07.01,00:00,1.5754,1.5757,1.5753,1.5757,23
2008.07.01,00:15,1.5756,1.5758,1.5753,1.5758,48
2008.07.01,00:30,1.5757,1.5758,1.5752,1.5754,32
2008.07.01,00:45,1.5755,1.5755,1.5747,1.5748,29
2008.07.01,01:00,1.5747,1.5758,1.5747,1.5757,66
2008.07.01,01:15,1.5756,1.5757,1.5752,1.5755,46
2008.07.01,01:30,1.5754,1.5756,1.5751,1.5754,65
Output 15 minutes datas from the R code :
----------------------------------------
2008.07.01,00:14, 1.5754, 1.5757, 1.5753, 1.5757, 23.0000
2008.07.01,00:29, 1.5756, 1.5758, 1.5753, 1.5758, 48.0000
2008.07.01,00:44, 1.5757, 1.5758, 1.5752, 1.5754, 32.0000
2008.07.01,00:59, 1.5755, 1.5755, 1.5747, 1.5748, 29.0000
2008.07.01,01:14, 1.5747, 1.5758, 1.5747, 1.5757, 66.0000
2008.07.01,01:29, 1.5756, 1.5757, 1.5752, 1.5755, 46.0000
2008.07.01,01:44, 1.5754, 1.5756, 1.5751, 1.5754, 65.0000
My R code :
----------
#-------------------------------------------------------------------------#
"InputQuotesMT4" <-
function( FicIn = "ErrorFicIn", RepIn = "ErrorRepIn" ){
InputFile <- paste(collapse="", c(RepIn, FicIn))
quotes <- read.csv(InputFile, header=FALSE)
IQuotes <- as.xts(quotes[,-(1:2)],
as.POSIXct(paste(quotes[,1],quotes[,2]),format='%Y.%m.%d %H:%M'))
colnames(IQuotes) <- c('Open','High','Low','Close','Volume')
return( IQuotes )
}
#-------------------------------------------------------------------------#
"OutputToCSV" <-
function(xFile = xFil , OD = OutputDirectory , OF = OutputFile ) {
nameFile <- paste(collapse="", c(OD, OF,".csv"))
write.table(format(xFile,nsmall=4, justify = "left"),
file = nameFile, quote=FALSE, col.names=FALSE,
row.names=format(index(xFile),"%Y.%m.%d,%H:%M"), sep=",")
}
#-------------------------------------------------------------------------#
library(xts)
library(quantmod)
InputDir <- "K:\\MT4Input\\"
InputFile <- "EURUSD1.csv"
OutputDir <- "K:\\MT4Output\\"
Quotes1MN <- InputQuotesMT4( FicIn = InputFile, RepIn = InputDir )
OutputToCSV(xFile = Quotes1MN, OD = OutputDir, OF = "EURUSD1")
Quotes5MNS <- to.minutes5(Quotes1MN)
OutputToCSV(xFile = Quotes5MNS, OD = OutputDir, OF = "EURUSD5")
Quotes15MNS <- to.minutes15(Quotes5MNS)
OutputToCSV(Quotes15MNS, OD = OutputDir, OF = "EURUSD15")
Quotes1H <- to.hourly(Quotes5MNS)
OutputToCSV(xFile = Quotes1H,OD = OutputDir, OF = "EURUSD60")
Quotes4H <- to.hourly(Quotes5MNS, k=4, indexAt='startof')
OutputToCSV(xFile = Quotes4H,OD = OutputDir, OF = "EURUSD240")
QuotesDay <- to.daily (Quotes1H)
OutputToCSV(xFile = QuotesDay,OD = OutputDir, OF = "EURUSD1440")
QuotesWeek <- to.weekly(QuotesDay)
OutputToCSV(xFile = QuotesWeek,OD = OutputDir, OF = "EURUSD10080")
____________________________________________________________
More information about the R-SIG-Finance
mailing list