PerformanceAnalytics icon indicating copy to clipboard operation
PerformanceAnalytics copied to clipboard

"ylog" is ignored in chart.CumReturns

Open gp2x opened this issue 7 years ago • 7 comments
trafficstars

I recently updated packages on my R installation and noticed that plots using a log-scale for the y-axis were no longer displaying correctly. Digging in, it looks like the "ylog" parameter for chart.CumReturns is now being ignored.

If I'm reading the code correctly, chart.CumReturns() calls chart.TimeSeries(), which calls chart.TimeSeries.base(), which has recently(?) been modified to call plot.xts(). However, looking at this commit: https://github.com/braverock/PerformanceAnalytics/commit/7f6665150628bd0baf79fbf5e1c518ec70e1ea9e

...it appears that since that modification there is now nothing done with the ylog parameter.

Basic example code: test <- xts(rep(0.01,1000),seq.Date(from=as.Date("2000-01-01"),to=as.Date("2002-09-26"),by=1)) chart.CumReturns(test,ylog=TRUE)

This plot should show a straight line, but now shows an exponential curve.

I am running R 3.4.4 and PerformanceAnalytics 1.5.2 on Antergos (Arch) Linux 64-bit. If you need any more details about my configuration let me know. Thanks!

gp2x avatar Mar 18 '18 21:03 gp2x

This may be related to this issue: https://github.com/braverock/PerformanceAnalytics/issues/1

... feel free to move things around if needed for cleanliness.

gp2x avatar Mar 18 '18 21:03 gp2x

For now, I've downgraded to 1.4.3541 using the instructions here: https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages

gp2x avatar Mar 24 '18 17:03 gp2x

Still an issue. logaxis = "y" shouldn't that variable passed into plot ?

https://github.com/braverock/PerformanceAnalytics/blob/master/R/chart.TimeSeries.builtin.R#L73

mcbain avatar Jul 07 '21 11:07 mcbain

Any plans to fix this? Really need a log chart here.

deaniceman avatar Aug 31 '22 23:08 deaniceman

This is likely dependent on https://github.com/joshuaulrich/xts/issues/103 being implemented.

joshuaulrich avatar Oct 11 '22 15:10 joshuaulrich

xts 0.13.2 is now out, but doesn't seem to fix this issue, perhaps @joshuaulrich can find an easy-ish fix for this now? I wouldn't say ylog parameter is "ignored" per se, but certainly doesn't produce a real log scale, and adding wealth.index=TRUE (to get rid of the 0 on the y-axis) doesn't help.

babbage9010 avatar Jan 25 '24 18:01 babbage9010

Thanks for giving this a try @babbage9010!

I just verified this works with the development version of the PerformanceAnalytics package if you set log = TRUE and wealth.index = TRUE. You need the development version for this to work, specifically this change.

Here's the linear scale plot from chart.CumReturns() as part of charts.PerformanceSummary().

library(PerformanceAnalytics)
data(edhec)
### linear scale
charts.PerformanceSummary(edhec)

image

And here's the log scale plot. Note that the legend doesn't appear on the log-scale plot due to this bug in addLegend().

### log scale
charts.PerformanceSummary(edhec, log = TRUE, wealth.index = TRUE)

image


So, to fix this issue, we need to send log = TRUE to plot.xts() when ylog = TRUE in chart.TimeSeries(). I would have to think about and test the best way to go about that.

We also need to handle the case when wealth.index = FALSE and there are negative values in the cumulative return series, since the log of negative numbers isn't defined.

joshuaulrich avatar Jan 25 '24 19:01 joshuaulrich