[R-SIG-Finance] problem aggregating daily series solved

John C. Frain frainj at tcd.ie
Tue Sep 26 00:08:24 CEST 2006


Diethelm

Thank you for looking into my problem.  I now understand why I had such
problems.  Apart from the problem with the applySeries function y from and to
lists should have been in the same zone as th read.timeSeries statemenmt which
created the original time series object.  Again thank you very much.

Best Regards

John


-----Original Message-----
From: Diethelm Wuertz [mailto:wuertz at itp.phys.ethz.ch]
Sent: 25 September 2006 01:35
To: John C. Frain; r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] problem aggregating daily series

Dear John Frain,
please apologize for any inconveniances caused by a bug in the
applySeries() Function.
It doesent appear when you worj with daily records using "GMT" as FinCenter.
Try:

 myFinCenter = "GMT"
 tD = timeSequence("2006-01-01", length.out = 365)
 Data = matrix(rep(1, times = 365), ncol = 1)
 tS = timeSeries(Data, tD)
 from = timeCalendar(2006)
 to = timeLastDayInMonth(from)
 applySeries(tS, from, to, FUN = colSums, units = "N")

Now fix the bug by overwriting the last line in applySeries()
timeSeries(data = rowBind, charvec = as.character(to), units = units,
       # format = x at format, zone = "GMT", FinCenter = x at FinCenter,
       format = x at format, zone = x at FinCenter, FinCenter = x at FinCenter,
       title = x at title, documentation = x at documentation, ...)

Here is the full function:

.applySeries =
function (x, from = NULL, to = NULL, FUN = colAvgs, units = NULL,  ...)
{
   colNames = units
   if (class(x) != "timeSeries") stop("s is not a timeSeries object")
   fun = match.fun(FUN)
   j.pos = as.POSIXct(seriesPositions(x))
   j.from = as.POSIXct(from)
   j.to = as.POSIXct(to)
   y = x at Data
   pos = seriesPositions(x)
   rowNames = rownames(x at Data)
   rowBind = NULL
   for (i in 1:from at Dim) {
       test = (j.pos >= j.from[i] & j.pos <= j.to[i])
       cutted = as.matrix(y[test, ])
       ans = fun(cutted, ...)
       rowBind = rbind(rowBind, ans)
   }
   rownames(rowBind) = as.character(to)
   if (is.null(colNames)) {
       units = x at units
   }
   else {
       units = colNames
   }
   timeSeries(data = rowBind, charvec = as.character(to), units = units,
       # format = x at format, zone = "GMT", FinCenter = x at FinCenter,
       format = x at format, zone = x at FinCenter, FinCenter = x at FinCenter,
       title = x at title, documentation = x at documentation, ...)
}


# Now try:

myFinCenter = "Dublin"
tD = timeSequence("2006-01-01", length.out = 365, FinCenter = "Dublin")
Data = matrix(rep(1, times = 365), ncol = 1)
tS = timeSeries(Data, tD, zone = "Dublin", FinCenter = "Dublin")
from = timeCalendar(2006)
to = timeLastDayInMonth(from, FinCenter = "Dublin")
.applySeries(tS, from, to, FUN = colSums, units = "N")

The philosophy behind the timeSeries class is that you have two
time reference points: The first where the data were collected (zone)
and the
second where the data willl be used (FinCenter). To circumvent
inconsistencies
in the future, I think it will be the best to allow to specify in any
case zone and
FinCenter through the argument list in any of the timeSeries class
functions


Diethelm Wuertz
John C. Frain.
Economics Department
Trinity College Dublin
Dublin 2

www.tcd.ie/Economics/staff/frainj/home.html
mailto:frainj at tcd.ie




----- End forwarded message -----



More information about the R-SIG-Finance mailing list