[R-SIG-Finance] Time interval logic

Jeffrey Ryan jeffrey.ryan at lemnica.com
Wed Nov 9 16:22:06 CET 2011


Agreed, posting guideline and general list courtesy requires something
reproducible.

Here is my take:

x <- xts(c(20,200,120,125,99,231,1000),
as.POSIXct("2011-11-01")+seq(60,60*7,60))

index(x)[which(diff(cumsum(x) %/% 300) > 0)]

#[1] "2011-11-01 00:03:00 CDT" "2011-11-01 00:06:00 CDT"
#[3] "2011-11-01 00:07:00 CDT"

I don't follow how you are getting the time diff though, since I see 3
min, 3min and 1 min...

Best,
Jeff

On Wed, Nov 9, 2011 at 7:33 AM, Brian G. Peterson <brian at braverock.com> wrote:
> Pleaee follow the posting guide and provide a reproducible example, as
> it is, you ask others to re-do work that you have already done, greatly
> increasing the time to help you finish your project.
>
>
> On Wed, 2011-11-09 at 21:48 +1100, Manoj wrote:
>
>> Hello,
>>     I am working on some tick-data and needed help computing the
>> following statistics:
>
> This is not tick data. it is one minute intraday observations.
>
>>      Assume the dataset to be an xts object of Price and Volume as shown below:
>> -------
>> Time  Prc     Vol     CumVol  Vol-Threshold   Vol_Residual    Time_Elapsed
>> 10:01 24.01   20      20
>> 10:02 24.05   200     220
>> 10:03 23.99   120     340     300     40      3
>> 10:04 24.02   125     465
>> 10:05 24.01   99      564
>> 10:06 24.02   231     795     300     195     4
>> 10:07 23.99   1000    1795    300     895     2
>
> This does not appear to be an xts object, where the index would not be
> called 'Time', would contain a date, and would not be labeled at all.
>
>> -------
>>
>>       From the above trade data - I am interested in finding out the
>> time taken to complete a certain volume threshold. The column in
>> question from above data is the "Time_Elapsed" column. I have used 300
>> shares as volume threshold in above example. Once the threshold is
>> reached, the excess volume for the currently processed trade is
>> allocated to next group. In example above - it takes 3 minutes to
>> complete 1st volume threshold (20+200+80) leaving behind a residual of
>> 40 shares for next group. The second and third volume thresholds are
>> completed in 4 minutes and 2 minutes in the example above.
>>
>>       What's the optimal way of speeding up the logic above?
>
> _______________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at lemnica.com

www.lemnica.com
www.esotericR.com



More information about the R-SIG-Finance mailing list