[R-SIG-Finance] business day to monthly or quarterly aggregation.

Brian G. Peterson brian at braverock.com
Thu Jan 10 13:05:40 CET 2008


Murali Menon wrote:
> Folks,
> 
> I have a matrix of portfolio weights whose rownames are daily dates (weekends elided).
> I'd like to create a new matrix of portfolio weights such that the weight on the first
> day of the month (quarter) is copied to the rest of the month (quarter). The idea is 
> that I rebalance my portfolio only on the first of the month (quarter). Is there a 
> neat way to do this?

The 'aggregate' function function from zoo comes immediately to mind, 
but seems like overkill for what you're talking about, as no real 
operation needs to be performed on the data series.

The quantmod package has functions that may be more on-point, for 
converting daily price time series to weekly, monthly, or quarterly 
series.  This is much closer to what you describe, as conversion of a 
price series in this manner involves taking the observation at the 
beginning(end) of the period.  The functions are to.weekly, to.monthly, 
and to.quarterly.

Help may be accessed via

install.packages("quantmod")
library("quantmod")
?to.period

Regards,

     - Brian



More information about the R-SIG-Finance mailing list