-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
166 lines (137 loc) · 7.03 KB
/
Copy pathmain.py
File metadata and controls
166 lines (137 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import re
import json
import os
import sys
from numpy import true_divide
from lib.warrant import Warrant
from lib.certificate import Certificate
from lib.stock import Stock
from lib.dividend import Dividend
import pdfminer
from pdfminer.high_level import extract_text
import shutil
import pandas as pd
def determineDocument(pdf):
""" Scans the pdf document for certain text lines and determines the type of investment vehicle traded"""
if 'turbop' in pdf or 'turboc' in pdf:
return 'certificate'
elif 'minil' in pdf:
return 'certificate'
elif 'call' in pdf or 'put' in pdf:
return 'warrant'
elif 'dividende' in pdf:
return 'dividend'
elif 'ausschüttung' in pdf:
return 'dividend'
elif 'wertpapierabrechnung' in pdf:
return 'stock'
else:
return 'stock'
def checkDocument(pdf):
if 'trade' in pdf and 'republic' in pdf:
return True
else:
return False
sourceFolder = '/Downloads/'
destinationFolder = '/Wertpapierabrechnungen/'
os.makedirs(destinationFolder + "originals", exist_ok=True)
# entsprechend Portfolio Performance
header = ['date', 'type', 'note', 'ticker symbol', 'security name', 'shares', 'price', 'fees', 'taxes', 'value', 'ISIN', 'expiration date', 'strike price', 'warrant type', 'warrant underlying']
df = pd.DataFrame(columns=header)
os.chdir(sourceFolder)
files = os.listdir()
for file in files:
dfTemp = pd.DataFrame()
if 'pdf' in file:
pdf = extract_text(file).lower().split()
print("\nStarted parsing file")
if checkDocument(pdf):
pdfType = determineDocument(pdf)
if pdfType == 'certificate':
certificate = Certificate(pdf)
print(pdfType.capitalize())
print(file)
print(certificate.file)
print(certificate.date + ' ' + certificate.time)
print(certificate.orderType.upper())
print(certificate.productType + ' ' + certificate.underlying.upper())
print('ISIN: ' + certificate.isin.upper())
print('Asset: '+ certificate.securityName.capitalize())
print('Shares: ' + str(certificate.shares))
print('Market Price: ' + str(certificate.marketPrice))
print('Gross total: ' + str(certificate.grossTotal))
print(' - Brokerage Fee: ' + str(certificate.brokerageFee))
print(' - Taxes: ' + str(certificate.taxes))
print('Total: ' + str(certificate.total))
dfTemp = pd.DataFrame({'date': [certificate.date], 'type': [certificate.orderType], 'shares': [certificate.shares], 'price': [certificate.marketPrice], 'fees': [certificate.brokerageFee], 'taxes': [certificate.taxes], 'value': [certificate.total], 'ISIN': [certificate.isin], 'security name': [certificate.securityName.capitalize()]})
df = pd.concat([df, dfTemp])
print('File parsed')
shutil.copy(sourceFolder + file, destinationFolder + certificate.file)
shutil.move(sourceFolder + file, destinationFolder + "originals/" + file)
print('File moved')
if pdfType == 'warrant':
warrant = Warrant(pdf)
print('\n' + pdfType.capitalize())
print(file)
print(warrant.file)
print(warrant.orderType.upper())
print(warrant.date + ' ' + warrant.time)
print(warrant.option.upper() + ' ' + warrant.underlying.upper() + ' @' + str(warrant.strikePrice) + ' ' + warrant.expiry)
print('ISIN: ' + warrant.isin.upper())
print('Asset: '+ warrant.securityName.capitalize())
print('Shares: ' + str(warrant.shares))
print('Market Price: ' + str(warrant.marketPrice))
print('Gross total: ' + str(warrant.grossTotal))
print(' - Brokerage Fee: ' + str(warrant.brokerageFee))
print(' - Taxes: ' + str(warrant.taxes))
print('Total: ' + str(warrant.total))
dfTemp = pd.DataFrame({'date': [warrant.date], 'type': [warrant.orderType], 'shares': [warrant.shares], 'price': [warrant.marketPrice], 'fees': [warrant.brokerageFee], 'taxes': [warrant.taxes], 'value': [warrant.total], 'ISIN': [warrant.isin], 'security name': [warrant.securityName.capitalize()]})
df = pd.concat([df, dfTemp])
print('File parsed')
shutil.copy(sourceFolder + file, destinationFolder + warrant.file)
shutil.move(sourceFolder + file, destinationFolder + "originals/" + file)
print('File moved')
if pdfType == 'stock':
stock = Stock(pdf)
print('\n' + pdfType.capitalize())
print(file)
print(stock.file)
print(stock.date + ' ' + stock.time)
print(stock.orderType.upper())
print('ISIN: ' + stock.isin.upper())
print('Asset: '+ stock.securityName.capitalize())
print('Shares: ' + str(stock.shares))
print('Market Price: ' + str(stock.marketPrice))
print('Gross total: ' + str(stock.grossTotal))
print(' - Brokerage Fee: ' + str(stock.brokerageFee))
print(' - Taxes: ' + str(stock.taxes))
print('Total: ' + str(stock.total))
dfTemp = pd.DataFrame({'date': [stock.date], 'type': [stock.orderType], 'shares': [stock.shares], 'price': [stock.marketPrice], 'fees': [stock.brokerageFee], 'taxes': [stock.taxes], 'value': [stock.total], 'ISIN': [stock.isin], 'security name': [stock.securityName.capitalize()]})
df = pd.concat([df, dfTemp])
print('File parsed')
shutil.copy(sourceFolder + file, destinationFolder + stock.file)
shutil.move(sourceFolder + file, destinationFolder + "originals/" + file)
print('File moved')
if pdfType == 'dividend':
dividend = Dividend(pdf)
print('\n' + pdfType.capitalize())
print(file)
print(dividend.file)
print(dividend.date)
print(dividend.orderType.upper())
print('ISIN: ' + dividend.isin.upper())
print('Asset: '+ dividend.securityName.capitalize())
print('Shares: ' + str(dividend.shares))
print('Gross total: ' + str(dividend.grossTotal))
print(' - Brokerage Fee: ' + str(dividend.brokerageFee))
print(' - Taxes: ' + str(dividend.taxes))
print('Total: ' + str(dividend.total))
dfTemp = pd.DataFrame({'date': [dividend.date], 'type': [dividend.orderType], 'shares': [dividend.shares], 'fees': [dividend.brokerageFee], 'taxes': [dividend.taxes], 'value': [dividend.total], 'ISIN': [dividend.isin], 'security name': [dividend.securityName.capitalize()]})
df = pd.concat([df, dfTemp])
print('File parsed')
shutil.copy(sourceFolder + file, destinationFolder + dividend.file)
shutil.move(sourceFolder + file, destinationFolder + "originals/" + file)
print('File moved')
df.set_index('date')
df.to_csv(sourceFolder + 'parsedTrades.csv', ',')
print('\nProcessing completed\n')