| aggregateMonthlySeries {QRMlib} | R Documentation |
This is one of several substitutes for the S-Plus language method
aggregateSeries(timeseries, FUN={max, mean, colAvg,
colSums,...}, by={weeks,months,quarters...},...).
The R-language aggregateMonthlySeries() function allows the user
to calculate a less granular timeseries (monthly) from a daily time series
by using a statistic like the max, mean, sum, etc. Note the R-methods do NOT
contain a by=“months” parameter so the R-language user must select
either the aggregateWeeklySeries method, the aggregateMonthlySeries()
method, or the aggregateQuarterlySeries() method to get the desired result.
aggregateMonthlySeries(timeseries, FUNC = colSums)
timeseries |
a (usually) daily timeSeries (R-Metrics type from fCalendar) from which the user wants to extract a monthly maximum (or monthly mean) timeSeries |
FUNC |
The name of a function to use in aggregating the data. For example the max, mean, min, etc. The default is colSums. |
For example, the user might want to create a series of monthly colSums returns from a daily time series of returns. Alternatively, (s)he might want the quarterly or weekly mean series. In either case, a less granular set of quarterly/monthly/weekly values is calculated from a daily timeSeries object. Unfortunately, the R-Metrics package has not yet implemented an R-version of the S-Plus aggregateSeries() method.
The aggregateWeeklySeries(), aggregateMonthlySeries(), and the aggregateQuarterlySeries() are interim functions developed to convert daily timeSeries to weekly, monthly, or quarterly timeSeries objects via a statistic like the max, mean, colAvg, or ColSums.
These functions exist in the functionsUtility.R file of the library.
A monthly timeSeries object characterized by some statistic like mean, max, min of the daily series over a month. The positions attribute (dates <- rseries@positions ) of the new time series will be the LAST DAYS OF THE RESPECTIVE MONTHS for the timeSeries object.
documentation by Scott Ulman for R-language distribution
aggregateWeeklySeries,
aggregateQuarterlySeries
#load nasdaq data set:
data(nasdaq);
#Create minus daily return series:
nreturns <- -mk.returns(nasdaq);
#convert to monthly series using max value from each month
#(rather than colSums):
monthly.maxima <- aggregateMonthlySeries(nreturns, FUNC=max);
## Not run:
Ret.DJ <- mk.returns(DJ);
#Choose only 10 of the 30 stocks:
selection1 <- c("AXP","EK","BA","C","KO","MSFT","HWP",
"INTC","JPM","DIS");
partialDJ30dailyTS <- Ret.DJ[,selection1];
partialDJ30daily <- cut(partialDJ30dailyTS, from="1992-12-31",
to="2000-12-31");
partialDJ30monthlyTS <- aggregateMonthlySeries(partialDJ30daily,
FUNC= colSums);
## End(Not run)