portfolio-performance / portfolio

Track and evaluate the performance of your investment portfolio across stocks, cryptocurrencies, and other assets.
http://www.portfolio-performance.info
Eclipse Public License 1.0
2.76k stars 579 forks source link

GBp (penny) quotes from Yahoo Finance interpreted as GBP (pound) #4038

Open leezu opened 1 month ago

leezu commented 1 month ago

Describe the bug While PP supports the GBX symbol for accounts denominated in British pence (https://github.com/portfolio-performance/portfolio/issues/406), brokers such as Interactive Brokers usually denominate accounts in British pounds and not pence. Importing GBX (also called GBp) or GBP transactions from the Interactive Brokers XML files to PP is therefore only possible to GBP accounts. Attempting to import to an GBX account does not import any transaction due to GBP not matching GBX. Importing to a GBP account works however correctly, with PP reading the correct GBP denominated purchase price from the XML file.

When PP queries current/historic quotes from Yahoo Finance, it receives a GBp response. See for example https://query1.finance.yahoo.com/v8/finance/chart/LSEG.L which begins with {"chart":{"result":[{"meta":{"currency":"GBp","symbol":"LSEG.L","exchangeName":"LSE","fullExchangeName":"LSE","instrumentType":"EQUITY", and contains quotes in pence (as indicated by the currency name "GBp". Unfortunately, PP interprets this GBp quote as GBP, leading to current and historic values being off by 100.

For historic reasons, it seems that all quotes for London listed stocks are in GBp and there should be no situation in which Yahoo Finance actually returns a GBP quote. This issue is not only Yahoo Finance specific, though at least Yahoo Finance includes the "GBp" currency information in the API response. Other providers, like alphavantage.co do not provide the currency symbol in the response and simply return "GBp" instead of "GBP". https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=LSEG.L&apikey=demo

To Reproduce Steps to reproduce the behavior:

Add a GBP stock purchase to a GBP denominated PP account. For example, LSEG.L. Provide the purchase price in GBP. Observe that PP obtains the GBp quotes from Yahoo and reports the value of the investment as 100x the true value.

Expected behavior PP distinguishes between GBp and GBP. When Yahoo Finance provides a GBp quote for a GBP security, PP correctly converts from GBp to GBP and reports the accurate value.

Workaround Obtain alphavantage.co API key. Setup manual JSON source for the security:

image

where the URL is https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=SYMBOL.L&apikey=APIKEY and disabling historical data.

Desktop (please complete the following information):