Calculating Stock Returns and Portfolio Returns in R

Premium

To calculate the returns of AAPL & GOOG over the time period, you can use the Return.calculate function.

1stockReturns <- Return.calculate(adjustedPrices)
2head(stockReturns)
3##            AAPL.Adjusted GOOG.Adjusted
4## 2017-01-03            NA            NA
5## 2017-01-04  -0.001119178  0.0009667604
6## 2017-01-05   0.005085153  0.0090481583
7## 2017-01-06   0.011148442  0.0152766979
8## 2017-01-09   0.009159465  0.0006202319
9## 2017-01-10   0.001008411 -0.0023058897
10

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