Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Inaccurate Currency Conversion #2700

Open
MRobi1 opened this issue Nov 28, 2023 · 7 comments
Open

[BUG] Inaccurate Currency Conversion #2700

MRobi1 opened this issue Nov 28, 2023 · 7 comments
Labels
question Further information is requested

Comments

@MRobi1
Copy link

MRobi1 commented Nov 28, 2023

Bug Description
Working at converting my historical crypto transactions from Yahoo to the new method which forces all crypto transactions to be listed in USD. When entering the transactions, I entered the appropriate dates as well as making sure to select CAD in the dropdown as all crypto transactions were done through Canadian exchanges in CAD.

Using the old Yahoo provider, I got accurate fees and cost basis.
image

Using the new method with the forced currency conversion, I get completely different numbers which are wildly inaccurate.
image

If there are no plans to allow crypto currency to be tracked in the fiat currency used to purchase it, we need a method to be able to properly convert the currency to USD otherwise tracking simply does not work.

Environment

  • Self-hosted
  • Ghostfolio Version 2.27.1 - 2023-11-28
  • Browser: Chrome
  • OS: Docker
@MRobi1
Copy link
Author

MRobi1 commented Nov 28, 2023

Just tried this with a different crypto currency on the off chance it was something with the coin above...

Proper cost basis using Yahoo:
image

Improper cost basis using coingecko:
image

My hunch here was that it was adding the USD totals, and then converting it to CAD on the bottom based on the current exchange rate (which would not be the correct way to report this since the cost at time of purchase should not fluctuate based on today's exchange rates).

However when tallying up the totals in USD and running it through a currency converter I get a different number again.
image

So I have no idea how it's arriving at the number being displayed. But it is not calculating it correctly.

EDIT: The current total value shows correctly on the holdings page, so the issue is solely related to the currency conversion when adding a transaction resulting in inaccurate cost basis as well as inaccurate reporting of gains/losses.

@dtslvr
Copy link
Member

dtslvr commented Dec 2, 2023

Hi @MRobi1

Could you please follow our bug report template including detailed steps to reproduce the problem and the expected behavior. Thanks for your assistance.

@dtslvr dtslvr added the question Further information is requested label Dec 2, 2023
@MRobi1
Copy link
Author

MRobi1 commented Dec 2, 2023

Steps to reproduce:

  • Go to Portfolio
  • Go to Activities
  • Hit +
  • Input crypto of your choice in "Name, symbol, ISIN"
  • Set date of transaction
  • Enter quantity
  • Enter unit price and select CAD in the dropdown
  • Enter fees and select CAD in the dropdown
  • Hit save

image
1500 @ $0.25 = $375 + $10 fees = $385

And here is the outcome
image
Shows $405.02CAD

Current value is correct
image

All other values are incorrect
image

@MRobi1
Copy link
Author

MRobi1 commented Dec 2, 2023

@dtslvr This may actually be the same issue as #2702 and #2449

@dtslvr
Copy link
Member

dtslvr commented Dec 3, 2023

Many thanks for the overview @MRobi1. The current implementation has the drawback that the currency exchange between CAD/USD over time is included (cf. 10.00 CAD on 2021/09/04 vs. 10.80 CAD on 2023/12/02).

There is a crowdfunding campaign to track cryptocurrencies in your custom currency: https://www.buymeacoffee.com/ghostfolio/w/31930

@MRobi1
Copy link
Author

MRobi1 commented Dec 3, 2023

This isn't just a cryptocurrency issue though. This is a fundamental flaw on how Ghostfolio tracks any activity where a currency exchange is involved.

I can easily recreate this issue with any security.
For example, here is AAPL.
10 shares @ $100CAD = $1,000 + $10 fee = $1,010. This is the initial investment. $1,010 is the cost.
image

It then reports $1,052.92. This is incorrect as only $1,010 was invested. This figure shows as if an additional $42.92 was invested which never happened.
image

As are the calculated figures for change, performance % and initial investment
image

If $1,000 is invested at time of purchase, it needs to remain at $1,000. It is fundamentally incorrect to change the initial purchase amount based on today's current currency exchange. $1,000 == $1,000.

@SentinelCQ
Copy link

I noticed there are TODOs in the code that look related to this issue.
// TODO: Use exchange rate of date
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
order.fee,
order.SymbolProfile.currency,
userCurrency
),
SymbolProfile: assetProfile,
// TODO: Use exchange rate of date
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
value,
order.SymbolProfile.currency,
userCurrency
)

So it looks like calls to
exchangeRateDataService.toCurrency(
needs to be replace here with
exchangeRateDataService.toCurrencyAtDate(
And likely all locations of .toCurrency audited for similar issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants