[R-SIG-Finance] Trying to plot intraday data on multiple daily plots

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Oct 12 05:05:03 CEST 2011


Your example isn't reproducible and I don't have example data at hand,
so here's my guess: "datte" is a Date class object, but (according to
?chart_Series) the subset argument of chart_Series is supposed to be a
character string.
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Tue, Oct 11, 2011 at 12:47 PM, Matti Zemack <matti.zemack at gmail.com> wrote:
> Hi all,
>
>
> I'm very new to R. And love it so far.
> Lately I've got interested in pre market + market up until 11am.
>
> So, I thought some graphical presentation would help me figure what's going on. I'm interested in MULTIPLE OHLC-plots on ONE sheet of paper. On plot (i.e. chart_Series) for every date, with 5 min candlesticks.
>
> Intraday-data is 1 min OHLC in a MySQL.
>
>
> Code so far:
>
> -------
> #Setup
> library(quantmod)
> library(RMySQL)
> drv <- dbDriver("MySQL")
> ch <- dbConnect(drv,dbname="databaseName","Login","Pass")
>
> #Get intraday data
> allQuotes <- dbGetQuery(ch,'SELECT CONCAT(date, " ", startTime) as dateTime, open as Open, high as High, low as Low, close as Close from quantQuoteData WHERE timeFrame=1 AND startTime<"11:00:00" AND date>="2011-08-01" AND date<="2011-08-31" AND  typ="spy"')
>
> #Make xts
> mzGSPC1 <- xts(allQuotes[,-1],order.by=as.POSIXlt(allQuotes[,1]))
>
> #Aggregate to 5mins OHLC
> mzGSPC5<-to.minutes5(mzGSPC1)
>
> #This works, but obviously not a way a programmer would produce plots
> par(mfrow=c(4,4))
> a<-"2011-08-01"
> chart_Series(mzGSPC5, subset=a)
> b<-"2011-08-02"
> chart_Series(mzGSPC5, subset=b)
> c<-"2011-08-03"
> chart_Series(mzGSPC5, subset=c)
> d<-"2011-08-04"
> chart_Series(mzGSPC5, subset=d)
> ...
>
> #Now trying to loop per date instead as I understand ONE chart_Series command must be sent for every plot.
> #Excuse me for my (probably) ugly way of retrieving the dates for the loop, but I'm new to R….
> par(mfrow=c(4,4))
> mzGSPCdaily<-to.daily(mzGSPC5)
> for (i in 1:length(mzGSPCdaily[,1])) {
>  datte<-as.Date(time(mzGSPCdaily[i]))
>  #Below print is just for verifying that I receive dates
>  print(datte)   #This works and prints the dates "2011-08-01", "2011-08-02"...
>  chart_Series(mzGSPC5, subset=datte)
> }
>
> ----------
> This chart_Series gives me an error:
> Error in plot.window(c(1, 0), c(NaN, NaN)) : need finite 'ylim' values
> In addition: Warning messages:
> 1: In min(x) : no non-missing arguments to min; returning Inf
> 2: In max(x) : no non-missing arguments to max; returning -Inf
>
> And I just cannot understand why my manual dating works, but not the looping version…
>
> Also I am grateful if you [smarter] people can find other stupid things I'm doing.
>
> Thanks in advance for all help,
> Thanks also for all the packages you programmers have spent time on.
>
> Regards,
> Matti Zemack
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>



More information about the R-SIG-Finance mailing list