How to draw cumulative return chart with charts.performanceanalytics in R

185 Views Asked by At

I managed to produce time series dataframe(tibble) with two columns(Date, Cumprofit)

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)

enter image description here

I tried to draw chart with charts.performancesummary function in Performanceanalytics package, but failed.

What is the correct method to get this done?

charts.PerformanceSummary(a)

enter image description here

1

There are 1 best solutions below

0
Wookeun Lee On

I solved the problem

dt = xts(a[,-1], order.by = a$Date)
charts.PerformanceSummary(dt)