Skip to content
All library documents

Compounding Portfolio Returns Across Securities and Time

Article Quant Q&A · Author: David

Summary

The document distinguishes portfolio returns across securities at one point in time from cumulative returns across time. In its example, the daily portfolio return comes from comparing the combined closing value of one share of each holding with their combined opening value. For successive days, simple returns are compounded by multiplying each period’s growth factor, one plus the return; cumulative log returns can instead be added and then converted back to a simple return by exponentiation.

The answers illustrate both approaches with a three-day numerical example and an S&P 500 price series, where the simple-return and log-return calculations produce nearly identical cumulative results. They note that log returns are convenient for mathematical work, while compounded simple returns are adequate for many practical uses such as strategy backtests. The example assumes the stated holdings and return calculations; when portfolio constituents or share counts change, the return series must reflect the actual portfolio value and weights for each period.

Key ideas

  • Simple returns compound over time by multiplying one plus each period’s return.
  • Log returns add across time and can be converted to cumulative simple returns by exponentiation.
  • A portfolio’s return at a given time depends on the values and holdings of its constituent securities.
  • The two compounding methods give equivalent cumulative results when applied consistently.

Tags

Full text
# Calculating log-returns across multiple securities and time


# Calculating log-returns across multiple securities and time












I've been getting very confused on the topic of calculating returns. To get cumulative returns in time, log-returns are used, but apparently log-returns aren't used across different securities at a fixed time?

I would like to get cumulative returns as a function of time over my portfolio.

I have two securities, A and B. I buy one share of both A and B when the market opens and sell when it closes.

Suppose these are the prices for a specific day:

```
    open    close
A   9       10
B   10      8
```

My overall return for that day is `(10+8)/(10+9) - 1 = -5.2%`. I store that -5.2% for that day. I repeat this for many days. How do I then calculate my cumulative sum? If it helps, I'm doing this in python.

Side note: I can use a `cumsum()` function very easily in python, but that assumes log-returns. I have no issue working with log-returns, but I'm not sure how to go about doing that.

I will add that I always purchase 1 share of whatever security is in my portfolio for that day. The securities in my portfolio change over the course of time.

## Answer by Sergey Bushmanov (score 7, accepted)

https://quant.stackexchange.com/a/21104

In Python, simple geometric returns:

```
    import numpy as np
    import pandas as pd
    sp500 = pd.io.data.DataReader('^GSPC', 'yahoo')['Close']
    simple_ret = sp500.pct_change()
    (1+simple_ret).cumprod()[-1] -1

    0.74751768460019963
```

Log-returns:

```
    log_ret = np.log(1+simple_ret)
    np.exp(log_ret.cumsum()[-1]) -1

    0.74751768460020074
```

In Quantitative Finance, doing your math in log-returns considered good manners, however for many practical applications (backtesting trading strategies e.g.), simple geometric returns suffice.

## Answer by Brumder (score 1)

https://quant.stackexchange.com/a/21094

When doing series like this in Python, I usually just add 1 to each return, then multiply across these sums for cumulative returns. Such as, if my returns over three days were -5.2%, 2.1% & 4.8%, then the values I would store would be:

> 1 + (-0.052) = 0.948 1 + (0.021) = 1.021 1 + (0.048) = 1.048

Then, to calculate my cumulative returns, I would just multiply (0.948)(1.021)(1.048) - 1 = 0.0144 or 1.44%.

This works especially well with arrays in Python, where you can store each return as an array in a larger array, allowing you to date index each part of the series then slice it however you want. Happy to work through the code for this if you provide me more detail on your data set.

## Answer by Carlos BL (score 0)

https://quant.stackexchange.com/a/74954

A simple example of use of simple geometric returns vs log returns:

```
import numpy as np
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt

# Load the S&P 500 stock index data
sp500 = yf.download('^GSPC')

# Calculate the daily simple returns
simple_ret = sp500['Adj Close'].pct_change()

# Calculate the total return using simple returns
total_ret_simple = (1 + simple_ret).cumprod()

# Calculate the daily log returns
log_ret = np.log(1 + simple_ret)

# Calculate the total return using log returns
total_ret_log = np.exp(log_ret.cumsum())

# Plot the daily simple returns and daily log returns
fig, ax = plt.subplots(figsize=(10, 5))
simple_ret.plot(ax=ax, label='Simple Returns')
log_ret.plot(ax=ax, label='Log Returns')
ax.legend()
ax.set(title='Daily Returns of S&P 500', ylabel='Return')
plt.show()

# Plot the cumulative simple returns and cumulative log returns
fig, ax = plt.subplots(figsize=(10, 5))
total_ret_simple.plot(ax=ax, label='Simple Returns')
total_ret_log.plot(ax=ax, label='Log Returns')
ax.legend()
ax.set(title='Cumulative Returns of S&P 500', ylabel='Return')
plt.show()

# Print the difference between the two total returns
print('Difference between total returns:', total_ret_simple[-1] - total_ret_log[-1])
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.