图表的交互式版本.PerformanceSummary()

时间:2013-09-12 13:33:01

标签: r morris.js rcharts performanceanalytics

我想使用charts.PerformanceSummary()创建rCharts的互动版本。

这是我迄今为止的尝试......但我正在努力将它们放在一起......

# Load xts and PerformanceAnalytics package
require(xts)
require(PerformanceAnalytics)
# Generate rtns data
set.seed(123)
X.stock.rtns <- xts(rnorm(1000,0.00001,0.0003), Sys.Date()-(1000:1))  
Y.stock.rtns <- xts(rnorm(1000,0.00003,0.0004), Sys.Date()-(1000:1))
Z.stock.rtns <- xts(rnorm(1000,0.00005,0.0005), Sys.Date()-(1000:1))
rtn.obj <- merge(X.stock.rtns , Y.stock.rtns, Z.stock.rtns)
colnames(rtn.obj) <- c("x.stock.rtns","y.stock.rtns","z.stock.rtns")

# The below output is what we are aiming for
charts.PerformanceSummary(rtn.obj,lwd=1,main="Performance of stocks x,y and z")

# So this is what I have tried to do to replicate the data and try and generate graphs

# custom function to convert xts to data.frame
xts.2.df <- function(xts.obj){
   df <- ggplot2:::fortify(xts.obj)
   df[,1] <- as.character(df[,1])
   df
}

# calculating the data for the top and bottom graph
cum.rtn <- do.call(merge,lapply(seq(ncol(rtn.obj)),function(y){cumprod(rtn.obj[,y]+1)-1}))
dd.rtn <- do.call(merge,lapply(seq(ncol(rtn.obj)),function(y){Drawdowns(rtn.obj[,y])}))

# Loading rCharts package
require(devtools)
install_github('rCharts', 'ramnathv',ref='dev')
require(rCharts)
# creating the first cumulative return graph
m1 <- mPlot(x = "Index", y = c("x.stock.rtns","y.stock.rtns","z.stock.rtns"), type = "Line", data = xts.2.df(cum.rtn),
             pointSize = 0, lineWidth = 1)
# Top cumulative return graph
m1

# Creating the individual bar graphs that are to be shown when one line is hovered over
m.x <- mPlot(x = "Index", y = c("x.stock.rtns"), type="Bar",data = xts.2.df(rtn.obj))
m.y <- mPlot(x = "Index", y = c("y.stock.rtns"), type="Bar",data = xts.2.df(rtn.obj))
m.z <- mPlot(x = "Index", y = c("z.stock.rtns"), type="Bar",data = xts.2.df(rtn.obj))

# Creating the drawdown graph
m2 <- mPlot(x = "Index", y = c("x.stock.rtns","y.stock.rtns","z.stock.rtns"), type = "Line", data = xts.2.df(dd.rtn),
            pointSize = 0, lineWidth = 1)
m2

因此问题的部分内容很少:

  1. 如何将三个morris.js图表​​放在一起以便它们相互连接?
  2. 您可以在顶部图表(m1)中加粗悬停的线条吗?
  3. 你如何得到中间的一个(即m.xm.ym.z中的一个)根据悬停的内容进行更改,即如果将鼠标悬停在库存z上,则库存z的回报(m.z)出现在中间?
  4. 你可以在底部的图表中使用粗体,在顶部图表中使用粗体显示相同的资产吗?
  5. 您是否可以更改浮动框中显示的信息,以显示有关正在悬停的资产的一些统计信息?
  6. 如何添加轴标签?
  7. 如何添加整体标题?
  8. 奖励:如何将crossfilter.js集成到其中,以便可以选择一部分时间......并重新绘制所有图表?
  9. 即使您无法回答所有部分,也不胜感激任何帮助/评论/答案......

0 个答案:

没有答案