[R-SIG-Finance] [R-sig-finance] How to change the way R format his output ?
Pierre8rou
pierre8r-nabble at yahoo.fr
Mon Aug 4 19:35:15 CEST 2008
I answer to myself.
Pierre8r
#-------------------------------------------------------------------------#
"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"))
colnames(xFile) <- c('Open','High','Low','Close','Volume')
xFile$Open <- sprintf("%5.04f", xFile$Open)
xFile$High <- sprintf("%5.04f", xFile$High)
xFile$Low <- sprintf("%5.04f", xFile$Low)
xFile$Close <- sprintf("%5.04f", xFile$Close)
xFile$Volume <- sprintf("%.0f", xFile$Volume)
write.table(xFile,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")
--
View this message in context: http://www.nabble.com/How-to-change-the-way-R-format-his-output---tp18770099p18815951.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list