Skip to content

intraday OHLC plot

6 messages · Thomas Steiner, Jeff Ryan, Gabor Grothendieck

#
I want to create a open/high/low/last plot of intraday data.
I try to use the function plotOHLC from the tsteries package. I create
my own multiple time series and then try to plot it.

raw Data Format (file eurusd2.csv):
"Date (GMT)"	"Open"	"High"	"Low"	"Last"
17-03-2008 00:00:00	1,5764	1,5766	1,5747	1,5750
17-03-2008 00:05:00	1,5749	1,5750	1,5741	1,5744
17-03-2008 00:10:00	1,5745	1,5762	1,5741	1,5749
Fehler in if ((!is.mts(x)) || (colnames(x)[1] != "Open") ||
(colnames(x)[2] !=  :
        Fehlender Wert, wo TRUE/FALSE n?tig ist
so there is a value missing where it expected a T/F...

In Details of the help on the function plotOHLC it says:
The time scale of x must be in Julian dates (days since the origin).

Perhaps anyone can provide help here?
Thanks,
Thomas
#
Try this:

Lines <- '"Date (GMT)"	"Open"	"High"	"Low"	"Last"
17-03-2008 00:00:00	1,5764	1,5766	1,5747	1,5750
17-03-2008 00:05:00	1,5749	1,5750	1,5741	1,5744
17-03-2008 00:10:00	1,5745	1,5762	1,5741	1,5749'
DF <- read.delim2(textConnection(Lines))

library(quantmod)
z <- read.zoo(textConnection(Lines), # replace with "myfile.dat"
    header = TRUE, sep = "\t", dec = ",",
    format = "%d-%m-%Y %H:%M:%S", tz = "")
q <- as.quantmod.OHLC(z, col.names = c("Open", "High", "Low", "Close"))
chartSeries(q)

Look at the zoo, quantmod and xts packages for more info.
On Sat, Mar 22, 2008 at 6:19 AM, Thomas Steiner <finbref.2006 at gmail.com> wrote:
1 day later
#
Dear Gabor and Jeff,

thanks for your hint! I tried it out and played around but could not
succeed completely:
Fehler in as.graphicsAnnot(labels) : objekt "x.labels" nicht gefunden

So it does not find the object "x.labels"... I just fould in the
pdf-documentation that this should be of type character.

Perhaps you know why it fails,
Thomas
#
Hi Thomas,

The issue is probably the quantmod package being outdated.  Try to
install this version:

http://r-forge.r-project.org/R/?group_id=125

The second issue is that xlab and ylab are no longer being applied -
they had some issue, and I haven't settled on a way to address yet.  I
will make that a priority though.

The third issue you *might* see upon updating quantmod is that you may
be better off calling chartSeries with the type='bar' argument - as
barChart just does this, but due to R lazy evaluation and the TA
mechanism/args things may break without a volume in the series.  The
alternate would be explicitly add TA=NULL to the call.

Jeff
On Sun, Mar 23, 2008 at 9:49 AM, Thomas Steiner <finbref.2006 at gmail.com> wrote:

  
    
#
Dear all,

thank you very much for continuing to look into this issue!
I checked the versions and in Gabor's code the spaces and tabs, but
still the problem remains (see code and error below).

To install quantmod, I used this time Rforge and it did not work. I
had to install the "Defaults" package from cran first by hand (ie not
like zoo and xts where it recognizes the dependence). And to get the
most recent version of the package I had to upgrade R as well (my
mistake of course). The link mentioned by Jeff points to 0.3.4, but I
got by the command
install.packages("quantmod",repos="http://R-Forge.R-project.org") the
version 0.3.3 as you see below.
+ 17-03-2008 00:05:001,57491,57501,57411,5744
+ 17-03-2008 00:10:001,57451,57621,57411,5749'
Lade n?tiges Paket: Defaults
quantmod: Quantitative Financial Modelling Framework

Version 0.3-3
http://www.quantmod.com

Warning message:
ungenutzte Verbindung 3 (Lines) geschlossen
+    header = F, sep = "\t", dec = ",",
+    format = "%d-%m-%Y %H:%M:%S", tz = "")
Fehler in read.zoo(textConnection(Lines), header = F, sep = "\t", dec = ",",  :
  index contains NAs
Fehler in ncol(x) : objekt "z" nicht gefunden
Fehler in UseMethod("as.xts") : keine anwendbare Methode f?r "as.xts"
R version 2.6.2 (2008-02-08)
i386-pc-mingw32

locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] quantmod_0.3-3 Defaults_1.1-1 xts_0.0-11     zoo_1.4-2

loaded via a namespace (and not attached):
[1] grid_2.6.2     lattice_0.17-4 tools_2.6.2
Anyway, after the upgarde and Jeff's hint to use the chartSeries
function it works. Now I still have to play around to make the labels
look nice...

Thanks a lot for all your help,
Thomas
#
You need zoo 1.5-0 and you are using 1.4-2.  Also note that
the DF <- line is not needed (though it doesn't hurt either)
and was just there to check your similar statement.
On Mon, Mar 24, 2008 at 4:48 AM, Thomas Steiner <finbref.2006 at gmail.com> wrote: