[R] block statistics with POSIX classes

Kahra Hannu kahra at mpsgr.it
Wed Sep 22 17:22:20 CEST 2004


I have a monthly price index series x, the related return series y = diff(log(x)) and a POSIXlt date-time variable dp. I would like to apply annual blocks to compute for example annual block maxima and mean of y.

When studying the POSIX classes, in the first stage of the learning curve, I computed the maximum drawdown of x:
> mdd <- maxdrawdown(x)
> max.dd <- mdd$maxdrawdown
> from <- as.character(dp[mdd$from]) 
> to <- as.character(dp[mdd$to])                       
> from; to
[1] "2000-08-31"
[1] "2003-03-31"
that gives me the POSIX dates of the start and end of the period and suggests that I have done something correctly.

Two questions:
(1) how to implement annual blocks and compute e.g. annual max, min and mean of y (each year's max, min, mean)?
(2) how to apply POSIX variables with the 'block' argument in gev in the evir package?

The S+FinMetrics function aggregateSeries does the job in that module; but I do not know, how handle it in R. My guess is that (1) is done by using the function aggregate, but how to define the 'by' argument with POSIX variables?

Thanks!
Hannu Kahra 
Progetti Speciali 
Monte Paschi Asset Management SGR S.p.A. 
Via San Vittore, 37
IT-20123 Milano, Italia 

Tel.: +39 02 43828 754 
Mobile: +39 333 876 1558 
Fax: +39 02 43828 247 
E-mail: kahra at mpsgr.it 
Web: www.mpsam.it




More information about the R-help mailing list