doino-gretchenliev / revolut-stocks
- среда, 3 февраля 2021 г. в 00:24:57
Python
Processing and calculating the required information about stock possession and operation is complicated and time-consuming. So that brought the idea of developing a calculator that is able to automate the process from end-to-end.
Revolut Stock calculator is able to parse Revolut statement documents and provide a ready-to-use tax declaration file(dec50_2020_data.xml
), that you can import into NAP online system. Each part of the declaration is also exported as csv
file for verification.
*.pdf
).pdf
format. Parsing a pdf
file is a risky task and heavily depends on the structure of the file. In order to prevent miscalculations, please review the generated statements.csv
file under the output
directory and make sure all activities are correctly extracted from your statement files.First-In, First-Out
. The calculator is developed according to that rule.-b
flag. When activating BNB online service provider, make sure you do not spam the BNB service with too many requests. Each execution makes around 3-5 requests.csv
and xml
files to identify stock symbols along with their records. You can use those identification comments to aggregate records with data, out of the scope of the calculator.Note: The calculator is not natively tested on Windows OS. When using Windows it's preferable to use WSL and Docker.
pip install -r requirements.txt
python stocks.py -i <path_to_input_dir> -o <path_to_output_dir>
python stocks.py -h
Output:
[INFO]: Collecting statement files.
[INFO]: Collected statement files for processing: ['input/statement-3cbc62e0-2e0c-44a4-ae0c-8daa4b7c41bc.pdf', 'input/statement-19ed667d-ba66-4527-aa7a-3a88e9e4d613.pdf'].
[INFO]: Parsing statement files.
[INFO]: Generating [statements.csv] file.
[INFO]: Populating exchange rates.
[INFO]: Generating [app8-part1.csv] file.
[INFO]: Calculating sales information.
[INFO]: Generating [app5-table2.csv] file.
[INFO]: Calculating dividends information.
[INFO]: Generating [app8-part4-1.csv] file.
[INFO]: Generating [dec50_2020_data.xml] file.
[INFO]: Profit/Loss: 1615981 lev.
Replace <path_to_input_dir>
and <path_to_output_dir>
placeholders in the docker-compose.yml
with paths to your input and output directories.
docker-compose up --build
Output file | NAP mapping | Description |
---|---|---|
dec50_2020_data.xml |
Декларация по чл.50 от ЗДДФЛ, Приложение 5 и 8 |
Tax declaration - ready for import. |
statements.csv |
N/A | Verification file to ensure correct parsing. Should be verified manually. |
app5-table2.csv |
Приложение 5, Таблица 2 |
|
app8-part1.csv |
Приложение 8, Част ІV, 1 |
|
app8-part4-1.csv |
Приложение 8, Част І |
Errors are being reported along with an ERROR
label. For example:
[ERROR]: Unable to get exchange rate from BNB. Please, try again later.
Traceback (most recent call last):
File "/mnt/c/Users/doino/Personal/revolut-stocks/libs/exchange_rates.py", line 57, in query_exchange_rates
date = datetime.strptime(row[0], BNB_DATE_FORMAT)
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data ' ' does not match format '%d.%m.%Y'
Please, check the latest reported error in the log for more information.
The error indicates that there was an issue obtaining the exchange rate from BNB online service. Please, test BNB online service manually here, before reporting an issue.
There was an issue finding input statement files. Please, check your input directory configuration and file permissions.
The calculator parser was unable to parse any activities within your statement file. Please, check your statement files and ensure there are reported activities. If there are reported activities, but the error still persists, please open an issue.
The calculator found unsupported activity type/s. Please, open an issue and include the reported activity type.
The calculator, while trying to perform the SSP surrender shares operation, was unable to find the previously purchased shares for the same stock symbol. Please, ensure there is a statement file in the input directory, containing the original purchase.
NOTE: Importing dec50_2020_data.xml
will clear all filling in your current tax declaration.
The dec50_2020_data.xml
file contains applications 5 and 8. It could be imported into NAP online system with the use of NAP web interface, navigating to Декларации, документи или данни, подавани от физически лица/Декларации по ЗДДФЛ/Декларация по чл.50 от ЗДДФЛ
and clinking on Импорт на файл
button.
During the import, a few errors will be reported. That's normal(see exceptions below). The reason for the errors is that the imported file contains data for applications 5 and 8 only, but the system expects a complete filling of the document. After the import, you can continue filling your tax declaration as usual. Don't forget to enable applications 5 and 8 under part 3 of the main document. After you enable them you should navigate to each application, verify the data and click Потвърди
button.
During the import, if there are reported errors in the fillings of applications 5 or 8, that's a sign of a bug in the calculator itself. Please report the error here.
As this was a late-night project, improvements could be made. I'm open to new PRs.
Please submit issues here.
You can find me on my social media accounts: