Skip to content

Fix realized capital gains calculation and add period adjustment#5666

Closed
Morpheus1w3 wants to merge 1 commit intoportfolio-performance:masterfrom
Morpheus1w3:fix-gain-calculation
Closed

Fix realized capital gains calculation and add period adjustment#5666
Morpheus1w3 wants to merge 1 commit intoportfolio-performance:masterfrom
Morpheus1w3:fix-gain-calculation

Conversation

@Morpheus1w3
Copy link
Copy Markdown
Contributor

@Morpheus1w3 Morpheus1w3 commented May 3, 2026

This change improves how realized capital gains are displayed in the performance calculation.
The existing period-based realized gains remain unchanged.

A new purchase-based realized gains line is added. It uses the actual historical purchase cost, based on FIFO or moving average. This helps users compare sales in the selected period against the original purchase cost.

A new adjustment line is added to keep the overall period-based performance calculation consistent.
The total portfolio value and the existing performance logic are not changed.

####Review note
The purchase-based value is built from transactions before the reporting period, so sales inside the selected period can be compared against the historical purchase cost.

The adjustment line keeps the existing period-based performance calculation consistent.

image image

@Morpheus1w3
Copy link
Copy Markdown
Contributor Author

At name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/dashboard/PerformanceCalculationWidget.java a minor Bugfix Was implemented.

For example "Cash Fremdwährungsgewinne" is basically an addition. However, it could happen that the amount is negative. So it' lead into confusion, if the calculation method is an addition, but the amount is negative and subtracted.

@Morpheus1w3 Morpheus1w3 marked this pull request as draft May 4, 2026 05:21
@Sn1kk3r5
Copy link
Copy Markdown
Contributor

Sn1kk3r5 commented May 4, 2026

closes: #5662

@prieurcath
Copy link
Copy Markdown

Thanks for this :)

This change improves how realized capital gains are calculated and displayed.

Previously, realized gains were based on market values at the start of the reporting period. This could lead to confusing results, especially when assets were bought before the selected period.

With this change:

Realized gains are now calculated using the actual purchase cost (FIFO or moving average).
A new adjustment line is added to keep the overall calculation consistent.
The adjustment ensures that only gains within the selected period are reflected in the result.

This makes the output easier to understand and closer to how users expect gains to be calculated.

No changes to total portfolio value or performance logic were introduced.
@Morpheus1w3 Morpheus1w3 force-pushed the fix-gain-calculation branch from e7394b7 to 9ec5bd2 Compare May 4, 2026 09:45
@Morpheus1w3 Morpheus1w3 marked this pull request as ready for review May 4, 2026 09:46
@mierin12
Copy link
Copy Markdown
Contributor

mierin12 commented May 4, 2026

Hmm if this goes through we need to be extra extra clear about what are those two new values. What is the meaning of the 336.8 EUR value ?
There are two different definitions for realized/unrealized gains now. Realized gains are now related to purchase cost, but unrealized gains remains related to the start of the period ? Why not related to the purchase cost too then ?

My understanding is that it was simply not the task of Performance/Calculation to provide such kind of values.
Performance Calculation was meant to provide information about the performance since a start date. Whatever happened before is irrelevant, as at the start everything is considered invested, both gains and principal.
https://forum.portfolio-performance.info/t/realized-capital-gains-doesnt-match-closed-trades/38737
#3387

Maybe Trades view or Payment/Closed Trades view or the Trades Profit/Loss widget are more usable for this kind of topic. But each of them have different characteristics but we can work on them:

View Account filter ? Period filter ? FIFO and moving average ? Before or after taxes and fees ?
Trades No No Both Both
Payment/Closed trades Yes Yes FIFO only Before only
Trades Profit/Loss widget Yes Yes Both After only

(before tax and fees = without tax and fees = pure price gains)
(after tax and fees = with tax and fees = gains reduced by tax and fees)

Another thing, I am assuming those "taxable gains" determination should be gains AFTER fees, right ? But the Performance Calculation view only provides Gains that are before tax and fees. So if you calculate your taxable gains from this view, then it means you consider that you have to pay tax on pure price gain, not yet reduced by the differents fees. So you consider you have to pay taxes on your fees..

All in all, PP is not made for tax calculation.

@Morpheus1w3
Copy link
Copy Markdown
Contributor Author

Morpheus1w3 commented May 4, 2026

Existing calculation method is even misleading. Alternative proposal as below.

Calculation Method (Performance)

INITIAL
+ CAPITAL_GAINS
+ EARNINGS
- FEE
- TAX
+ FOREX
= FINAL

@prieurcath
Copy link
Copy Markdown

Even "Portfolio Performance is focusing the performance of investments, t" . the calculation on performance when Securities have been sold the profit must be calculated on initial price paid and not on the last cotation. If fact it's the case on curent year just apprear to be different if the acquisition was made the previous year.

@Morpheus1w3 Morpheus1w3 closed this May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants