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

Joshua Ulrich jo@h@m@u|r|ch @end|ng |rom gm@||@com
Mon Jan 3 16:03:21 CET 2022


Hi Ilya,

It looks like this is an artifact of how that part of the plot is drawn.
The grid line and black drawdown line nearly overlap. I can see the line if
I make the plot larger.

Best,
Josh


On Fri, Dec 31, 2021 at 2:12 PM Ilya Kipnis <ilya.kipnis using gmail.com> wrote:

> 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.
> _______________________________________________
> R-SIG-Finance using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>


-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20220103/4ae50c02/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/20220103/4ae50c02/attachment.png>


More information about the R-SIG-Finance mailing list