Return Contributions

Calculate how much each position added to the portfolio’s return in every period.

The periods are weeks, months, quarters or years, and the contributions add up to the portfolio’s return of that period. Every day a position contributes its weight in the portfolio at the previous close times its return, \(c_{i,t} = w_{i,t} - 1 r_{i,t}\), and over a longer period the daily contributions are carried by the growth of the portfolio since the period began, \(C_{i} = \sum_{t} c_{i,t} \Pi_{s < t} (1 + R_{s})\), so they add up to the compounded return of the portfolio (Bacon, 2008). It is toolkit.portfolio.get_return_contributions with the weights of the positions as they moved from day to day.

The returns are the total returns of the assets (dividends reinvested) and the weights the Current Weight of the positions overview, so a purchase or a sale changes the weights from the next day on and is no return itself.

Also known as: contribution to return, return attribution by position.

Example

Install the Finance Toolkit with pip install financetoolkit -U, then call get_return_contributions:

from financetoolkit import Portfolio

portfolio = Portfolio(example=True, api_key="FINANCIAL_MODELING_PREP_KEY")

portfolio.get_return_contributions(period="yearly")[
    ["ASML", "MSFT", "NVDA", "AMZN", "Portfolio"]
]

Which returns:

Parameters

get_return_contributions accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period to add the contributions up over. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “monthly”."weekly"
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Portfolio’s rounding.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Bacon, C. R. (2008). “Practical Portfolio Performance Measurement and Attribution.” 2nd edition, Wiley, chapter 5.
  • Library Shares similar logic as PerformanceAnalytics (R)’s to.period.contributions
Share