[R-SIG-Finance] business day to monthly or quarterly aggregation.
Murali Menon
feanor0 at hotmail.com
Thu Jan 10 12:14:09 CET 2008
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 reason I'm thinking of copying weights till the end of each period is that then,
in order to compute rebalancing costs, I just need to do a abs(diff) on the weights matrix and multiply by the transaction cost.
I guess if I can just convert the vector of dates into a vector of repeated first-of-period
dates, I can use this vector to index into the portfolio weights matrix. But I can't
think how I could achieve this vector conversion either.
Any suggestions?
Thanks,
Murali
ourdates <- c("1997-01-29", "1997-01-30", "1997-01-31", "1997-02-03", "1997-02-04",
"1997-02-05", "1997-02-06", "1997-02-07", "1997-02-10", "1997-02-11",
"1997-02-12", "1997-02-13", "1997-02-14", "1997-02-17", "1997-02-18",
"1997-02-19", "1997-02-20", "1997-02-21", "1997-02-24", "1997-02-25",
"1997-02-26", "1997-02-27", "1997-02-28", "1997-03-03", "1997-03-04",
"1997-03-05", "1997-03-06", "1997-03-07", "1997-03-10", "1997-03-11",
"1997-03-12", "1997-03-13", "1997-03-14", "1997-03-17", "1997-03-18",
"1997-03-19", "1997-03-20", "1997-03-21", "1997-03-24", "1997-03-25",
"1997-03-26", "1997-03-27", "1997-03-28", "1997-03-31", "1997-04-01",
"1997-04-02", "1997-04-03", "1997-04-04", "1997-04-07", "1997-04-08",
"1997-04-09", "1997-04-10", "1997-04-11", "1997-04-14", "1997-04-15",
"1997-04-16", "1997-04-17", "1997-04-18", "1997-04-21", "1997-04-22",
"1997-04-23", "1997-04-24", "1997-04-25", "1997-04-28", "1997-04-29",
"1997-04-30", "1997-05-01", "1997-05-02", "1997-05-05", "1997-05-06",
"1997-05-07", "1997-05-08", "1997-05-09", "1997-05-12", "1997-05-13",
"1997-05-14", "1997-05-15", "1997-05-16", "1997-05-19", "1997-05-20",
"1997-05-21", "1997-05-22", "1997-05-23", "1997-05-26", "1997-05-27",
"1997-05-28", "1997-05-29", "1997-05-30", "1997-06-02", "1997-06-03",
"1997-06-04", "1997-06-05", "1997-06-06", "1997-06-09", "1997-06-10",
"1997-06-11", "1997-06-12", "1997-06-13", "1997-06-16", "1997-06-17"
)
set.seed(123)
pWt <- matrix(rnorm(1000), ncol = 10)
somehow create new vector newdates: ("1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-02-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-03-03", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-04-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-05-01", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02", "1997-06-02")
pWt[newdates, ] will give me the repeated monthly weights that I want.
And similarly for repeated quarterly weights.
_________________________________________________________________
Share life as it happens with the new Windows Live.
08
More information about the R-SIG-Finance
mailing list