[R-SIG-Finance] [R-sig-finance] Extracting OHLC from trade price series
Yuri Volchik
yuri.volchik at gmail.com
Wed Feb 27 18:44:48 CET 2008
Hi to all members,
I presume my question is to Jeff mostly concerning to.minutes:
I have a xts object with tick data:
mm<-xts(dd[,2:4],new.timestamps)
BO Price Quantity
2007-01-02 08:13:52 O 18.50000000 5
2007-01-02 08:15:02 B 18.29999924 3
2007-01-02 08:15:02 B 18.29999924 10
2007-01-02 08:46:31 B 18.00000000 10
2007-01-02 09:01:43 B 17.85000038 1
2007-01-02 09:04:48 B 17.85000038 9
2007-01-02 09:19:58 B 17.85000038 1
2007-01-02 09:38:19 B 17.85000038 1
2007-01-02 09:54:08 B 17.70000076 5
2007-01-02 10:07:25 O 17.79999924 5
...
and trying to convert to 5 min data using
xx<-to.minutes(mm[,2],5,'minutes')
minutes.Open minutes.High minutes.Low minutes.Close
2007-01-02 08:13:52 18.50000000 18.50000000 18.50000000 18.50000000
2007-01-02 08:15:02 18.29999924 18.29999924 18.29999924 18.29999924
2007-01-02 08:46:31 18.00000000 18.00000000 18.00000000 18.00000000
2007-01-02 09:01:43 17.85000038 17.85000038 17.85000038 17.85000038
2007-01-02 09:04:48 17.85000038 17.85000038 17.85000038 17.85000038
2007-01-02 09:19:58 17.85000038 17.85000038 17.85000038 17.85000038
2007-01-02 09:38:19 17.85000038 17.85000038 17.85000038 17.85000038
2007-01-02 09:54:08 17.70000076 17.70000076 17.70000076 17.70000076
2007-01-02 10:07:28 17.79999924 17.79999924 17.79999924 17.79999924
2007-01-02 10:17:22 17.79999924 17.79999924 17.79999924 17.79999924
....
The question is this output correct, is there a way to convert tick data to
a somewhat 'nice' representation with equally spaced time intervals and
using specific method of interpolation for missing data (or just leaving
them as NA). I created such code in R, but i think it is quite slow.
Thanks
Jeff Ryan wrote:
>
> 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 :)
>
>
>
--
View this message in context: http://www.nabble.com/Extracting-OHLC-from-trade-price-series-tp15579652p15718653.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list