2
$\begingroup$

Is there any function for plotting the evolution of portfolio weights over time in r?. I have a matrix of portfolio weights from an equal weighting strategy at rebalancing times and want to plot weights of the stocks over time on a single plot.

for example:you want to backtest equal weight strategy where you allocate weights equally at each rebalancing dates for each stock. I have a matrix of weights:

             A       B            C       D              E           F

2001-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2002-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2003-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2004-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2005-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2006-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2007-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2008-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2009-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2010-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

2011-12-01 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806 0.03225806

I want to plot the stocks(A,B,..) on a single plot where the y axis will be the allocatons and x axis the time ie plotting a transition map for weights over time using R

Regards

$\endgroup$
  • $\begingroup$ Could you please provide more information like e.g. code, an example matrix with the weights etc.? $\endgroup$ – vonjd Jun 30 '14 at 9:13
  • $\begingroup$ I think this is off-topic because in short you ask how to plot multvariate time series - right? Look at the xts package cran.r-project.org/web/packages/xts/index.html and get to know time formats in R. $\endgroup$ – Ric Jun 30 '14 at 10:29
  • 2
    $\begingroup$ This is a simple programming question. $\endgroup$ – Ric Jun 30 '14 at 10:30
  • $\begingroup$ Although the question has been closed you can still upvote my answer and accept it if it was helpful - Thank you :-) $\endgroup$ – vonjd Jun 30 '14 at 14:03
  • $\begingroup$ Thank you, I was able to figure out what I really needed, I wanted stacked Area Graph to plot the weights over time. I used the ggplot after changing my time series object to long format.@vonjd $\endgroup$ – user3481555 Jun 30 '14 at 14:31
1
$\begingroup$

You can use the zoo package:

library(zoo)
W <- matrix(rep(0.03225806,66),nrow=11)
T <- seq(as.Date("2001-12-01"), as.Date("2011-12-01 "), "years")
M <- read.zoo(data.frame(T,W))
colnames(M) <- c(LETTERS[1:6])
plot.zoo(M)
plot.zoo(M,plot.type = "single")
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.