Code Monkey home page Code Monkey logo

tastyworks-pnl's Issues

Support für den CSV Export aus der Plattform

Hi,
warum wird eigentlich in dem Tool auf den WebClient für den CSV Download verwiesen? Warum kann man nicht den von der Plattform generierten nehmen. Eigentlich müsste doch das der gleiche Inhalt sein. Das zusammenfriemeln der CSV ist sehr anfällig für manuelle Fehler. Der Export aus der Plattform hat die 250 Zeilen Datensatzbegrenzung nicht.

Altrnativ, wäre es möglich, dass man statt einer einzelnen CSV einen Ordner voller CSVs als Input nehmen kann und das Tool kümmert sich daraum daraus einen validen Datensatz zu bauen wobei Duplikate z.B. in den Exports automatisch entfernt werden.

TypeError: 'type' object is not subscriptable

When running the script I get the following error:
File "tw-pnl.py", line 186, in
SP500: tuple[str, ...] = ('A', 'AAL', 'AAP', 'AAPL', 'ABBV', 'ABC', 'ABT', 'ACGL', 'ACN', 'ADBE',
TypeError: 'type' object is not subscriptable

Any idea what that means?

Download Limit Transaction History

Currently, the only simple way to download all transactions in one go, one needs to use
the desktop application. Downloads within the web version is limited to 250 lines.

Sadly both formats differ. Do you know how much effort it might be to adjust the code to understand the format from the Desktop Apps Exports ?

Using the web frontend works, but only with a lot of manual steps which lead to errors and possibly missing transactions.

Verlustverrechnungsbeschränkung 2021

Hi @laroche, great tool! Does it also support the new "Verlustverrechnungsbeschränkung für Termingeschäfte bis 20.000€" introduced in 2021? I saw there is a parameter term_loss but I'm unsure if I can just set it to 20000 and that's it? Thank you

[Frage] convert currency, funktioniert es richtig?

hallo Florian,
woher soll man wissen ob die USD / EUR Wechsel funktioniert oder nicht?

image

Ich sehe immer nur "= 0.00 pnl"

Wenn ich aber die Anwendung mit --usd starte, dann ist die Zusammenfassung meiner Meinung nach richtig, es steht überall $ und die Werte sind höher.

Aber warum steht dort immer "= 0.00 pnl"?

Oder passt es so, und Ihr habt es auch so?
Danke!
Alneven

Problem with --tax-output=2021

Hello,
at first, thanks for the cool software.
Without the option --tax-output=2021 the program works fine.

However, when using the option --tax-output=2021 it prints the summary for 2021 on the command line but the csv file is not generated. It breaks with the following trace.

Traceback (most recent call last):
File "./tw-pnl.py", line 1124, in
main(sys.argv[1:])
File "./tw-pnl.py", line 1121, in main
check(all_wk, output_summary, output_csv, output_excel, tax_output, show)
File "./tw-pnl.py", line 1046, in check
new_wk = append_yearly_stats(new_wk, tax_output, stats, min_year, max_year)
File "./tw-pnl.py", line 710, in append_yearly_stats
df = df_append_row(df, ['', '', '', '', '', '', '', '', '', '', ''] + end)
File "./tw-pnl.py", line 465, in df_append_row
df.loc[len(df)] = row
File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line 723, in setitem
iloc._setitem_with_indexer(indexer, value, self.name)
File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line 1724, in _setitem_with_indexer
self._setitem_with_indexer_missing(indexer, value)
File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line 2027, in _setitem_with_indexer_missing
raise ValueError("cannot set a row with mismatched columns")
ValueError: cannot set a row with mismatched columns

Receive Deliver - Symbol Change not considered

In case of a symbol change an uncaught exception is raised since the subcode is not implemented.

Sample data:

Date/Time Transaction Code Transaction Subcode Symbol Buy/Sell Open/Close Quantity Expiration Date Strike Call/Put Price Fees Amount Description Account Reference
12/22/2020 12:32 PM Receive Deliver Symbol Change GOEV Sell Open 1 01/15/2021 15 P   0.00 118 Symbol change: Open 1.0 GOEV 210115P00015000 Individual...80
12/22/2020 12:32 PM Receive Deliver Symbol Change HCAC Buy Close 1 01/15/2021 15 P   0.00 -118 Symbol change: Close 1.0 HCAC 210115P00015000 Individual...80

[BUG]: Program terminates with key error

Given the following CSV:

Date/Time,Transaction Code,Transaction Subcode,Symbol,Buy/Sell,Open/Close,Quantity,Expiration Date,Strike,Call/Put,Price,Fees,Amount,Description,Account Reference
04/21/2021 8:11 PM,Trade,Sell to Close,NIO,Sell,Close,100,,,,38.02,0.112,3802,Sold 100 NIO @ 38.02,Individual...35
04/21/2021 8:11 PM,Trade,Buy to Close,NIO,Buy,Close,1,05/07/2021,37.5,C,2.72,0.13,-272,Bought 1 NIO 05/07/21 Call 37.50 @ 2.72,Individual...35
04/19/2021 3:50 PM,Trade,Buy to Open,NIO,Buy,Open,100,,,,37,0.08,-3700,Bought 100 NIO @ 37.00,Individual...35
04/19/2021 3:50 PM,Trade,Sell to Open,NIO,Sell,Open,1,05/07/2021,37.5,C,2.45,1.142,245,Sold 1 NIO 05/07/21 Call 37.50 @ 2.45,Individual...35
03/26/2021 9:00 PM,Receive Deliver,Expiration,NIO,,,3,03/26/2021,47,C,,0.00,0,Removal of 3.0 NIO 03/26/21 Call 47.00 due to expiration.,Individual...35
03/26/2021 9:00 PM,Receive Deliver,Expiration,NIO,,,3,03/26/2021,46.5,C,,0.00,0,Removal of 3.0 NIO 03/26/21 Call 46.50 due to expiration.,Individual...35

You will get the following error:

Traceback (most recent call last):
  File "tw-pnl.py", line 733, in <module>
    main(sys.argv[1:])
  File "tw-pnl.py", line 730, in main
    check(wk, output_csv, output_excel, opt_long, verbose, show, debugfifo)
  File "tw-pnl.py", line 606, in check
    (tsubcode in ('Expiration', 'Exercise', 'Assignment') and fifos_islong(fifos, asset)):
  File "tw-pnl.py", line 354, in fifos_islong
    return fifos[asset][0][2] > 0
KeyError: 'NIO C46.5 21-03-26'

--assume-individual-stock does not work

I changed it to:

if opt in ('--assume-individual-stock')

then it works in my local branch. Also I cannot push to the repo. Mind marking me as collaborator?

"Z19 Ausländische Kapitalerträge" ohne Verluste aus Termingeschäften

Hallo Florian,

vielen Dank für die tolle Arbeit, die du mit diesem Tool geleistet hast. Ich habe meine für 2022 zu zahlende Steuer über das Feld "KAP+KAP-INV KErSt+Soli" gecheckt und war über den hohen Wert überrascht. Dann ist mir aufgefallen, dass du wie in https://laroche.github.io/private-geldanlage/steuern.html dokumentiert in Z19 keine Verluste aus Termingeschäften subtrahierst.

Ich habe daraufhin zwei Demo-Termingeschäfte (Long Calls auf Aktien) erstellt und mir die Konsolenausgabe angeschaut. Hier werden bei zwei Trades knapp 20k Verlust erzielt und dann knapp 20k Gewinn.

Date/Time,Transaction Code,Transaction Subcode,Symbol,Buy/Sell,Open/Close,Quantity,Expiration Date,Strike,Call/Put,Price,Fees,Amount,Description,Account Reference
01/08/2023 3:36 PM,Trade,Sell to Close,AMD,Sell,Close,1,10/21/2023,80,P,250.00,0.142,25000,Sold 1 AMD 10/21/23 Put 80.00 @ 250.00,4711
01/07/2023 4:05 PM,Trade,Buy to Open,AMD,Buy,Open,1,10/21/2023,80,P,50,1.13,-5000,Bought 1 AMD 10/21/23 Put 80.00 @ 50.00,4711
01/06/2023 3:36 PM,Trade,Sell to Close,AMD,Sell,Close,1,10/21/2023,80,P,50,0.142,5000,Sold 1 AMD 10/21/23 Put 80.00 @ 50.00,4711
01/05/2023 4:05 PM,Trade,Buy to Open,AMD,Buy,Open,1,10/21/2023,80,P,250.00,1.13,-25000,Bought 1 AMD 10/21/23 Put 80.00 @ 250.00,4711

Unter dem Strich hätte ich dann eine Steuerschuld um die 0 erwartet. Das Tool sagt aber folgendes:

...
Long-Optionen-Gewinne 19046.41
Long-Optionen-Verluste -18821.98
Long-Optionen Gesamt 224.43
...
Z19 Ausländische Kapitalerträge 19046.41
Z21 Termingeschäftsgewinne+Stillhalter 19046.41
Z24 Termingeschäftsverluste -18821.98
KAP+KAP-INV 19046.41
KAP+KAP-INV KErSt+Soli 5023.49
KAP+KAP-INV Verlustvortrag 0.00
...

Mir ist aufgefallen, dass in meinem Interactive Brokers German Tax Report in Z19 "losses from trading in derivatives" bereits abgezogen sind und bin jetzt leicht verwirrt. Zum einen, welchen Wert ich bei meiner Steuererklärung in Z19 eintragen soll und zum anderen, warum mir eine Steuerlast von über 5k angezeigt wird. Vielleicht kannst du mir hier auf die Sprünge helfen.

Keep up the good work, viele Grüße,
Thomas

Key Error: Receive Deliver - Expiration on Options

Hi,

I encountered a "KeyError" when processing an expiration on an option.

Traceback:
Traceback

Fields in the transaction-csv
transactions.csv

As a workaround i deleted those lines and ran the program again.
Now it tells me I still have open positions (I have none), but at least the tax income statement gets created correct:
OpenPositions

Calculation of column "usd_gains"

Hi @laroche,

This is a tax law question rather than an issue: Why is the usd_gains column calculated the way it is? I can see that there's values in this column when option positions are opened and no values when they are closed. I'd have expected it the other way around, but my knowledge of the tax law isn't great. Could you explain why Währungsgewinne are calculated that way (or point me to an article)?

tsubcode 'Withdrawal' - Money Movement,Withdrawal - Wire Funds Received

Hi Florian,

tsubcode 'Withdrawal' doesn't recognize Wire Funds Received.

The following record from a tastyworks transaction history file

02/19/2020 11:00 PM,Money Movement,Withdrawal,,,,,,,,,0.00,1234.5,Wire Funds Received a/o 2/18,John Doe...06

yields an error message:

2020-02-19 23:00    1143.06€    1234.50$     1 dividends paid: nan, Wire Funds Received a/o 2/18
Traceback (most recent call last):
  File "./tw-pnl.py", line 599, in <module>
    main(sys.argv[1:])
  File "./tw-pnl.py", line 595, in main
    check(wk, output_csv, output_excel, all_currency_gains, opt_long,
  File "./tw-pnl.py", line 456, in check
    raise
RuntimeError: No active exception to reraise

Cheers,
Thomas

Special Dividend

Hello,
the script does not work in the (rare) case of a special dividend which leads to a change in the options strike prices.

The lines in the log are:

05/19/2022 1:02 PM,Receive Deliver,Special Dividend,JD,Sell,Open,1,07/01/2022,60.76,P,,0.00,1177,Special dividend: Open 1.0 JD 220701P00060760,
05/19/2022 1:02 PM,Receive Deliver,Special Dividend,JD,Buy,Close,1,07/01/2022,62,P,,0.00,-1177,Special dividend: Close 1.0 JD 220701P00062000,

Missing fees

Hi @laroche,

I love this tool and also the information you compiled about german tax law. Thank you so much, it's really very useful! I was going mad trying to do this in Libre Office.

I have one question regarding the fees. Following the instructions, I downloaded the transaction history on the web site and combined all data in one file. The script runs and finishes successfully. But while the source data has a Fees column with valid values, they are not included in the Ordergebühren column, nor elsewhere.

For my Lynx account I always put the fees in the tax form to be deducted. So my question is - is this intentional?

Reverse Split - Reverse Stock Split X to 1

hallo Florian,

hast Du vielleicht auch ein Beispiel für einen Reverse Stock Split?
Ich nutze dein Skript neben Tasty auch für Tradezero und hatte dort ich einen 10 zu 1 Aktiensplit. Ich bin mir nicht sicher, wie ich es in meiner Input Datei erfassen soll (oder wie ich überprüfen kann, ob es funktioniert hat...)

11/17/2022 00:00 AM,Receive Deliver,Reverse Split,XXX,Sell,Close,280,,,,,0.00,389.699,Reverse split: Close 280 XXX,tradezero...1
11/17/2022 00:00 AM,Receive Deliver,Reverse Split,XXX,Buy,Open,28,,,,,0.00,-389.699,Reverse split: Open 28 XXX,tradezero...1

Vielen Dank und Grüße
A

Wrong first line in csv file

Hi,

I have download the transaction history from the tastytade web page but it doesnt match the expected format.
It is in this format : Date,Type,Action,Symbol,Instrument Type,Description,Value,Quantity,Average Price,Commissions,Fees,Multiplier,Root Symbol,Underlying Symbol,Expiration Date,Strike Price,Call or Put,Order #

RuntimeError: No active exception to reraise

Moin moin und hallo,
ich wollte das Script mal bei mir durchlaufen lassen, bekomme es aber nicht hin. Hier mal der Auszug aus dem Terminal:

martin@Air-von-Martin tastyworks-pnl % python3 tw-pnl.py --assume-individual-stock --tax-output=2021 --output-csv=tastyworks-tax-2021.csv transaction_history.csv
Traceback (most recent call last):
File "/Users/martin/tastyworks-pnl/tw-pnl.py", line 1124, in
main(sys.argv[1:])
File "/Users/martin/tastyworks-pnl/tw-pnl.py", line 1121, in main
check(all_wk, output_summary, output_csv, output_excel, tax_output, show)
File "/Users/martin/tastyworks-pnl/tw-pnl.py", line 982, in check
check_trade(tsubcode, - (quantity * price), amount, asset_type)
File "/Users/martin/tastyworks-pnl/tw-pnl.py", line 159, in check_trade
raise
RuntimeError: No active exception to reraise

Ich benutze macos12.7 und python 3.10.6. Ich habs auch auf ubuntu probiert mit dem selben Ergebnis.

Gruß Martin

Blew up my account but tool says I made gains - did I do something wrong?

Hi @laroche
I just used your tool to calculate my Tastyworks tax. Thank you so much fro providing this service.
But to be honest I'm a bit confused by the result.

Basically I blew up my account in 2021. All my gains and most of my initial deposit was gone by the end of 2021.
The tool however calculated about 50% more gains than losses for that year under "Long-Optionen" and about 98% under "Stillhalter".

Did I do something wrong? Or just misunderstood something?

Thanks ins advance.

Use Case der Strike Adjustierung durch Special Dividend wird nicht abgedeckt

In meinem Log habe ich den Use Case der Special Dividend. Hier wurden die Strikes angepasst.

Fehlermeldung
{noformat}
Traceback (most recent call last):
File "C:\Users\michael\tastyworks-pnl\tw-pnl.py", line 1148, in
main(sys.argv[1:])
File "C:\Users\michael\tastyworks-pnl\tw-pnl.py", line 1145, in main
check(all_wk, output_summary, output_csv, output_excel, tax_output, show, verbose, debug)
File "C:\Users\michael\tastyworks-pnl\tw-pnl.py", line 1056, in check
stats = get_summary(new_wk, tax_output, min_year, max_year)
File "C:\Users\michael\tastyworks-pnl\tw-pnl.py", line 605, in get_summary
raise
RuntimeError: No active exception to reraise
{noformat}
Log Eintrag
{noformat}
12/29/2021 1:03 PM,Receive Deliver,Special Dividend,ARKK,Sell,Open,1,02/18/2022,79.22,P,,0.00,174,Special dividend: Open 1.0 ARKK 220218P00079220,Individual...90
12/29/2021 1:03 PM,Receive Deliver,Special Dividend,ARKK,Buy,Close,1,02/18/2022,80,P,,0.00,-174,Special dividend: Close 1.0 ARKK 220218P00080000,Individual...90
12/29/2021 1:03 PM,Receive Deliver,Special Dividend,ARKK,Sell,Open,1,02/18/2022,109.22,C,,0.00,131,Special dividend: Open 1.0 ARKK 220218C00109220,Individual...90
12/29/2021 1:03 PM,Receive Deliver,Special Dividend,ARKK,Buy,Close,1,02/18/2022,110,C,,0.00,-131,Special dividend: Close 1.0 ARKK 220218C00110000,Individual...90
12/28/2021 7:51 PM,Trade,Sell to Open,ARKK,Sell,Open,1,02/18/2022,80,P,1.74,1.132,174,Sold 1 ARKK 02/18/22 Put 80.00 @ 1.74,Individual...90
12/28/2021 7:51 PM,Trade,Sell to Open,ARKK,Sell,Open,1,02/18/2022,110,C,1.31,1.132,131,Sold 1 ARKK 02/18/22 Call 110.00 @ 1.31,Individual...90
{noformat}

Als Workaround habe ich die Special Dividend Einträge gelöscht und die Buy Log Einträge zum schließen des Calls und des Puts angespasst.

Problem with bmf_force = True

With the following data, a runtime error is generated when bmf_force = True is set (it works with bmf_force = False)

Date/Time,Transaction Code,Transaction Subcode,Symbol,Buy/Sell,Open/Close,Quantity,Expiration Date,Strike,Call/Put,Price,Fees,Amount,Description,Account Reference
09/23/2020 9:38 PM,Trade,Buy to Close,RUT,Buy,Close,8,10/30/2020,1530,P,98.19,2.53,-78552,Bought 8 RUT 10/30/20 Put 1530.00 @ 98.19,Individual...00
09/23/2020 9:30 PM,Trade,Buy to Close,RUT,Buy,Close,1,10/30/2020,1530,P,97.69,0.32,-9769,Bought 1 RUT 10/30/20 Put 1530.00 @ 97.69,Individual...00
08/24/2020 9:37 PM,Trade,Sell to Open,RUT,Sell,Open,1,10/30/2020,1530,P,60.96,1.322,6096,Sold 1 RUT 10/30/20 Put 1530.00 @ 60.96,Individual...00
08/24/2020 9:35 PM,Trade,Sell to Open,RUT,Sell,Open,6,10/30/2020,1530,P,61.16,7.902,36696,Sold 6 RUT 10/30/20 Put 1530.00 @ 61.16,Individual...00
08/24/2020 9:34 PM,Trade,Sell to Open,RUT,Sell,Open,2,10/30/2020,1530,P,60.97,2.634,12194,Sold 2 RUT 10/30/20 Put 1530.00 @ 60.97,Individual...00

Cryptos fail on quantity

As cryptos are bought in fractions this check here fails.

int(quantity) != quantity

if isnan(quantity):
quantity = 1
else:
if tcode == 'Receive Deliver' and (tsubcode == 'Forward Split' or tsubcode == 'Reverse Split'):
pass # splits might have further data, not quantity
elif int(quantity) != quantity:
raise
else:
quantity = int(quantity)

"Wire Funds Received" Line throws error

Hallo,

erst einmal vielen Dank für die super Software! :-)

Das Programm wirft bei mir einen Fehler bei Einzahlungen. (Wenn ich die Zeilen lösche, klappt alles)
Hier ist eine Beispiel Zeile:
08/19/2020 11:00 PM,Money Movement,Withdrawal,,,,0,,,,,0.00,2352.2,Wire Funds Received,Individual...80

Hier ist der Callstack:

2020-08-19 23:00 2352.20$ 2352.20$ 0 transferred: Wire Funds Received Traceback (most recent call last): File "C:\Users\martin\tastyworks\SteuerSw\tastyworks-pnl-main\tw-pnl.py", line 875, in <module> main(sys.argv[1:]) File "C:\Users\martin\tastyworks\SteuerSw\tastyworks-pnl-main\tw-pnl.py", line 872, in main check(wk, output_csv, output_excel, opt_long, verbose, show, debugfifo) File "C:\Users\martin\tastyworks\SteuerSw\tastyworks-pnl-main\tw-pnl.py", line 768, in check '%.2f' % float(local_pnl), '%.2f' % term_loss, ValueError: could not convert string to float: ''

Viele Grüße,
Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.