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

IB cfd import #1837

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MichaelSp
Copy link

@MichaelSp MichaelSp commented Nov 23, 2020

Support for CFD trades from via "IB Activity Statement" Importer

There is a problem with the cost/netCash however:
Since CFDs are traded with the help of the broker (x% your money, rest from the broker), it doesn't make sens to put the actual value of the underlying in your portfolio. It's not your money. If you sell this position you will not get this amount in your account.

In the IB statement the attribute netCash (which is currently used) only contains the fees. And that is the actual value that is withdrawn from your account. Eventually you'll have netCash - fee = 0 as amount in your portfolio. Rating the performance later based on 0 value could be... difficult :)

Other attributes are as follows:

 quantity = 3
 tradePrice = 409.75
 closePrice = 409.75
 commission = fee (-5.8)
 cost = quantity * tradePrice - commission (1235.05)
 netCash = commission                        (-5.8)
 tradeMoney = quantity * tradePrice        (1229.25)
 proceeds= -tradeMoney                    (-1229.25)

which attribute should be the amount? Any ideas?

https://forum.portfolio-performance.info/t/interactive-brokers/276/148

Related issues
#1466 #1736 (it's about selling short, but based on CFD)

@MichaelSp MichaelSp marked this pull request as draft November 24, 2020 20:35
because netCash contains only commission for CFD
@buchen
Copy link
Member

buchen commented Nov 28, 2020

To be honest, I haven't had the time to wrap my head around the short selling.
PP assumes you invest X to purchase an asset and that it can make daily valuation of that asset.

My naive thinking is:
For the transaction above, the fees (5.8) what you actually pay to purchase the asset (CFD).
The daily valuation of your position would be something like currentPrice - tradePrice.
PP does not support that (yet?)

How is InteractiveBrokers showing the valuation of your CFD?
How is it showing the investment.

@MichaelSp
Copy link
Author

I think "Valutation" is called "Net asset value"? (I'm not to familiar with all these financial terms)

In NAV you'll find basically these entries:
image
Stock, Cash and Dividend as absolute values
But CFD only as difference: In Profit/Loss

I' try to find out how it's rated performance wise.

Meanwhile I found a bug in the import, which I'm gonna try to fix too:
https://github.com/buchen/portfolio/blob/master/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/IBFlexStatementExtractor.java#L483-L487
Here the gross unit is added based on total` value.

And I have to think about this change here: d57af92 I was about to use cost instead of netCash...

# Conflicts:
#	name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/IBFlexStatementExtractorTest.java
Nirus2000 added a commit to Nirus2000/portfolio that referenced this pull request Apr 14, 2023
Improves the processing of the attributes "netCash" and "cost" based on the portfolio-performance#3177 comments from @pfalcon.

https://forum.portfolio-performance.info/t/interactive-brokers-flex-query-importer-not-importing-fund-trades/23714/4

Remove CFD Trading transaction
Here still unclear how the transaction should be made, as this was not conclusively clarified in PR portfolio-performance#1837.

Fix Options and Futures
After implementation by PR e99c44d no tests were inserted to verify the function correctly.
Since there were also no tests for older tests because they were simply missing, they were added with PR portfolio-performance#3177.
Now we fix this testiBFlexStatementFile02() #Trade-3
Nirus2000 added a commit to Nirus2000/portfolio that referenced this pull request Apr 15, 2023
Improves the processing of the attributes "netCash" and "cost" based on the portfolio-performance#3177 comments from @pfalcon.

Improve IBFlex-Query-Importer to support new transaction + Fix portfolio-performance#3280 (comment) from @pfalcon

https://forum.portfolio-performance.info/t/interactive-brokers-flex-query-importer-not-importing-fund-trades/23714/4

Remove CFD Trading transaction
Here still unclear how the transaction should be made, as this was not conclusively clarified in PR portfolio-performance#1837.

Fix Options and Futures
After implementation by PR e99c44d no tests were inserted to verify the function correctly.
Since there were also no tests for older tests because they were simply missing, they were added with PR portfolio-performance#3177.
Now we fix this testiBFlexStatementFile02() #Trade-3

Improve trade date and trade time

Fix testiBFlexStatementFile12.xml and testiBFlexStatementFile12()
In PR portfolio-performance#3177 the test file was taken from the post https://forum.portfolio-performance.info/t/interactive-brokers/276/122 to check the correct function of the importer. However, this was manipulated in the dates.
The element "dateTime" agrees in the specification to the "tradeDate" and deviates by one year. The original test file, but with too much anonymization of the data, can be found in the article https://forum.portfolio-performance.info/t/interactive-brokers/276/115.
buchen pushed a commit that referenced this pull request Apr 15, 2023
Improves the processing of the attributes "netCash" and "cost" based on the #3177 comments from @pfalcon.

Improve IBFlex-Query-Importer to support new transaction + Fix #3280 (comment) from @pfalcon

https://forum.portfolio-performance.info/t/interactive-brokers-flex-query-importer-not-importing-fund-trades/23714/4

Remove CFD Trading transaction
Here still unclear how the transaction should be made, as this was not conclusively clarified in PR #1837.

Fix Options and Futures
After implementation by PR e99c44d no tests were inserted to verify the function correctly.
Since there were also no tests for older tests because they were simply missing, they were added with PR #3177.
Now we fix this testiBFlexStatementFile02() #Trade-3

Improve trade date and trade time

Fix testiBFlexStatementFile12.xml and testiBFlexStatementFile12()
In PR #3177 the test file was taken from the post https://forum.portfolio-performance.info/t/interactive-brokers/276/122 to check the correct function of the importer. However, this was manipulated in the dates.
The element "dateTime" agrees in the specification to the "tradeDate" and deviates by one year. The original test file, but with too much anonymization of the data, can be found in the article https://forum.portfolio-performance.info/t/interactive-brokers/276/115.
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.

None yet

2 participants