[R-sig-Finance] Convert tick data to OHLC

bogdan romocea br44114 at gmail.com
Mon Jul 24 16:19:03 CEST 2006


I guess it's faster and perhaps easier to write the code from scratch
than to look around for an existing function. For example:
ohlc <- function(ttime,tprice,fmt)
{
ttime.int <- format(ttime,fmt)
data.frame(o = tapply(tprice,ttime.int,function(x) {head(x,1)}),
  h = tapply(tprice,ttime.int,max),
  l = tapply(tprice,ttime.int,min),
  c = tapply(tprice,ttime.int,function(x) {tail(x,1)}),
  time = ttime[tapply(1:length(ttime),ttime.int,function(x) {head(x,1)})])
}
ohlc.1min <- ohlc(Sys.time() + 1:10000,runif(10000),"%Y%m%d %H%M")
ohlc.1hour <- ohlc(Sys.time() + 1:10000,runif(10000),"%Y%m%d %H")



> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of
> Spencer Graves
> Sent: Sunday, July 23, 2006 6:33 PM
> To: Bret Shroyer
> Cc: r-sig-finance at stat.math.ethz.ch
> Subject: Re: [R-sig-Finance] Convert tick data to OHLC
>
>   The only "open, high, low, close" functions I found were
> plotOHLC{tseries} and ohlcPlot{fMultivar}.  I too would be
> surprised if
> you were the first to attempt this.  However, if anyone has
> contributed
> any such thing to CRAN, it is sufficiently well hidden that
> neither of
> us could find it.
>
>   If I had a need for such right now, I likely would
> write my own
> function.
>
>   Sorry I couldn't be more helpful.
>   Spencer Graves
>
> Bret Shroyer wrote:
> > I have tick data that I'd like to convert to OHLC data at various
> > arbitrary timeframes - 1 minute, 5 minutes, one hour, etc.  I've
> > searched "R site search" and looked into RMetrics and the closest I
> > found was the not-yet-released fTickdata package.
> >
> > I don't think it would be challenging to write this routine
> myself, but
> > I have to believe I'm not the first to attempt this, and
> the solution is
> > out there somewhere.
> >
> > Can anyone help point me in the right direction, or give me
> some better
> > search words?
> >
> > Thanks,
> >
> > Bret Shroyer
> >
> > [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Finance at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>



More information about the R-SIG-Finance mailing list