Session Ready
Exercise

Calculating the returns

In this lab, you will learn more about the analysis of stock returns by using the R packages PerformanceAnalytics, zoo and tseries (click them for more information).

We obtained the price series for multiple stocks from 1998 to 2009. These price series are already loaded into your environment as VBLTX_prices, FMAGX_prices and SBUX_prices. It is often convenient to store these time series in a single variable before we start the analysis. You will use the merge() function to do that, since it merges series by column while taking into account the time index.

Remember that the continuously compounded returns are defined as the difference between the log prices. Once all price series are merged by column, you can easily calculate the continuously compounded returns. Use the log() function to calculate the log prices and apply the diff() function to the object that contains the log prices to get the continuously compounded returns.

Instructions
100 XP
  • Assign to all_prices the merged price series VBLTX_prices, FMAGX_prices, SBUX_prices such that each column contains the prices of one stock.
  • Calculate the continuously compounded returns with the help of the diff() and log() functions.
  • Have a look at the data in the console.