afadil / wealthfolio

A Beautiful Private and Secure Desktop Investment Tracking Application
https://wealthfolio.app
GNU Affero General Public License v3.0
4.38k stars 225 forks source link

[BUG] Showing wrong currency value at Holdings #168

Open sertxudev opened 5 days ago

sertxudev commented 5 days ago

Hi, awesome work!

I've noticed account holdings are shown with the account currency (EUR):

image

These should be:

Total value Today's price
€9,15 ~€9,64~ €4,58 ~€4,82~

The values shown are retrieved from Yahoo finance, which are stored in USD.

image

The account holdings should be converted to EUR (or whatever the account currency is).

The other values in the account are working as expected.

image

So the bug it's only at the account holdings table.

MarcinFrankowski commented 13 hours ago

The problem seems to be caused by the calculation logic in the HoldingsService. It's using the holding currency instead of the asset currency to get the exchange rate.

Additionally, there's book_value_converted field that doesn't make much sense to me, since it's not calculated using the exchange rate from day of the activity but the current exchange rate

It gets even more interesting when you have 3 currencies in the setup.

  1. Set up currency A as a base currency
  2. Add 2 accounts with B and C currencies
  3. Add the same BUY activity of any asset to both accounts and compare the numbers on the account and holdings pages

I think the discrepancies come from the confusion around book_value For examample if we have an account in currency B but the asset currency is C, then the value of market_value is in currency C but book_value is in currency B. What's even more confusing both of values are converted using the same exchange rate to the base account currency A this code does that