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

Improve degiro v3 parsing #148

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ikruglov
Copy link

@ikruglov ikruglov commented Jan 4, 2025

Added

This commit re-works degiroConverterV3 logic.

The main change is that the code can now consider a set of records as one instead action+tx record.

The following set of records is one sale with two transaction fee records. They can be reported as one in ghostfolio. The previous code didn't handle this.

23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.79,EUR,,1d2e7a85-cf67-4325-82c7-d5994a0afb98
23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-4.00,EUR,,1d2e7a85-cf67-4325-82c7-d5994a0afb98
23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,Verkoop 120 @ 1.202 GBX,,GBP,1442.40,GBP,,1d2e7a85-cf67-4325-82c7-d5994a0afb98

Another example is below. It has two sells and one tx record.

11-07-2024,16:46,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 16 @ 124,28 EUR",,EUR,1988.48,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c
11-07-2024,16:43,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-1.00,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c
11-07-2024,16:43,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 8 @ 124,28 EUR",,EUR,994.24,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c

Or this

24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.26,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-2.00,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.02,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 14 @ 61,7 EUR",,EUR,863.80,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 1 @ 61,7 EUR",,EUR,61.70,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818

To make it even more complicated. There are cases of taxes without any associated buy/sell:

16-12-2021,18:02,22-10-2021,MOODY'S CORP.,US6153691059,Dividendbelasting,,USD,-0.01,USD,0.00,
16-12-2021,18:02,22-10-2021,MORGAN STANLEY,US6174464486,Dividendbelasting,,USD,0.01,USD,0.01,
16-12-2021,18:02,22-10-2021,MOODY'S CORP.,US6153691059,Dividendbelasting,,USD,-0.01,USD,0.00,
16-12-2021,18:02,22-10-2021,MORGAN STANLEY,US6174464486,Dividendbelasting,,USD,0.01,USD,0.01,

There are also a bunch of cosmetic changes.

This is quite a significant change, so I'm looking into your feedback. I've collected a corpus of tests while debugging. I'm ready to write tests for them, but I would like your feedback to ensure you're comfortable accepting this PR.

Fixes

Checklist

  • Added relevant changes to README (if applicable)
  • Added relevant test(s)
  • Updated GitVersion file and corresponding version in package.json

Related issue (if applicable)

Possibly resolves #140

@ikruglov ikruglov requested a review from dickwolff as a code owner January 4, 2025 22:13
@ikruglov
Copy link
Author

ikruglov commented Jan 4, 2025

@dickwolff I just spotted #146. It's still a half-measure, I believe. There are complex cases when one sale or purchase can include two or more buy/sell records and multiple transaction fee records. Please take a look at the description for examples.

Copy link
Owner

@dickwolff dickwolff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions on how to improve the mapping for DEGIRO. I have done an initial review of the changes. Overall I think you’re on the right path, but I have some remarks, questions or suggestions.

Please note that I have reviewed it on my iPad, so I might not have the full picture of all the changes. I will look into it some more later when I can get on a pc.

src/converters/degiroConverterV3.ts Outdated Show resolved Hide resolved
src/models/degiroRecord.ts Outdated Show resolved Hide resolved
src/converters/degiroConverterV3.ts Show resolved Hide resolved
* since buy/sell txs are in EUR.
*
* This hack allows to buypass all internal heuristic and hardcode correct results.
* Format: IE00B02KXK85=FXAC.AS,foo=bar
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen a similar thing with the isin of VWRL resulting in VWRL.L instead of VWRL.AS (see comment on line 92 on main).

I think you’re on the right path to a solution, but I think it can be improved upon. I’d then rather use a simple text file with mappings which you as a user can provide.

I have created #149 for this to make this separate of this change. Could you revert any change regarding this mapping override, so the this PR is moreso a better fix for the transaction matching?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have ready code? If not, I can write it since I need it. Do you have any particular preferences implementation wise?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I have no code yet, but your suggestion gave me an idea on how to do it.

You can give it a go, but preferably separate from, and after this change has been merged

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I have no code yet, but your suggestion gave me an idea on how to do it.

You can give it a go, but preferably separate from, and after this change has been merged

so, just a plain file with foo=bar pairs on each line?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was basically what I was going for. Then read it when present, and also provide a file volume mount in Docker.

But as stated, I’d prefer it separate from this PR

package.json Outdated Show resolved Hide resolved
src/converters/degiroConverterV3.ts Show resolved Hide resolved
@ikruglov ikruglov force-pushed the improve-degiro-v3 branch 2 times, most recently from 8f96285 to 98b28af Compare January 5, 2025 11:35
@ikruglov
Copy link
Author

ikruglov commented Jan 5, 2025

btw, do you prefer rebase + force-push or extra commits?

@dickwolff
Copy link
Owner

I recently tried to switch to rebasing, so please

@ikruglov
Copy link
Author

ikruglov commented Jan 5, 2025

@dickwolff I fixed all your suggestions and added tests. But I didn't figure out how to update Yahoo Finance mock file to include info about new ISINs. How do I do it?

@ikruglov
Copy link
Author

ikruglov commented Jan 5, 2025

@dickwolff I just realized that the import logic seriously messes up with currencies. It just replaces record currency with looked-up-from-yahoo currency without any proper conversation.

I understand why, but it affects results. In my case, with INRG.L, quite seriously.

Asked question: ghostfolio/ghostfolio#4139 (comment)

What was your thinking when you wrote it?

@dickwolff
Copy link
Owner

dickwolff commented Jan 5, 2025

@dickwolff I fixed all your suggestions and added tests. But I didn't figure out how to update Yahoo Finance mock file to include info about new ISINs. How do I do it?

See the wiki for instructions how to do this.


@dickwolff I just realized that the import logic seriously messes up with currencies. It just replaces record currency with looked-up-from-yahoo currency without any proper conversation.

I understand why, but it affects results. In my case, with INRG.L, quite seriously.

Asked question: ghostfolio/ghostfolio#4139 (comment)

What was your thinking when you wrote it?

This was a fix for GBP to GBp matching. I have since made some changes in a branch to revert that change, in response to #129. I have not merged that yet due to something I wanted to verify with the reporter first. But I think I will do that merge tomorrow, so you can continue working on this.

@jonathanR79
Copy link

Some other samples of multi line transaction record that are currentlly not really well processed:

10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,Operation de change - Crédit,1.2105,USD,311.00,USD,0.00,a08ddbcc-73da-4250-ac23-yyyyyyyyy
10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,Opération de change - Débit,,EUR,-256.92,EUR,754.35,a08ddbcc-73da-4250-ac23-yyyyyyyyy
10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,Taxe sur les Opérations Boursières belge (TOB),,EUR,-0.90,EUR,1011.27,a08ddbcc-73da-4250-ac23-yyyyyyyyy
10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,Frais DEGIRO de courtage et/ou de parties tierces,,EUR,-0.33,EUR,1012.17,a08ddbcc-73da-4250-ac23-yyyyyyyyy
10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,Frais DEGIRO de courtage et/ou de parties tierces,,EUR,-0.50,EUR,1012.50,a08ddbcc-73da-4250-ac23-yyyyyyyyy
10-12-2020,17:54,10-12-2020,ADR ON AMBEV,US02319V1035,"Achat 100 ADR on Ambev@3,11 USD (US02319V1035)",,USD,-311.00,USD,-311.00,a08ddbcc-73da-4250-ac23-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,Taxe sur les Opérations Boursières belge (TOB),,EUR,-0.30,EUR,506.28,b5c849a1-baef-473e-bdd7-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,Frais DEGIRO de courtage et/ou de parties tierces,,EUR,-0.10,EUR,506.58,b5c849a1-baef-473e-bdd7-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,Taxe sur les Opérations Boursières belge (TOB),,EUR,-0.30,EUR,506.68,b5c849a1-baef-473e-bdd7-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,Frais DEGIRO de courtage et/ou de parties tierces,,EUR,-0.10,EUR,506.98,b5c849a1-baef-473e-bdd7-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,"Achat 50 Quest For Growth@4,98 EUR (BE0003730448)",,EUR,-249.00,EUR,507.08,b5c849a1-baef-473e-bdd7-yyyyyyyyy
04-06-2020,12:21,04-06-2020,QUEST FOR GROWTH,BE0003730448,"Achat 50 Quest For Growth@4,97 EUR (BE0003730448)",,EUR,-248.50,EUR,756.08,b5c849a1-baef-473e-bdd7-yyyyyyyyy

@dickwolff
Copy link
Owner

@jonathanR79 Thanks for providing these. Of the first set, the first records should be ignored. I think that currently is already the case. Of the second set, would you want there to be 2 buy records, or is it fine to combine all these 6 lines into one activity for Ghostfolio?

@jonathanR79
Copy link

jonathanR79 commented Jan 5, 2025

@jonathanR79 Thanks for providing these. Of the first set, the first records should be ignored. I think that currently is already the case. Of the second set, would you want there to be 2 buy records, or is it fine to combine all these 6 lines into one activity for Ghostfolio?

On the first, it's detected as a divident for now.

On the second, the purchase price is different. So , ideally it should be two different records. A single entry with the average of the 2 should work as well but I'm not sure what is the easiest.

@ikruglov
Copy link
Author

ikruglov commented Jan 9, 2025

@dickwolff I've pushed an improved version. Unfortunately, I'm unable to test it locally. For some reason, ghostfolio tells me, "Don't have a currency rate from EUR to USD." I'm unable to work around it for now.

@ikruglov
Copy link
Author

ikruglov commented Jan 9, 2025

On the second, the purchase price is different. So , ideally it should be two different records. A single entry with the average of the 2 should work as well but I'm not sure what is the easiest.

@jonathanR79 this code will do two records. One with combination of TX costs, second one without one tx cost.

@ikruglov ikruglov requested a review from dickwolff January 9, 2025 23:09
@dickwolff
Copy link
Owner

dickwolff commented Jan 10, 2025

@dickwolff I've pushed an improved version. Unfortunately, I'm unable to test it locally. For some reason, ghostfolio tells me, "Don't have a currency rate from EUR to USD." I'm unable to work around it for now.

You should be able to this via Admin Control. Click the + Add Currency-button and enter EUR. Then you should have the exchange rate like 1 USD = 0,9745 EUR (on time of writing).

I will hopefully have some time this weekend to go through your changes and leave review.

@ikruglov
Copy link
Author

@dickwolff I've pushed an improved version. Unfortunately, I'm unable to test it locally. For some reason, ghostfolio tells me, "Don't have a currency rate from EUR to USD." I'm unable to work around it for now.

You should be able to this via Admin Control. Click the + Add Currency-button and enter EUR. Then you should have the exchange rate like 1 USD = 0,9745 EUR (on time of writing).

I will hopefully have some time this weekend to go through your changes and leave review.

I tried that. It doesn't help. I'm kinda stuck. I see that ghostfolio extracts and adds historical data for USDEUR, but it fails with the opposite conversation: EURUSD. I don't know/see a way to import it.

@ikruglov
Copy link
Author

oh, I figured it out. It's a bug in ghostfolio. I'm preparing a PR.

@ikruglov
Copy link
Author

submitted ghostfolio/ghostfolio#4187

Copy link
Owner

@dickwolff dickwolff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked at the changes and they seem to make sense overall. I might do some testing and code cleanup myself after merging, but the idea is sound. Great work!

Finally, can you bump the versions to 0.23.0?

@@ -35,7 +35,7 @@ describe("degiroConverterV3", () => {
// Assert
expect(actualExport).toBeTruthy();
expect(actualExport.activities.length).toBeGreaterThan(0);
expect(actualExport.activities.length).toBe(26);
expect(actualExport.activities.length).toBe(43);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the tests are currently failing. V2 converter is missing 1 (as V2 and V3 tests are sharing the same input file for testing), and V3 only got 31 instead of expecting the 43 you put in the test. Can you take a look at this and make changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dickwolff I need help with tests:

  1. to update Yahoo Finance information. I think the instructions from the wiki are not complete. I got a missing import of a Mock object, which I didn't figure out how to import. Note that I'm a first-time user of Typescript
  2. How do I print debug statements (to stdout/stderr) in tests? I'm getting unexpected behavior, which I need to debug.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Hope this helps:

  1. If you use an IDE like VSCode, you can to CTRL + . (dot) and then import all usings.
  2. In the tests, console statements are supressed. You can comment the whole beforeEach(() => { function, then you'll get the console log statements in your console. For debugging purposes I usually add console.log(...) statements on places that could help me debug.

This commit re-works degiroConverterV3 logic.

The main change is that the code now can consider a set of records as one, instread action+tx record.

The following set of records are one sell with two transaction fees
records. They can be reported as one in ghostfolio. The previous code
didn't handle this.

23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.79,EUR,,1d2e7a85-cf67-4325-82c7-d5994a0afb98
23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-4.00,EUR,,1d2e7a85-cf67-4325-82c7-d5994a0afb98
23-12-2020,10:03,23-12-2020,ISHARES GLOBAL CLEAN ENERGY UCITS ETF,IE00B1XNHC34,Verkoop 120 @ 1.202 GBX,,GBP,1442.40,GBP,,1d2e7a85-cf67-4325-82c7-d5994a0afb98

Another example is below. It has two sells and one tx record.
11-07-2024,16:46,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 16 @ 124,28 EUR",,EUR,1988.48,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c
11-07-2024,16:43,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-1.00,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c
11-07-2024,16:43,11-07-2024,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 8 @ 124,28 EUR",,EUR,994.24,EUR,,56e1f16b-4142-4373-851d-45d0505fe12c

Or this
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.26,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-2.00,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,DEGIRO Transactiekosten en/of kosten van derden,,EUR,-0.02,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 14 @ 61,7 EUR",,EUR,863.80,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
24-03-2020,13:10,24-03-2020,VANGUARD FTSE ALL-WORLD UCITS ETF,IE00B3RBWM25,"Verkoop 1 @ 61,7 EUR",,EUR,61.70,EUR,,810d6e1d-af8e-43a4-830e-0b85bf90c818
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.

DEGIRO - Buy record in French (Belgium)
3 participants