Session Ready
Exercise

The time series of asset returns

Calculating the returns for one period is pretty straightforward to do in R. When the returns need to be calculated for different dates the functions Return.calculate() and Return.portfolio(), in the R package PerformanceAnalytics are extremely helpful. They require the input data to be of the xts-time series class, which is pre-loaded. You will explore the functionality of the PerformanceAnalytics package in this exercise.

The object prices which contains the Apple (aapl) and Microsoft (msft) stocks is available in the workspace.

Instructions
100 XP
  • Load the package PerformanceAnalytics in your R session.
  • Have a look at the first and last six rows of prices, using head() and tail() respectively.
  • Use the function Return.calculate() with the only argument prices to compute for each date the return as the percentage change in the price compared to the previous date, call this returns.
  • Print the first six rows of returns.
  • Remove the first row of returns.