Calculate transaction performance metrics for a specified period.

This method calculates per asset and period how the units bought in that period performed up to the end of the period, next to the return the identical purchases would have made in the benchmark. The following columns are included:

  • Volume: the net volume traded in the period, i.e. buys minus sells.
  • Price: the volume-weighted average price paid for the units bought in the period.
  • Costs: the transaction costs of the period, of buys and sells.
  • Invested Amount: the value of the units bought plus the costs of those buys.
  • Realized Proceeds: the cash received from sales in the period.
  • Current Value: the units bought in the period at the closing price at the end of the period.
  • Dividends: the cash dividends those units received up to the end of the period.
  • Return: (Current Value + Dividends - Invested Amount) / Invested Amount, NaN in a period without purchases.
  • Benchmark Return: the same return for benchmark units bought with the same money on the same dates, dividends included.
  • Alpha: Return minus Benchmark Return.

Sales are reported but left out of the return: the units sold in a period were usually bought in an earlier one, and their proceeds would credit this period’s purchases with the gains of earlier ones. Units are valued at the traded closing price and receive their dividends as cash.

Transactions Performance in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_transactions_performance as shown below.

from financetoolkit import Portfolio

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

portfolio.get_transactions_performance(period='quarterly')

Which returns:

  Volume Price Costs Invested Amount Realized Proceeds Current Value Dividends Return Benchmark Return Alpha
(Period(‘2023Q4’, ‘Q-DEC’), ‘MCHI’) 15 43.29 -3 652.35 0 611.1 14.9115 -0.0404 0.0856 -0.1259
(Period(‘2024Q1’, ‘Q-DEC’), ‘BAC’) 5 33.62 -3 171.1 0 189.6 1.2 0.1151 0.028 0.0872
(Period(‘2024Q1’, ‘Q-DEC’), ‘GOOGL’) 14 141.16 0 1976.24 0 2113.02 0 0.0692 0.071 -0.0018
(Period(‘2024Q1’, ‘Q-DEC’), ‘MCHI’) 7 39.77 -1 279.39 0 278.11 0 -0.0046 0.0292 -0.0338
(Period(‘2024Q1’, ‘Q-DEC’), ‘MPWR’) 11 736.55 0 8102.05 0 7451.62 13.75 -0.0786 0.0153 -0.0939
(Period(‘2024Q2’, ‘Q-DEC’), ‘CAMT’) 4 94.11 0 376.44 0 500.96 0 0.3308 0.0407 0.29
(Period(‘2024Q2’, ‘Q-DEC’), ‘META’) 8 507.47 0 4059.76 0 4033.76 4 -0.0054 0.0158 -0.0213
(Period(‘2024Q2’, ‘Q-DEC’), ‘MPWR’) 14 852.56 -1 11936.8 0 11503.5 17.5 -0.0348 -0.0049 -0.0299
(Period(‘2024Q4’, ‘Q-DEC’), ‘MCHI’) 6 49.85 0 299.1 0 281.16 5.3466 -0.0421 0.0127 -0.0548
(Period(‘2024Q4’, ‘Q-DEC’), ‘VOO’) 11 549.03 0 6039.33 0 5926.91 19.1235 -0.0154 -0.0173 0.0019

Parameters

get_transactions_performance accepts the following parameters.

ParameterTypeDescriptionExample
periodstr | NoneThe time period for which transaction performance metrics should be calculated. This can be one of the following: ‘yearly’, ‘quarterly’, ‘monthly’, ‘weekly’, or ‘daily’. If None, the default is ‘quarterly’ if the ‘quarterly’ attribute is set to True, otherwise ‘yearly’."quarterly"
exclude_sold_positionsboolWhether to leave out the periods without an invested amount, those in which only units bought earlier were sold, and those whose only purchases cost nothing (a price of 0), which have no return to measure. Defaults to True.False
roundingint | NoneThe number of decimal places to round the output to. If None, it defaults to the rounding specified in the configuration.2
Share