Transactions Overview
Calculate and collect transaction overview ratios based on the provided data.
This method calculates various transaction overview ratios, such as returns, costs, and profit & loss (PnL), based on the transaction dataset. The calculated ratios are added as new columns to the portfolio dataset. It also provides the option to use different methods for calculating PnL (FIFO, LIFO, or AVERAGE). The method ensures that necessary historical and benchmark data is available before performing calculations.
Transactions Overview in Python
get_transactions_overview is part of the Portfolio module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_transactions_overview as shown below.
from financetoolkit import Portfolio
portfolio = Portfolio(example=True, api_key="FINANCIAL_MODELING_PREP_KEY")
portfolio.get_transactions_overview()
Which returns:
| Date | Name | Price | Volume | Costs | Currency | Invested Amount | Current Value | % Return | Return | PnL | Cumulative PnL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2024-02-01 | GOOGL | 140.041 | 14 | 0 | USD | 1960.57 | 5005.28 | 1.553 | 3044.71 | 0 | 0 |
| 2024-02-12 | BAC | 33.0126 | 5 | -3 | USD | 168.063 | 319.3 | 0.8999 | 151.237 | 0 | 56.8807 |
| 2024-02-22 | MCHI | 38.4963 | 7 | -1 | USD | 270.474 | 398.51 | 0.4734 | 128.036 | 0 | -4.77 |
| 2024-03-12 | MPWR | 727.32 | 11 | 0 | USD | 8000.52 | 15192.1 | 0.8989 | 7191.58 | 0 | 376.706 |
| 2024-05-14 | CAMT | 94.4243 | 4 | 0 | USD | 377.697 | 632.4 | 0.6744 | 254.703 | 0 | 99.4194 |
| 2024-06-11 | META | 505.574 | 8 | 0 | USD | 4044.59 | 4759.36 | 0.1767 | 714.771 | 0 | 0 |
| 2024-06-18 | MPWR | 847.6 | 14 | -1 | USD | 11867.4 | 19335.4 | 0.6293 | 7468 | 0 | 376.706 |
| 2024-07-30 | AMD | 139.57 | 3 | 0 | USD | 418.711 | 1408.68 | 2.3643 | 989.97 | 0 | 9.795 |
| 2024-10-25 | MCHI | 48.8436 | 6 | 0 | USD | 293.062 | 341.58 | 0.1656 | 48.5183 | 0 | -4.77 |
| 2024-11-13 | VOO | 552.136 | 11 | 0 | USD | 6073.5 | 7817.15 | 0.2871 | 1743.65 | 0 | 131.082 |
Parameters
get_transactions_overview accepts the following parameters:
- rounding (int | None): The number of decimal places to round the output to. If None, it defaults to the rounding specified in the configuration.
- exclude_sold_positions (bool): A flag indicating whether to exclude sold positions
- pnl_method (str): The method for calculating profit & loss. Options are: ‘FIFO’ (First In, First Out), ‘LIFO’ (Last In, First Out), or ‘AVERAGE’. Defaults to ‘FIFO’.