xts. Change the way time series is build ( minutes ).
Using minute data from Interactive Brokers interface in R (IBrokers)
library(IBrokers)
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following object(s) are masked from package:base :
as.Date.numeric
IBrokers version 0.1-2: (pre-alpha)
This software comes with NO WARRANTY. Not intended for production use!
See ?IBrokers for details
tws <- twsConnect()
QQQQ <- reqHistoricalData(tws, twsEquity("QQQQ"), barSize='1 min', duration='1 D')
waiting for TWS reply ...... done.
head(QQQQ)
Open High Low Close Volume WAP hasGaps Count 2008-08-04 08:30:00 44.88 44.92 44.82 44.82 9491 44.88 0 884 2008-08-04 08:31:00 44.82 44.83 44.52 44.57 31075 44.67 0 3102 2008-08-04 08:32:00 44.58 44.66 44.50 44.63 16498 44.57 0 1853 2008-08-04 08:33:00 44.63 44.68 44.62 44.66 3604 44.65 0 625 2008-08-04 08:34:00 44.67 44.72 44.67 44.69 3803 44.70 0 547 2008-08-04 08:35:00 44.69 44.75 44.68 44.75 2539 44.70 0 306
to.hourly(QQQQ[,1:5],name='QQQQ')
QQQQ.Open QQQQ.High QQQQ.Low QQQQ.Close QQQQ.Volume 2008-08-04 08:59:00 44.88 44.92 44.50 44.68 148632 2008-08-04 09:59:00 44.67 44.71 44.38 44.49 176134 2008-08-04 10:59:00 44.48 44.84 44.41 44.77 185493 2008-08-04 11:59:00 44.77 44.82 44.59 44.60 61961 2008-08-04 12:59:00 44.60 44.69 44.51 44.62 62291 2008-08-04 13:12:00 44.61 44.64 44.57 44.62 11080
to.hourly(QQQQ[,1:5],name='QQQQ',indexAt='startof')
QQQQ.Open QQQQ.High QQQQ.Low QQQQ.Close QQQQ.Volume 2008-08-04 08:30:00 44.88 44.92 44.50 44.68 148632 2008-08-04 09:00:00 44.67 44.71 44.38 44.49 176134 2008-08-04 10:00:00 44.48 44.84 44.41 44.77 185493 2008-08-04 11:00:00 44.77 44.82 44.59 44.60 61961 2008-08-04 12:00:00 44.60 44.69 44.51 44.62 62291 2008-08-04 13:00:00 44.61 44.64 44.57 44.62 11080 Like previous posts.. the indexAt arg is the key. For hourly you are going to have to use the R-forge version, or the source (all open!) from r-forge as well. You can also modify the code to your liking, if you'd be so inclined. Though the latter would be unnecessary in this case as it does what you want. If you have the windows tools (I am assuming that is your platform) to build R packages, just grab the source from r-forge. If not, you'll have to wait until I clean it so that it passes R CMD check and makes it to CRAN. Here are the links: http://r-forge.r-project.org/bin/windows/contrib/latest/xts_0.0-16.zip http://r-forge.r-project.org/src/contrib/xts_0.0-16.tar.gz Or from R: install.packages('xts', type='source', repos='http://r-forge.r-project.org') Jeff
On Mon, Aug 4, 2008 at 1:04 PM, Pierre8rou <pierre8r-nabble at yahoo.fr> wrote:
Hi, Follow a sample showing how is build a hourly time frame from xts and from a trading software There is a difference with the minutes. Is it possible to change the way time frame is build with xts ? Hourly time frame build with a trading software -------------------------------------------- 2008.07.01,00:00,1.5754,1.5758,1.5747,1.5748,132 2008.07.01,01:00,1.5747,1.5761,1.5747,1.5760,242 2008.07.01,02:00,1.5761,1.5766,1.5745,1.5746,309 2008.07.01,03:00,1.5745,1.5751,1.5727,1.5739,333 Hourly time frame build with xts ------------------------------ 2008.07.01,00:59,1.5754,1.5758,1.5747,1.5748,132 2008.07.01,01:59,1.5747,1.5761,1.5747,1.5760,242 2008.07.01,02:59,1.5761,1.5766,1.5745,1.5746,309 2008.07.01,03:59,1.5745,1.5751,1.5727,1.5739,333 Pierre8r -- View this message in context: http://www.nabble.com/xts.-Change-the-way-time-series-is-build-%28-minutes-%29.-tp18816524p18816524.html Sent from the Rmetrics mailing list archive at Nabble.com.
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. -- If you want to post, subscribe first.
Jeffrey Ryan jeffrey.ryan at insightalgo.com ia: insight algorithmics www.insightalgo.com