charts.PerformanceSummary()的交互式版本

charts.PerformanceSummary()的交互式版本,r,morris.js,rcharts,performanceanalytics,R,Morris.js,Rcharts,Performanceanalytics,我想使用rCharts创建一个交互式版本的charts.PerformanceSummary() 到目前为止,这是我的尝试…但我正在努力将其整合起来 # 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), Sy

我想使用
rCharts
创建一个交互式版本的
charts.PerformanceSummary()

到目前为止,这是我的尝试…但我正在努力将其整合起来

# 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
#加载xts和性能分析包
需要(xts)
要求(性能分析)
#生成rtns数据
种子集(123)

rtns“帮助我完成这个项目”太宽泛了。你没有“问题的几个部分”;您有8个问题,我相信您可以通过搜索找到其中一些问题的答案(例如,如何添加轴标签,整体标题)。不清楚这与D3有何关系,所以我删除了标记。我确实查找了如何添加轴和标题…但鉴于它是一个相对较新的包…我找不到太多…我认为这段代码可能会运行,因为它似乎有虚假的示例,但它重新运行了一系列因缺少对象和函数而导致的错误。@Dwin我编辑了代码以添加到的开发分支安装中rCharts…希望它现在可以运行…(例如,require(devtools)install_github('rCharts','ramnathv',ref='dev'))