[R-SIG-Finance] Extracting OHLC from trade price series
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Feb 20 01:39:27 CET 2008
Hi,
The package 'xts' (the function in question previously part of
'quantmod') has a nice and fast aggregation function that allows you
to create OHLC from any univariate series, or from an existing OHLC
series - called 'to.period'.
library(quantmod)
getSymbols("QQQQ")
to.monthly(QQQQ) # yields a monthly series from daily data
The code works equally well for anything from minute bars on up. It
should work below that, though I can't promise anything as I haven't
really tested that recently. Other functions in the group are
to.minutes, to.hourly, to to.daily... you get the idea.
to.period is the function you want to look at. It calls Fortran - so
it is very fast on all but gigantic data sets - and then nothing is :)
The GMT issue has been discussed here many times over - try
Sys.setenv(TZ='GMT') for starters. You are probably better off _not_
using timeDate - but I wrote xts so I wouldn't have to - to each his
own.
As for the last question... I am not too sure if I understand it
correctly. As long as you subset the data before hand 'to.period'
shouldn't care about your index dates/times.
'xts' also allows for easier subsetting by date:
as.xts(myts)['2007-01-01::2007-01-23']
The help with regard to the latter is not all there yet - so feel free
to contact me with specific questions.
Jeff
On Feb 19, 2008 6:22 PM, <adschai at optonline.net> wrote:
> Hi - I have a trade price series whose file is really big. My first question is, is there any existing routine in R to extract OHLC (Open-High-Low-Close) of specified interval from irregular trade price series?
>
> My second question is from my attempt to do this. The logic is not difficult but I am not familiar with fCalendar package especially timeDate object.
>
> First of all, I do:
>
> timeDate('2007-11-01',zone='GMT'); # I expect '2007-11-01 00:00:00 GMT'
>
> The result sometimes show '2007-11-01 GMT' or '2007-10-31 18:00:00 Central standard time'. My question is how do I specify display format, says in 'EST' consistently? Note that my machine time locale is CST.
>
> Third question, I try to generate a sequence of OHLC bar given a user input date. For example, I am interested in extracting OHLC from 6:00:00 EST to 14:30:00 EST on every weekday. How can I do that?
>
> Thank you,
>
> - adschai
>
> _______________________________________________
> 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.
>
--
There's a way to do it better - find it.
Thomas A. Edison
More information about the R-SIG-Finance
mailing list