I'd just like to add--if you're going to ask Chatgpt4 for code, at least run it to see if it works and answers the questions properly >_<
On Tue, May 23, 2023, 1:11 PM Joshua Ulrich <[email protected]> wrote: > Hi Ed, > > It's not helpful to give an answer you're not sure is correct. > Especially from ChatGPT, which is known to confidently give wrong > answers. And that's what it did in this case. There are at least two > issues: > > 1. "chart.CumReturns.custom is a copy of the chart.CumReturns > function" is false. > The definition of chart.CumReturns.custom() isn't even close to the > definition of chart.CumReturns() in PerformanceAnalytics version > 2.0.4. You can find the actual chart.CumReturns() code on GitHub: > > https://github.com/braverock/PerformanceAnalytics/blob/691961b6a9d97cbc9c0660431f7bf0e9884cf03d/R/chart.CumReturns.R#L42 > > 2. The code you pasted throws an error. You could have run the code > yourself to see if it was correct. > i. The 'returns' object can't be converted to xts, which causes an > error > ii. It errors even if you make 'returns' an xts object because it > uses `class(x) == "numeric"` (which the real function does not) > > There's already enough noise in time series data. We don't need > ChatGPT adding even more noise. ;-) > > Regards, > Josh > > > On Mon, May 22, 2023 at 10:47 PM Ed Herranz <[email protected]> wrote: > > > > Jason, > > > > This is what ChatGPT 4.0 says. No guarantees that it is correct, though: > > > > The PerformanceAnalytics package in R does not provide direct options to > > remove the date from the title of the charts. > > > > However, it's possible to work around this by making a custom version of > > the function in which the date is added to the chart title, and removing > > the part of the code that adds the date. > > > > Below is an example using the chart.CumReturns function: > > > > library(PerformanceAnalytics) > > library(zoo) > > > > # Create a custom version of chart.CumReturns > > chart.CumReturns.custom <- function (R, wealth.index = FALSE, geometric = > > FALSE, > > main = "Cumulative Returns", ylab = "Cumulative Returns", > > xlab = "Date", ...) > > { > > # Convert to zoo for time series functionality > > R = checkData(R, method = "zoo") > > R = na.omit(R) > > > > # Calculate returns > > if (geometric) { > > returns = Return.cumulative(R, geometric = TRUE) > > } else if (wealth.index) { > > returns = Return.cumulative(R, geometric = TRUE) > > returns = cumprod(1 + returns) - 1 > > } else { > > returns = Return.cumulative(R, geometric = FALSE) > > } > > > > # Remove the date from the chart title > > chart.TimeSeries(returns, main = main, ylab = ylab, > > xlab = xlab, ...) > > } > > > > # Generate some example returns data > > returns = rnorm(100) > > > > # Create the chart > > chart.CumReturns.custom(returns) > > > > > > In this code, chart.CumReturns.custom is a copy of the chart.CumReturns > > function, with the part of the code that adds the date to the chart title > > removed. You can use this function just like chart.CumReturns, but it > will > > not include the date in the chart title. > > > > Note: This code was based on the PerformanceAnalytics 2.0.4 package as of > > my knowledge cut-off in September 2021. The specifics may change in later > > versions of the package. Be sure to check the function's code for the > > specific version of the package you are using. > > > > Regards, > > > > -Ed > > > > On Sun, Feb 26, 2023 at 12:20 PM Jason Hart via R-SIG-Finance < > > [email protected]> wrote: > > > > > Hello all - is it possible to remove the date that shows up by default > in > > > the main title (on the right hand side) in certain charts such as > > > chart.cumreturns, chart.rollingperformance, chart.rollingregression, > etc? > > > The date can crowd out and overlap with the main title on charts, > > > particularly if they're lined up side by side in a layout. I've tried > > > everything but I haven't had any luck. Thanks for any tips here. > > > > > > Jason > > > _______________________________________________ > > > [email protected] 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. > > > > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > [email protected] 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 > > _______________________________________________ > [email protected] 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. > [[alternative HTML version deleted]] _______________________________________________ [email protected] 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.
