LoslegenKostenlos loslegen

Highlighting a specific period in a time series

To highlight a specific period in a time series, you can display it in the plot in a different background color. The chart.TimeSeries() function in the PerformanceAnalytics package offers a very easy and flexible way of doing this.

Let's examine some of the arguments of this function:

chart.TimeSeries(R, period.areas, period.color)

R is an xts, time series, or zoo object of asset returns, period.areas are shaded areas specified by a start and end date in a vector of xts date ranges like c("1926-10/1927-11"), and period.color draws the shaded region in whichever color is specified.

In this exercise, you will highlight a single period in a chart of the Citigroup time series in data.

Diese Übung ist Teil des Kurses

Visualizing Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

  • Create an object called period containing the first three months of 2015
  • Using the chart.TimeSeries() function, highlight the citigroup data values in the period
  • Use chart.TimeSeries() again to redraw the same line chart but this time set the color of the highlighted period to "lightgrey"

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Create period to hold the 3 months of 2015


# Highlight the first three months of 2015 


# Highlight the first three months of 2015 in light grey
 
Code bearbeiten und ausführen