[R-SIG-Finance] Feature request to the xls package. Add to.4hours(x, name)

pierre8r-list at yahoo.fr pierre8r-list at yahoo.fr
Fri Jul 25 09:57:03 CEST 2008


Hi Jeff, 

> I suspect you mean the 'xts' package.  If so try:

Well guess!  ;-)

I have downloaded  hourly and four hours Forex datas from 
http://www.metaquotes.net/

Then I have used :
to.hourly(x, k=4)
with the hourly datas to compare.
But the results are not the same, why ?


My R code :
----------

library(quantmod)
library(xts)

Lines <-
"2008.07.07,00:00,1.5691,1.5705,1.5691,1.5702,58
2008.07.07,01:00,1.5701,1.5702,1.5691,1.5694,94
2008.07.07,02:00,1.5693,1.5693,1.5650,1.5652,278
2008.07.07,03:00,1.5651,1.5667,1.5633,1.5643,515
2008.07.07,04:00,1.5642,1.5643,1.5631,1.5637,255
2008.07.07,05:00,1.5638,1.5647,1.5634,1.5645,301
2008.07.07,06:00,1.5644,1.5653,1.5640,1.5640,341
2008.07.07,07:00,1.5641,1.5642,1.5625,1.5641,380
2008.07.07,08:00,1.5640,1.5646,1.5617,1.5627,590
2008.07.07,09:00,1.5628,1.5639,1.5611,1.5623,810
2008.07.07,10:00,1.5622,1.5647,1.5611,1.5643,808
2008.07.07,11:00,1.5642,1.5663,1.5642,1.5658,850
2008.07.07,12:00,1.5659,1.5667,1.5627,1.5663,802
2008.07.07,13:00,1.5665,1.5671,1.5651,1.5654,436
2008.07.07,14:00,1.5653,1.5659,1.5641,1.5649,599
2008.07.07,15:00,1.5648,1.5651,1.5621,1.5634,823
2008.07.07,16:00,1.5633,1.5663,1.5631,1.5663,694
2008.07.07,17:00,1.5662,1.5674,1.5645,1.5645,815
2008.07.07,18:00,1.5646,1.5718,1.5645,1.5717,840
2008.07.07,19:00,1.5716,1.5753,1.5715,1.5745,790
2008.07.07,20:00,1.5744,1.5748,1.5725,1.5730,510
2008.07.07,21:00,1.5729,1.5730,1.5707,1.5718,438
2008.07.07,22:00,1.5719,1.5730,1.5716,1.5726,223
2008.07.07,23:00,1.5725,1.5728,1.5720,1.5722,69"

quotes <- read.csv(textConnection(Lines), header=FALSE)
xH <- as.xts(quotes[,-(1:2)],
as.POSIXct(paste(quotes[,1],quotes[,2]),format='%Y.%m.%d %H:%M'))
colnames(xH) <- c('Open','High','Low','Close','Volume')
xH

x4H <- to.hourly(xH, k=4) 
x4H



Datas 60 minutes from  http://www.metaquotes.net/ :
--------------------------------------------------
2008.07.07,00:00,1.5691,1.5705,1.5691,1.5702,58
2008.07.07,01:00,1.5701,1.5702,1.5691,1.5694,94
2008.07.07,02:00,1.5693,1.5693,1.5650,1.5652,278
2008.07.07,03:00,1.5651,1.5667,1.5633,1.5643,515
2008.07.07,04:00,1.5642,1.5643,1.5631,1.5637,255
2008.07.07,05:00,1.5638,1.5647,1.5634,1.5645,301
2008.07.07,06:00,1.5644,1.5653,1.5640,1.5640,341
2008.07.07,07:00,1.5641,1.5642,1.5625,1.5641,380
2008.07.07,08:00,1.5640,1.5646,1.5617,1.5627,590
2008.07.07,09:00,1.5628,1.5639,1.5611,1.5623,810
2008.07.07,10:00,1.5622,1.5647,1.5611,1.5643,808
2008.07.07,11:00,1.5642,1.5663,1.5642,1.5658,850
2008.07.07,12:00,1.5659,1.5667,1.5627,1.5663,802
2008.07.07,13:00,1.5665,1.5671,1.5651,1.5654,436
2008.07.07,14:00,1.5653,1.5659,1.5641,1.5649,599
2008.07.07,15:00,1.5648,1.5651,1.5621,1.5634,823
2008.07.07,16:00,1.5633,1.5663,1.5631,1.5663,694
2008.07.07,17:00,1.5662,1.5674,1.5645,1.5645,815
2008.07.07,18:00,1.5646,1.5718,1.5645,1.5717,840
2008.07.07,19:00,1.5716,1.5753,1.5715,1.5745,790
2008.07.07,20:00,1.5744,1.5748,1.5725,1.5730,510
2008.07.07,21:00,1.5729,1.5730,1.5707,1.5718,438
2008.07.07,22:00,1.5719,1.5730,1.5716,1.5726,223
2008.07.07,23:00,1.5725,1.5728,1.5720,1.5722,69


Datas 240 minutes from  http://www.metaquotes.net/ :
--------------------------------------------------
2008.07.07,00:00,1.5691,1.5705,1.5633,1.5643,945
2008.07.07,04:00,1.5642,1.5653,1.5625,1.5641,1277
2008.07.07,08:00,1.5640,1.5663,1.5611,1.5658,3058
2008.07.07,12:00,1.5659,1.5671,1.5621,1.5634,2660
2008.07.07,16:00,1.5633,1.5753,1.5631,1.5745,3139
2008.07.07,20:00,1.5744,1.5748,1.5707,1.5722,1240


Output datas from the R code :
-----------------------------
                    xH.Open xH.High xH.Low xH.Close xH.Volume
2008-07-07 01:00:00  1.5691  1.5705 1.5691   1.5694       152
2008-07-07 05:00:00  1.5693  1.5693 1.5631   1.5645      1349
2008-07-07 09:00:00  1.5644  1.5653 1.5611   1.5623      2121
2008-07-07 13:00:00  1.5622  1.5671 1.5611   1.5654      2896
2008-07-07 17:00:00  1.5653  1.5674 1.5621   1.5645      2931
2008-07-07 21:00:00  1.5646  1.5753 1.5645   1.5718      2578
2008-07-07 23:00:00  1.5719  1.5730 1.5716   1.5722       292



















      ____________________________________________________________


More information about the R-SIG-Finance mailing list