Skip to content

Incorrect portfolio return calculation in financial workshop documentation #393

@wjb75

Description

@wjb75

In the Financial Data Analysis with Spyder workshop, the portfolio return is calculated using:

rets_1 = np.log(close_data_1/close_data_1.shift(1)).dropna()
weights_1 = [0.2, 0.2, 0.2, 0.2, 0.2]
def portfolio_return(returns, weights):
    return np.dot(returns.mean(), weights) * 252

problems

This approach is problematic for two reasons:

  1. Arithmetic scaling of returns: Multiplying the mean daily return by 252 assumes linearity and ignores compounding, which misrepresents actual portfolio performance.

  2. Log scale mismatch: If returns are log returns (as is common in financial analysis), the formula incorrectly averages them arithmetically. This leads to inaccurate results, as shown in this example:

Invest $50 in Stock A (100% gain) and $50 in Stock B (0% gain)

True portfolio return: 50%

Log returns: log(2) and log(1)

Arithmetic mean of log returns: log(2)/2 ≈ 0.3466

Exponentiated result: exp(0.3466) - 1 ≈ 41.42% → incorrect

suggested fix

  1. Use the terminal value (raw, not logged) for returns to avoid scaling the log returns with linear weights.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions