如何在R中使用charts.performanceanalytics绘制累积回报图表
Posted
技术标签:
【中文标题】如何在R中使用charts.performanceanalytics绘制累积回报图表【英文标题】:How to draw cumulative return chart with charts.performanceanalytics in R 【发布时间】:2021-05-22 06:09:01 【问题描述】:我设法生成了包含两列(日期、累积利润)的时间序列数据框(tibble)
a = dayt %>% mutate(buy = ifelse((foreignNetbuy > 0 || instNetbuy > 0) &
priceClose < 1500000 &
rise > 3 &
rise < 25 &
candle == 1 &
middle > -1 &
disparity > 100 &
disparity < 120 &
amount > 7500000000,1,0)) %>%
filter(buy == 1) %>%
select(logDate,stockCode, ovnprofit, buy) %>%
group_by(logDate) %>%
summarize(count = sum(buy),
avgprofit = mean(ovnprofit, na.rm = TRUE)) %>%
mutate(profit = ifelse(count > 60, avgprofit, (avgprofit*count + 60-count)/60)) %>%
arrange(logDate) %>%
as_tibble() %>%
mutate(Date = ymd(logDate),
Cumprofit = cumprod(profit)) %>%
select(Date,Cumprofit)
我尝试使用 Performanceanalytics 包中的 charts.performancesummary 函数绘制图表, 但失败了。
完成这项工作的正确方法是什么?
charts.PerformanceSummary(a)
【问题讨论】:
【参考方案1】:我解决了问题
dt = xts(a[,-1], order.by = a$Date)
charts.PerformanceSummary(dt)
【讨论】:
以上是关于如何在R中使用charts.performanceanalytics绘制累积回报图表的主要内容,如果未能解决你的问题,请参考以下文章