1

所以我使用 PerformanceAnalytics 包来绘制一个简单的 PnL 系列的性能摘要,所以

library(xts)
library(PerformanceAnalytics)

dates <- structure(c(14008, 14011, 14012, 14013, 14014, 14015, 14018, 14019, 14020, 14021),
                   class = "Date")

PnL.xts = structure(c(0, -0.00510803851321091, -0.0102109843849305, -0.00138369232677364, 
                      -0.00255257489213331, -0.00200279255353461, 0.0104232666033935, 
                      0.00181846800788812, 4.72633257030091e-05, 0.0138334493571853),
                    .Dim = c(10L, 1L),
                    index = structure(c(1210291200, 1210550400, 1210636800, 1210723200,
                                        1210809600, 1210896000, 1211155200, 1211241600,
                                        1211328000, 1211414400),
                                      tzone = "UTC", tclass = "Date"),
                   .indexCLASS = "Date", tclass = "Date",
                   .indexTZ = "UTC", tzone = "UTC", .Dimnames = list(NULL, "PnL"),
                   class = c("xts", "zoo"))

PnL.cum = cumsum(PnL.xts)
ret.ann = Return.annualized(PnL.xts, geometric = FALSE)
ret.cum = Return.cumulative(PnL.xts, geometric = FALSE)
ret.min = min(PnL.cum)
stdev = StdDev.annualized(PnL.xts)
sharpe = SharpeRatio.annualized(PnL.xts, geometric = FALSE)

stats = paste(paste("Annualized Return:", percent(round(ret.ann, 5))),
              paste("Cumulative Return:", percent(round(ret.cum, 5))),
              paste("Standard Deviation:", round(stdev, 5)),
              paste("Sharpe Ratio:", round(sharpe, 5)), sep = '\n' )
lag = 1
descr = paste("Following fitted Granger model - ", lag, " day lag", sep = "")

charts.PerformanceSummary(R = PnL.xts, geometric = FALSE)
text(midrange(dates),ret.min, labels = stats, cex = 1)
mtext(descr, side = 3, line = 31)

但是,我想在累积 PnL 图表中添加一些描述性文本,例如年化收益、累积收益、标准差和锐化。如何将其粘贴到第一张图中的空白处?

如果我自己绘制图表,我可以用上面的代码来做。但是,由于 charts.PerformanceSummary 函数自动绘制 3 个图,我只能访问它看起来的第 3 个图。有什么方法可以访问函数打印的 3 个图表中的第一个,以便我可以在其上相对于其自身坐标编写文本?

这是我想要的一个例子:http: //i.imgur.com/QXUb2Aq.png。但在这种情况下,我必须手动测试 y 坐标的值,直到我找到可行的方法。谢谢!

4

0 回答 0