I am trying to create a dashboard which looks something like the image just below:
It makes a cumulative plot for indices using weekly returns. Now i want to embed a barplot as additional column which plots returns at monthly frequency (assuming each month is 4 weeks). Is that possible ?
While adding returns up from 1 week to 4 weeks is easy, what sort of time values should I give and will it then lead to gaps in my barplot ?
Here is the code that I use for sparktable
content <- list(
function(x) { tail(x,1) },
function(x) {
round(tail(x,1),2)
},
function(x) { round(max(x),2) },
function(x) { round(min(x),2) },
newSparkLine(lineWidth = 2, pointWidth = 6), newSparkBar()
)
names(content) <- c("Current", "LastWeek", "Max", "Min", "Cumulative","WeeklyRet")
dat<-reshapeExt(lpl,idvar="INDEX",varying=list(2))
# set variables
vars <- c("CLOSE", "WEEKLY", "CLOSE", "CLOSE","CLOSE" ,"WEEKLY")
stab <- newSparkTable(dataObj = lpl, tableContent = content, varType = vars)
My data looks something like this
id time CLOSE WEEKLY
1469 SP500 1 1987.66 -2.4184217
1476 SP500 2 1951.13 -1.8722484
1483 SP500 3 1952.29 0.0594174
1490 SP500 4 1990.20 1.9048337
1497 SP500 5 1932.24 -2.9996274
1504 SP500 6 1923.82 -0.4376709
What I want is weekly returns added for say weeks 1 to 4, 5 to 8 and then plotted as a separate column