[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-finance
Subject:    Re: [R-SIG-Finance] charts.PerformanceAnalytics plotting glitchy
From:       Joshua Ulrich <josh.m.ulrich () gmail ! com>
Date:       2022-01-03 15:03:21
Message-ID: CAPPM_gSwFLy0n26T7n1xQriQ+cjXjMT5x1--WMgdSC8CiaagcQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/related)]

[Attachment #4 (multipart/alternative)]


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@gmail.com> wrote:

> Ilya Kipnis <ilya.kipnis@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@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

[Attachment #7 (text/html)]

<div dir="ltr"><div>Hi Ilya,</div><div><br></div><div>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.</div><div><br></div><div>Best,</div><div>Josh</div><div><br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 31, 2021 at 2:12 PM \
Ilya Kipnis &lt;<a href="mailto:ilya.kipnis@gmail.com">ilya.kipnis@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div \
style="float:none;padding:0px \
16px;display:flex;height:80px;min-width:40px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:medium"><div><img \
id="gmail-m_-2668333868403416165gmail-:17p_156-e" name="m_-2668333868403416165_:17p" \
src="https://lh3.googleusercontent.com/a-/AOh14Gj_FKv4Bmfl9gP4I_NhX4ZV7P3ZDMR8K8Ln293L=s40" \
aria-hidden="true" style="display: block; width: 40px; height: 40px; border-radius: \
50%; background-color: rgb(204, 204, 204);"></div></div><div \
style="margin:0px;padding:0px 0px \
20px;width:1290.67px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:medium"><div \
style="padding:20px 0px 0px;font-size:0.875rem"><table \
style="border-collapse:collapse;margin-top:0px;width:auto;font-size:0.875rem;letter-spacing:0.2px;display:block" \
cellpadding="0"><tbody style="display:block"><tr style="height:auto;display:flex"><td \
style="white-space:nowrap;padding:0px;vertical-align:top;width:1032.46px;line-height:20px;display:block;max-height:20px"><table \
style="border-collapse:collapse;table-layout:fixed;width:1032.46px" \
cellpadding="0"><tbody><tr><td style="display:flex"><h3 \
style="overflow:hidden;font-size:0.75rem;font-weight:inherit;margin:inherit;text-overflow:ellipsis;letter-spacing:0.3px;color:rgb(95,99,104);line-height:20px"><span \
role="gridcell"><span name="Ilya Kipnis" \
style="color:rgb(32,33,36);font-size:0.875rem;font-weight:bold;display:inline;vertical-align:top;letter-spacing:0.2px;line-height:20px"><span \
style="vertical-align:top">Ilya Kipnis</span></span>  <span \
style="vertical-align:top;color:rgb(85,85,85)"><span aria-hidden="true">&lt;</span><a \
href="mailto:ilya.kipnis@gmail.com" target="_blank">ilya.kipnis@gmail.com</a><span \
aria-hidden="true">&gt;</span></span></span></h3></td></tr></tbody></table></td><td \
style="text-align:right;white-space:nowrap;vertical-align:top;display:block;max-height:20px"><div \
style="padding:0px;display:flex"><span id="gmail-m_-2668333868403416165gmail-:8kw" \
title="Dec 31, 2021, 3:06 PM" alt="Dec 31, 2021, 3:06 PM" role="gridcell" \
style="vertical-align:top;margin:0px;font-size:0.75rem;letter-spacing:0.3px;color:rgb(95,99,104);display:block;line-height:20px">3:06 \
PM (5 minutes ago)</span><div aria-label="Not starred" title="Not starred" \
role="checkbox" aria-checked="false" \
style="display:inline-block;height:20px;margin-left:20px;outline:currentcolor none \
0px"><span style="display:inline-flex;height:20px;text-align:center;width:20px;padding:0px;margin:0px;border:medium \
none;outline:currentcolor none medium"></span></div></div></td><td \
style="text-align:right;white-space:nowrap;vertical-align:top;display:flex"></td><td \
rowspan="2" style="text-align:right;white-space:nowrap;vertical-align:top;display:block;max-height:20px"><div \
role="button" aria-label="Reply" style="display:inline-flex;border-radius:2px 0px 0px \
2px;font-size:0.875rem;text-align:center;margin:0px 0px 0px \
20px;height:20px;line-height:18px;min-width:0px;outline:currentcolor none \
medium;padding:0px;background:transparent none repeat scroll 0% \
0%;color:rgb(68,68,68);border:medium none"><img role="button" \
src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="" style="background: \
rgba(0, 0, 0, 0) url(&quot;https://ci5.googleusercontent.com/proxy/sgSzsQRyQRmsv2OE-iz \
G98u3VkpnGw0M_zKrRSeaYyRsXTjZwl149BuSuK7uLP3890VjX_KW27JcgWxhOB8kpUUp3EyKgATzOUPy0uzvf \
AxLPQwYnUD58AbvJ6O4y-7cMtQ=s0-d-e1-ft#https://www.gstatic.com/images/icons/material/system_gm/1x/reply_black_20dp.png&quot;) \
no-repeat scroll 50% 50% / 20px; height: 20px; margin: 0px; vertical-align: middle; \
width: 20px; opacity: 0.7; display: inline-block; padding: 0px;"></div><div \
id="gmail-m_-2668333868403416165gmail-:8re" role="button" aria-expanded="false" \
aria-haspopup="true" aria-label="More" style="display:inline-flex;border-radius:0px \
2px 2px 0px;font-size:0.875rem;text-align:center;margin:0px 0px 0px \
20px;height:20px;line-height:18px;min-width:0px;outline:currentcolor none \
medium;padding:0px;background:transparent none repeat scroll 0% \
0%;color:rgb(68,68,68);border:medium none"><img role="menu" \
src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="" style="background: \
rgba(0, 0, 0, 0) url(&quot;https://ci5.googleusercontent.com/proxy/1J5Lh-GYVsVXJXT-tzQ \
GnDdXABaA2JI051HnEhPCBlFtMUO9zCICiX55yBOVHetZxFN0H1luWES1vh8bFWUnRkjMcDt1nUZwoCXZoCGa6 \
ZPK2TktNGBlAqmtYHZpeytSCD1VAwps=s0-d-e1-ft#https://www.gstatic.com/images/icons/material/system_gm/1x/more_vert_black_20dp.png&quot;) \
no-repeat scroll 50% 50% / 20px; height: 20px; width: 20px; margin: 0px; \
vertical-align: middle; opacity: 0.7; display: inline-block; padding: \
0px;"></div></td></tr><tr style="height:auto;display:flex"><td colspan="3"><table \
style="border-collapse:collapse;table-layout:fixed;white-space:nowrap;width:1290.67px" \
cellpadding="0"><tbody><tr><td \
style="overflow:visible;text-overflow:ellipsis;display:flex;line-height:20px"><div \
style="overflow:hidden;max-width:92%;display:inline-block"><span \
style="vertical-align:top;color:rgb(95,99,104);font-size:0.75rem;letter-spacing:0.3px;line-height:20px">to \
<span name="r-sig-finance" \
style="vertical-align:top">r-sig-finance</span></span></div><div \
id="gmail-m_-2668333868403416165gmail-:8jl" aria-haspopup="true" role="button" \
aria-label="Show details" \
style="display:inline-flex;margin-left:4px;vertical-align:top;border:medium \
none;outline:currentcolor none medium"><img \
src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="" style="background: \
rgba(0, 0, 0, 0) url(&quot;https://ci6.googleusercontent.com/proxy/Bn-WVNI_gjIXNsB8AUe \
oUq_iIiKwp2uQkyt49MgAK_ReicH0gp-qPe_YyUNnOgDl1ba-BzrPGguOgmLCID4EouM5uXvi1xrpZXALsBLrm \
GBuibaVFtcbuSQ71pCOzbZOiU_7GdohG5acZRtz=s0-d-e1-ft#https://www.gstatic.com/images/icons/material/system_gm/1x/arrow_drop_down_black_20dp.png&quot;) \
no-repeat scroll 50% 50% / 20px; padding: 0px; vertical-align: baseline; height: \
20px; width: 20px; border: medium none; margin: 0px 0px 0px auto; display: flex; \
opacity: 0.71;"></div></td></tr></tbody></table></td></tr></tbody></table></div><div \
id="gmail-m_-2668333868403416165gmail-:8kt"><div></div><div></div><div></div><div></div></div><div><div></div><div \
id="gmail-m_-2668333868403416165gmail-:8jk"></div><div \
id="gmail-m_-2668333868403416165gmail-:8ku" \
style="font-size:0.875rem;direction:ltr;margin:8px 0px 0px;padding:0px"><div \
id="gmail-m_-2668333868403416165gmail-:8jj" \
style="overflow:hidden;font-variant-numeric:normal;font-variant-east-asian:normal;font \
-stretch:normal;font-size:small;line-height:1.5;font-family:Arial,Helvetica,sans-serif"><div \
dir="ltr">Quick bug description: using charts.PerformanceSummary, the drawdown plot \
looks like it has a gap.<div><br></div><div>Min reproducible example using a simple \
moving average crossover on \
SPY:</div><div><br></div><div>require(quantmod)<br>require(TTR)<br>require(PerformanceAnalytics)<br><br>sma_strat \
&lt;- function(prices, n_short = 1, n_long = 200, lag = 2) {<br>   returns &lt;- \
na.omit(Return.calculate(prices))<br>   out &lt;- lag(SMA(prices, n_short) &gt; \
SMA(prices, n_long), 2) * returns<br>   return(out)<br>}<br><br>stratStats &lt;- \
function(rets) {<br>   stats &lt;- rbind(table.AnnualizedReturns(rets), \
maxDrawdown(rets))<br>   stats[5,] &lt;- stats[1,]/stats[4,]<br>   stats[6,] &lt;- \
stats[1,]/UlcerIndex(rets)<br>  <br>   stats &lt;- rbind(stats, Omega(rets), \
SortinoRatio(rets),<br>                          skewness(rets), kurtosis(rets), \
VaR(rets))<br>   rownames(stats)[4] &lt;- &quot;Worst Drawdown&quot;<br>   \
rownames(stats)[5] &lt;- &quot;Calmar Ratio&quot;<br>   rownames(stats)[6] &lt;- \
&quot;Ulcer Performance Index&quot;<br>   \
return(stats)<br>}<br><br>getSymbols(&#39;SPY&#39;, from = \
&#39;1990-01-01&#39;)<br><br><br>spy_SMA_1_200 &lt;- \
sma_strat(Cl(SPY))<br>spy_SMA_50_200 &lt;- sma_strat(Cl(SPY), 50, 200)<br><br>compare \
&lt;- na.omit(cbind(spy_SMA_1_200, spy_SMA_50_200))<br>colnames(compare) &lt;- \
c(&quot;SPY_1_200&quot;, \
&quot;SPY_50_200&quot;)<br><br>charts.PerformanceSummary(compare)<br>stratStats(compar \
e)<br></div><div><br></div><div>Output:</div><div><br></div><div><br></div><div><br></div><div><img \
src="cid:ii_kxuu1e4r0" alt="image.png" width="542" \
height="424"><br></div><div><br></div><div><div>Notice the gap in the drawdowns in \
2008-2009 on the black line.</div><div><br></div><div>Just something I noticed \
now.</div></div></div></div></div></div></div></div> \
_______________________________________________<br> <a \
href="mailto:R-SIG-Finance@r-project.org" \
target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br> <a \
href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" rel="noreferrer" \
                target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a><br>
                
-- Subscriber-posting only. If you want to post, subscribe first.<br>
-- Also note that this is not the r-help list where general R questions should \
go.<br> </blockquote></div><br clear="all"><br>-- <br><div dir="ltr" \
class="gmail_signature">Joshua Ulrich   |   <a href="http://about.me/joshuaulrich" \
target="_blank">about.me/joshuaulrich</a><br>FOSS Trading   |   <a \
href="http://www.fosstrading.com" target="_blank">www.fosstrading.com</a></div>

--00000000000054e28805d4aed30c--


["image.png" (image/png)]

_______________________________________________
R-SIG-Finance@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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic