The application calculates profits (and losses) from stock and dividend transactions for a given tax year.
Polish translation (for SEO): aplikacja licząca podatek od akcji i dywidend.
Most applications that provide stock trading functions for retail investors generate tax forms automatically. At least they do if you are a citizen of one of the larger countries with a higher concentration of customers. I am a citizen of Poland, and for me, neither Degiro nor Revolut prepares a tax form related to gains (or losses) on stocks.
Have you ever tried to manually assess taxes for stock transactions? It is an extremely repetitive process to say the least, so I decided to automate it.
Disclaimer: There is NO guarantee that this application works correctly. In fact, it is more likely that it works incorrectly. (e.g., see incorrect tax values: #6)
There are certain assumptions:
- the principles of Polish tax law are hard-coded (e.g., 19% income tax, no long-term capital gains)
- currency exchange rates based on the National Bank of Poland
- the only currencies supported are USD, EUR and PLN
The current implementation supports two platforms: Revolut and Degiro. Transaction providers are implemented via an interface, so adding implementations for other platforms should be relatively simple.
The application uses the following code structure to keep the CSV files fairly organized: data/investing/{platform}/{year}.csv
.
- Log in to the
Degiro
through Web Browser, - Activity (left panel) -> Account Statement,
- Select "start date" and "end date" which contain all transactions,
- Export (CSV),
- Save downloaded file to
data/investing/degiro/{year}.csv
.
- Open
Revolut
application, - Go to
Stocks
section, - Click on
...
button next to+ Add money
, - Choose
Statements
, - Change format to
Excel
, - Select "starting on" and "ending on" dates to include full fiscal year (e.g. January 2021 -> December 2021),
- Click on "Get statement",
- Download the statement and convert to CSV,
- Save converted file to
data/investing/revolut/{year}.csv
.
Wallet
->Overview
,Transaction History
in the left panel,- Click on
Generate all statements
in the top right, - Choose time range related to desired fiscal year,
First, you need to save the transactions from the platforms you use (instructions above).
$ ls -al data/investing/degiro
.rw-r--r-- 0 mwarzynski 2 Jan 00:00 .keep
.rw-r--r-- 1k mwarzynski 2 Jan 00:00 2020.csv
.rw-r--r-- 1k mwarzynski 2 Jan 00:00 2021.csv
$ ls -al data/investing/revolut
.rw-r--r-- 0 mwarzynski 2 Jan 00:00 .keep
.rw-r--r-- 1k mwarzynski 2 Jan 00:00 2020.csv
.rw-r--r-- 1k mwarzynski 2 Jan 00:00 2021.csv
If you already have this data, just run the script as follows:
$ python main.py
tax_stocks: computes the profits (and losses) for stocks transactions and dividends for particular fiscal year.
Example: python main.py 2020
$ python main.py 2020
Year: 2020
=== Stocks
Profit = 50420.6969 PLN
Tax = 9579.9324 PLN
Sell: 120480.12 PLN, Buy: 70059.4231 PLN
TSLA: 50420.6969 PLN
=== Dividends
Total = 0.0000 PLN
Net = 0.0000 PLN
Tax = 0.0000 PLN
Tax (paid) = 0.0000 PLN
$ python main.py 2021
Year: 2021
=== Stocks
Profit = 100420.6969 PLN
Tax = 19079.9324 PLN
Sell: 1000463.3938 PLN, Buy: 900042.6969 PLN
TSLA: 100420.6969 PLN
=== Dividends
Total = 1718.9905 PLN
Net = 1392.3820 PLN
Tax = 326.6080 PLN
Tax (paid) = 258.0565 PLN
Helpful links: