nearby(x, rule, contracts)
"F95"
, or
"F1995"
, where the first
letter is the month code and the remainder is the year, and where
two-digit years are converted to four-digit years using
options("time.century")
. These should be in ascending order.
The series is generated with the following steps. First, the contract
months are converted to dates of the first of the month, e.g. Z98 becomes
December 1, 1998. Then the roll rule is added to each date, to
calculate the last day each column of the data set should be used.
The time series positions and the end dates are then passed to the
cut
function to determine which column is needed for each output date,
and these data values are subscripted from
x
and returned.
NA
will
be the result for positions that have no valid column data.
# make a 5-column time series x <- timeSeries(data=matrix(1:750, ncol=5), pos=timeDate("1/1/1995", format="%a %02m/%02d/%Y")+1:150) # make a nearby series, assuming this are Feb-June 1995 contracts (ignoring # the fact that there should be NAs in the matrix), rolling on the 3rd # Friday of the month before the contract month nearby(x, timeRelative("-1mth -1day +3fri"), paste(c("G", "H", "J", "K", "M"), 1995, sep=""))