[R] intraday OHLC plot

Gabor Grothendieck
2008-03-22T12:07:13Z

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:
> 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
>
> > library("tseries")
> > raw=read.delim2("eurusd2.csv")
> > date.d=strptime(raw$Date..GMT,"%d-%m-%Y %H:%M:%S")
> > x=ts(data=c(raw$Open,raw$High,raw$Low,raw$Last),c="mts")
> > plotOHLC(x)
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>