[R-SIG-Finance] Financial time series data mining in R

Jeff Ryan jeff.a.ryan at gmail.com
Thu May 21 20:32:33 CEST 2009


Reena,

> r <- rnorm(20)
> r[c(1,2,16,17)] <- NA

> r
 [1]          NA          NA  1.01972607 -0.26526079 -0.48193672  1.26074421
 [7]  1.09832958 -0.57868771  0.64506617  0.37299142  0.63672673 -0.02503177
[13]  1.44064294  0.23808208  1.33212831          NA          NA  0.34509281
[19] -0.29853578  0.49943889

> rle(is.na(r))
Run Length Encoding
  lengths: int [1:4] 2 13 2 3
  values : logi [1:4] TRUE FALSE TRUE FALSE

You can then find the starting and stopping points from there.


HTH,
Jeff

On Thu, May 21, 2009 at 1:21 PM, Reena Bansal <Reena.Bansal at moorecap.com> wrote:
> Hi All,
>
> This is a financial time series data mining question. Suppose I have a
> time series as below, a typical fetch with NA's and prices.
>
>> z
>        y
> 1      NA
> 2      NA
> 3  884.96
> 4  894.07
> 5  902.33
> 6  810.36
> 7  810.52
> 8  811.94
> 9  812.12
> 10 826.85
> 11 826.45
> 12 808.03
> 13 800.28
> 14 800.70
> 15 800.68
> 16     NA
> 17     NA
> 18 800.49
> 19 800.65
> 20 801.82
>
> I want to create summary of the data, which should give me the length of
> each contiguous block of NA and NUMBER(prices here), and start and end
> index, so a sample output might be.
>
> Type            Length  StartIndex      EndIndex
> NA              2       1               2
> NUMBER  13      3               15
> NA              2       16              17
> NUMBER  3       18              20
>
> I looked into arules package but didn't find anything that did the same.
> Any ideas?
>
> Thanks everybody,
> Reena
>
>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list