[R-SIG-Finance] charts.PerformanceAnalytics plotting glitchy

Ilya Kipnis ||y@@k|pn|@ @end|ng |rom gm@||@com
Fri Dec 31 21:12:27 CET 2021


Ilya Kipnis <ilya.kipnis using gmail.com>
3:06 PM (5 minutes ago)
to r-sig-finance
Quick bug description: using charts.PerformanceSummary, the drawdown plot
looks like it has a gap.

Min reproducible example using a simple moving average crossover on SPY:

require(quantmod)
require(TTR)
require(PerformanceAnalytics)

sma_strat <- function(prices, n_short = 1, n_long = 200, lag = 2) {
  returns <- na.omit(Return.calculate(prices))
  out <- lag(SMA(prices, n_short) > SMA(prices, n_long), 2) * returns
  return(out)
}

stratStats <- function(rets) {
  stats <- rbind(table.AnnualizedReturns(rets), maxDrawdown(rets))
  stats[5,] <- stats[1,]/stats[4,]
  stats[6,] <- stats[1,]/UlcerIndex(rets)

  stats <- rbind(stats, Omega(rets), SortinoRatio(rets),
                 skewness(rets), kurtosis(rets), VaR(rets))
  rownames(stats)[4] <- "Worst Drawdown"
  rownames(stats)[5] <- "Calmar Ratio"
  rownames(stats)[6] <- "Ulcer Performance Index"
  return(stats)
}

getSymbols('SPY', from = '1990-01-01')


spy_SMA_1_200 <- sma_strat(Cl(SPY))
spy_SMA_50_200 <- sma_strat(Cl(SPY), 50, 200)

compare <- na.omit(cbind(spy_SMA_1_200, spy_SMA_50_200))
colnames(compare) <- c("SPY_1_200", "SPY_50_200")

charts.PerformanceSummary(compare)
stratStats(compare)

Output:



[image: image.png]

Notice the gap in the drawdowns in 2008-2009 on the black line.

Just something I noticed now.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20211231/38902bcb/attachment.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 243228 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20211231/38902bcb/attachment.png>


More information about the R-SIG-Finance mailing list