Measuring Overall ETFs Performance

Premium

We will now plot a graph to show the accumulated returns of the ETFs over a period of time.  We can do so by following the following steps:

  • Build a dataframe with the 4 ETFs prices and a date column. Calculate daily returns and cumulative returns. The cumsum() function returns the cumulative sums (i.e. the sum of all values up to a certain position of a vector).
  • Change the format of the data from wide shape to long shape with the gather() function from dplyr package.
  • Use ggplot2 to graph the ETFs performance in the whole period.

Unlock Premium Content

Upgrade your account to access the full article, downloads, and exercises.

You'll get access to:

  • Access complete tutorials and examples
  • Download source code and resources
  • Follow along with practical exercises
  • Get in-depth explanations