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

Incorrect FIFO or cross-account currents #171

Open
pronebird opened this issue Feb 22, 2025 · 2 comments
Open

Incorrect FIFO or cross-account currents #171

pronebird opened this issue Feb 22, 2025 · 2 comments

Comments

@pronebird
Copy link
Contributor

pronebird commented Feb 22, 2025

Hi,

Not sure if that's a bug, basically this is a transaction history:

 Account  | Date                | Asset | B/S  | Symbol | Contract ID | ISIN         | Qty  | Price   | Multiple | Currency | Notes                            
----------+---------------------+-------+------+--------+-------------+--------------+------+---------+----------+----------+----------------------------------
 U70XXXX  | 2022-03-29 10:56:35 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 300  | 27.088  | 1        | USD      |                                  
 U70XXXX  | 2022-04-05 14:29:21 | STK   | Sell | PAAS   | 4816190     | CA6979001089 | -300 | 27.31   | 1        | USD      |                                  
 U70XXXX  | 2022-04-07 13:13:20 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 150  | 27.685  | 1        | USD      |                                  
 U70XXXX  | 2022-04-21 11:26:26 | STK   | Sell | PAAS   | 4816190     | CA6979001089 | -150 | 27.655  | 1        | USD      |                                  
 U70XXXX  | 2022-04-27 13:31:07 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 200  | 24.628  | 1        | USD      |                                  
 U76XXXX  | 2022-04-27 13:31:29 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 100  | 24.645  | 1        | USD      |                                  
 U70XXXX  | 2023-03-03 13:11:43 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 100  | 15.878  | 1        | USD      |                                  
 U70XXXX  | 2024-05-31 10:44:36 | STK   | Sell | PAAS   | 4816190     | CA6979001089 | -100 | 21.8605 | 1        | USD      | Executed against an IB affiliate 
          |                     |       |      |        |             |              |      |         |          |          | Partial execution                
 U70XXXX  | 2024-05-31 10:44:36 | STK   | Sell | PAAS   | 4816190     | CA6979001089 | -200 | 21.865  | 1        | USD      | Partial execution                
 U76XXXX  | 2024-09-24 12:33:39 | STK   | Buy  | PAAS   | 4816190     | CA6979001089 | 50   | 22.18   | 1        | USD      |                                             

When outputting KDVP for 2024 the following transactions are produced:

<ISIN>CA6979001089</ISIN>
<Code>PAAS</Code>
<Name>PAN AMERICAN SILVER CORP</Name>
<IsFond>false</IsFond>
<Row>
  <ID>0</ID>
  <Purchase>
    <F1>2022-04-27</F1>
    <F2>B</F2>
    <F3>200.0000</F3>
    <F4>23.2713</F4>
    <F5>0.0000</F5>
  </Purchase>
  <F8>200.0000</F8>
</Row>
<Row>
  <ID>1</ID>
  <Purchase>
    <F1>2023-03-03</F1> <!-- I think this is not right! -->
    <F2>B</F2>
    <F3>100.0000</F3>
    <F4>14.9581</F4>
    <F5>0.0000</F5>
  </Purchase>
  <F8>300.0000</F8>
</Row>
<Row>
  <ID>2</ID>
  <Sale>
    <F6>2024-05-31</F6>
    <F7>300.0000</F7>
    <F9>20.1470</F9>
  </Sale>
  <F8>0.0000</F8>
</Row>

I think that may not be correct.

  • The first 4 trades have already been closed in 2022.
  • There are 2 buy orders in 2022-04-27 and 1 buy order in 2023-03-03, which together bring the balance to 400 (spread across 2 different accounts)
  • On 2024-05-31 2 sell orders happen disposing 300 shares. If we disregard the account IDs, I think that this transaction, based on FIFO, taps 300 shares from 2022-04-27.

In other words:

 Account ID | Date                | Quantity | Price   | Currency | Multiplier | Balance 
------------+---------------------+----------+---------+----------+------------+--------
 U70XXXX    | 2022-04-27 13:31:07 | 200      | 24.628  | USD      | 1          | 200     
 U76XXXX    | 2022-04-27 13:31:29 | 100      | 24.645  | USD      | 1          | 300     
 U70XXXX    | 2024-05-31 10:44:36 | -300     | 21.8635 | USD      | 1          | 0       

This is a diff with ib-edavki output on the left hand side, and how I think that should be on the right hand side:

Image

Something that I have been wondering about is whether FURS take into consideration each individual account separately and that's why ib-edavki acts this way, or are we forced to merge all our trades together when reporting?

@pronebird pronebird changed the title Incorrect FIFO? Incorrect FIFO or cross-account currents Feb 22, 2025
@jamsix
Copy link
Owner

jamsix commented Feb 22, 2025

FURS requires FIFO over all accounts and brokers, so your observation is correct.

ib-edavki should support that behavior. In the past we've had IBUK -> IBCE and IBCE->IBIE changes, so we already faced multiple possible accounts in the past and it has worked.

Hence, this is a bug that might require some debugging on your actual data.

@ddbk
Copy link
Contributor

ddbk commented Feb 26, 2025

@pronebird can you check if ISIN changed between purchase and sale? I had the same issue and this was the reason. I also have a quick (and dirty) fix ready to update all trades with the latest ISIN.

Edit: I see you included ISIN in the note above and that's not it. :/

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

No branches or pull requests

3 participants