[R-SIG-Finance] Performanceanalytics Charts - removing default date in title?

Ed Herranz ed@herr@nz @end|ng |rom gm@||@com
Tue May 23 05:47:31 CEST 2023


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 <
r-sig-finance using r-project.org> 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
> _______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list