ananthakumaran / paisa

Paisa – Personal Finance Manager. https://paisa.fyi demo: https://demo.paisa.fyi
https://paisa.fyi
GNU Affero General Public License v3.0
2.34k stars 117 forks source link

Incorrect Market Value Calculation for Stocks in Foreign Currency #69

Closed saleehk closed 9 months ago

saleehk commented 10 months ago

Problem:

When the default currency is set to INR and I make transactions for stocks in USD, the market value calculation appears to be significantly off.

Example ledger entry:

2023/07/07 Buy 0.76179738 Shares of ABNB
    Assets:Equity:Vested:NYSE:ABNB  0.76 ABNB @ 131.27 USD
    Assets:Broker:Vested

The stock is purchased in USD and in assets report the Absolute return is incorrect.

For example As of Today 4th Oct 2023 the market value of ABNB is 127.73 USD. In absolute return it shows 12,673.00% change. Actual change is less than 20%.

Is this expected behavior or am I doing something wrong?

ananthakumaran commented 10 months ago

Paisa doesn't handle 2 level indirection well. Since the USD to INR price is not mentioned anywhere, it will not know how to handle it. The price fetched from yahoo will be stored as ABNB -> INR. You can fix the problem in 2 ways

  1. Add USD to INR conversion price

    P 2023/07/07 00:00:00 USD 80.442048 INR
  2. Remove the USD and specify the price in INR

    2023/07/07 Buy 0.76179738 Shares of ABNB
    Assets:Equity:Vested:NYSE:ABNB  0.76 ABNB @ 10559.6277 INR
    Assets:Broker:Vested

I personally use the second method, but both might approach might work

saleehk commented 10 months ago

Thanks @ananthakumaran

This helps. Is there any plan in future to handle this?

ananthakumaran commented 10 months ago

What is your expectation? The way I see it, it already works, you just have to specify how commodities are connected.

saleehk commented 10 months ago

Currently, I'm using your first solution. I have to add the USD to INR price manually. I was wondering if there is a way this can be added automatically, similar to how you are pulling stock and mutual fund prices

sohamshanbhag commented 10 months ago

Hey, if you are still looking for this, add the following to fetch USD to INR price automatically to your commodities in paisa.yaml:

  - name: USD
    type: stock
    price:
      provider: com-yahoo
      code: INR=X
    harvest: 0
    tax_category: unlisted_equity

Or add USD as a stock with price fetch from yahoo with ticker INR=X similar to how you added ABNB in the UI. Though I'm not sure if this will correctly solve this issue, this is a valid way to fetch the exchange rate. @ananthakumaran I can create a PR adding this to the docs for fetching currency prices if you like.

ananthakumaran commented 10 months ago

I doubt this will help with the OP issue, the amount is converted to default currency when the ledger file is parsed, and during that time prices from external systems are not referred to, only the prices specified in the ledger file are used.

sohamshanbhag commented 10 months ago

Ah, I see. It seems that the code for conversion of the prices to $default_currency exists already somewhere in the code, since the market value is calculated correctly with the example ledger entry. You need to use the same code when calculating investment amount too for correct gain calculations.