Skip to content

Commit

Permalink
Added dividend statements for Trade Republic
Browse files Browse the repository at this point in the history
Issue: #1234
  • Loading branch information
buchen committed Sep 29, 2019
1 parent 19ea81f commit 436f5a7
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"security": {
"name": "BASF SE",
"isin": "DE000BASF111",
"wkn": "BASF11"
"wkn": "BASF11",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"security": {
"name": "BASF SE",
"isin": "DE000BASF111",
"wkn": "BASF11"
"wkn": "BASF11",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"security": {
"name": "COMSTAGE-MSCI WORLD TRN U.ETF INH.ANT.I O.N. 1/1",
"isin": "LU0392494562",
"wkn": "ETF110"
"wkn": "ETF110",
"currency": "EUR"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"security": {
"name": "BASF SE",
"isin": "DE000BASF111",
"wkn": "BASF11"
"wkn": "BASF11",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"security": {
"name": "BASF SE",
"isin": "DE000BASF111",
"wkn": "BASF11"
"wkn": "BASF11",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"security": {
"name": "BASF SE",
"isin": "DE000BASF111",
"wkn": "BASF11"
"wkn": "BASF11",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"security": {
"name": "UBS Msci Pacific exJap.U ETF A",
"isin": "LU0446734526",
"wkn": "A0X97T"
"wkn": "A0X97T",
"currency": "USD"
},
"units": [
{
Expand All @@ -35,7 +36,8 @@
"security": {
"name": "ISHS Gbl.Corp.Bd.EU Hgd.U.ETF",
"isin": "IE00B9M6SJ31",
"wkn": "A1W02Q"
"wkn": "A1W02Q",
"currency": "EUR"
},
"units": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": 1,
"transactions": [
{
"type": "DIVIDEND",
"date": "2019-09-12",
"currency": "EUR",
"amount": 3.1,
"shares": 10.0,
"security": {
"name": "Microsoft Corp.",
"isin": "US5949181045",
"currency": "USD"
},
"units": [
{
"type": "GROSS_VALUE",
"fxAmount": 4.6,
"fxCurrency": "USD",
"fxRateToBase": 1.106
},
{
"type": "TAX",
"amount": 0.42
},
{
"type": "TAX",
"amount": 0.02
},
{
"type": "TAX",
"fxAmount": 0.69,
"fxCurrency": "USD",
"fxRateToBase": 1.106
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PDF Author: ''
PDFBox Version: 1.8.16
-----------------------------------------
TRADE REPUBLIC BANK GMBH KASTANIENALLEE 32 10435 BERLIN
My Name SEITE 1 von 1
My Str. 2 DATUM 12.09.2019
D 12345 Berlin DEPOT XXXXXXXXX
DIVIDENDE
ÜBERSICHT
Dividende mit dem Ex-Tag 14.08.2019.
POSITION ANZAHL ERTRÄGNIS BETRAG
Microsoft Corp. 10 Stk. 0,460 USD 4,60 USD
Registered Shares DL-,00000625
US5949181045
GESAMT 4,60 USD
ABRECHNUNG
POSITION BETRAG
Quellensteuer DE für US-Emittent -0,690 USD
Zwischensumme 3,91 USD
Zwischensumme 1,106 EUR/USD 3,54 EUR
Kapitalertragssteuer -0,420 EUR
Solidaritätszuschlag -0,020 EUR
GESAMT 3,10 EUR
BUCHUNG
VERRECHNUNGSKONTO VALUTA BETRAG
DE63110XXXXXXXXXXXXXXX 12.09.2019 3,10 EUR
Microsoft Corp. Registered Shares DL-,00000625 in Girosammelverwahrung.
Diese Abrechnung wird maschinell erstellt und daher nicht unterschrieben.
Sofern keine Umsatzsteuer ausgewiesen ist, handelt es sich gem. § 4 Nr. 8 UStG um eine umsatzsteuerfreie
Leistung.
Trade Republic Bank GmbH www.traderepublic.com Sitz der Gesellschaft: Düsseldorf Geschäftsführer
Kastanienallee 32 [email protected] AG Düsseldorf HRB 85864 Ingo Hillen
10435 Berlin USt-ID DE307510626 Karsten Müller
ABRE / 12.09.2019 / 363XXXXX / XXXX-XXXX
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import name.abuchen.portfolio.json.JSecurity;
import name.abuchen.portfolio.json.JTransaction;
import name.abuchen.portfolio.json.JTransactionUnit;
import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.BuySellEntry;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.model.Transaction;
import name.abuchen.portfolio.money.Money;
import name.abuchen.portfolio.money.Values;
Expand Down Expand Up @@ -97,6 +99,9 @@ private void addTransaction()
case SALE:
pdftx.wrap(t -> wrapBuySell(t, PortfolioTransaction.Type.SELL));
break;
case DIVIDEND:
pdftx.wrap(this::wrapDividend);
break;
default:
throw new IllegalArgumentException();
}
Expand Down Expand Up @@ -160,6 +165,7 @@ private void setValuesToSecurity(JTransaction t, Map<String, String> v)
security.setIsin(v.get("isin")); //$NON-NLS-1$
security.setTicker(v.get("ticker")); //$NON-NLS-1$
security.setWkn(v.get("wkn")); //$NON-NLS-1$
security.setCurrency(asCurrencyCode(v.get("currency"))); //$NON-NLS-1$
t.setSecurity(security);
}

Expand Down Expand Up @@ -232,12 +238,7 @@ private Extractor.Item wrapBuySell(JTransaction t, PortfolioTransaction.Type txT

entry.setShares(Values.Share.factorize(t.getShares()));

Map<String, String> values = new HashMap<>();
values.put("name", t.getSecurity().getName()); //$NON-NLS-1$
values.put("isin", t.getSecurity().getIsin()); //$NON-NLS-1$
values.put("tickerSymbol", t.getSecurity().getTicker()); //$NON-NLS-1$
values.put("wkn", t.getSecurity().getWkn()); //$NON-NLS-1$
entry.setSecurity(getOrCreateSecurity(values));
entry.setSecurity(convertToSecurity(t));

t.getUnits().map(u -> convertToUnit(t, u)).filter(Objects::nonNull)
.forEach(u -> entry.getPortfolioTransaction().addUnit(u));
Expand All @@ -247,12 +248,62 @@ private Extractor.Item wrapBuySell(JTransaction t, PortfolioTransaction.Type txT
return item;
}

private Extractor.Item wrapDividend(JTransaction t)
{
AccountTransaction tx = new AccountTransaction();
tx.setType(AccountTransaction.Type.DIVIDENDS);

tx.setAmount(Values.Amount.factorize(t.getAmount()));
tx.setCurrencyCode(t.getCurrency());
tx.setShares(Values.Share.factorize(t.getShares()));

if (t.getTime() != null)
tx.setDateTime(t.getDate().atTime(t.getTime()));
else
tx.setDateTime(t.getDate().atStartOfDay());

tx.setSecurity(convertToSecurity(t));

t.getUnits().map(u -> convertToUnit(t, u)).filter(Objects::nonNull).forEach(tx::addUnit);

TransactionItem item = new TransactionItem(tx);
item.setData(t);
return item;
}

private Security convertToSecurity(JTransaction t)
{
Map<String, String> values = new HashMap<>();
values.put("name", t.getSecurity().getName()); //$NON-NLS-1$
values.put("isin", t.getSecurity().getIsin()); //$NON-NLS-1$
values.put("tickerSymbol", t.getSecurity().getTicker()); //$NON-NLS-1$
values.put("wkn", t.getSecurity().getWkn()); //$NON-NLS-1$
values.put("currency", t.getSecurity().getCurrency()); //$NON-NLS-1$
return getOrCreateSecurity(values);
}

private Transaction.Unit convertToUnit(JTransaction jtx, JTransactionUnit junit)
{
if (junit.getAmount() == 0d)
return null;
Money amount = null;

if (junit.getAmount() == null || junit.getAmount() == 0d)
{
// if amount is not available, but fxAmount and fxRateToBase is,
// calculate the value
if (junit.getFxAmount() == null || junit.getFxAmount() == 0d //
|| junit.getFxRateToBase() == null
|| junit.getFxRateToBase().compareTo(BigDecimal.ZERO) == 0)
return null;

double value = BigDecimal.valueOf(junit.getFxAmount())
.divide(junit.getFxRateToBase(), 2, RoundingMode.HALF_DOWN).doubleValue();

Money amount = Money.of(jtx.getCurrency(), Values.Amount.factorize(junit.getAmount()));
amount = Money.of(jtx.getCurrency(), Values.Amount.factorize(value));
}
else
{
amount = Money.of(jtx.getCurrency(), Values.Amount.factorize(junit.getAmount()));
}

if (junit.getType() != Transaction.Unit.Type.GROSS_VALUE
&& (junit.getFxAmount() == null || junit.getFxAmount() == 0d))
Expand All @@ -262,7 +313,7 @@ private Transaction.Unit convertToUnit(JTransaction jtx, JTransactionUnit junit)
if (Strings.isNullOrEmpty(junit.getFxCurrency()))
return null;

String fxCurrency = asCurrencyCode(junit.getFxCurrency());
String fxCurrency = asCurrencyCode(jtx.getSecurity().getCurrency());

if (jtx.getCurrency().equals(fxCurrency))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public PDFImportAssistant(Client client, List<File> files)
extractors.add(new JSONPDFExtractor(client, "deutsche-bank-purchase.json")); //$NON-NLS-1$
extractors.add(new JSONPDFExtractor(client, "deutsche-bank-sale.json")); //$NON-NLS-1$
extractors.add(new JSONPDFExtractor(client, "ffb-purchase.json")); //$NON-NLS-1$
extractors.add(new JSONPDFExtractor(client, "trade-republic-dividends.json")); //$NON-NLS-1$
}

public Map<Extractor, List<Item>> run(IProgressMonitor monitor, Map<File, List<Exception>> errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"context": "SECURITY",
"pattern": [
"^Splittkauf( Betrag)? (?<name>.*) [\\d.,]+ \\w{3} [\\d.,]+ \\w{3} [\\d.,]+$",
"^Splittkauf( Betrag)? (?<name>.*) [\\d.,]+ \\w{3} [\\d.,]+ (?<currency>\\w{3}) [\\d.,]+$",
"^[\\d]* (?<wkn>[^ ]+) / (?<isin>[^ ]+) .*"
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"version": 1,
"name": "Deutsche Bank - Kaufbuchungen",
"locale": "de",
"pattern": [
"TRADE REPUBLIC",
"DIVIDENDE"
],
"transactions": [
{
"type": "DIVIDEND",
"startWith": "DIVIDENDE",
"sections": [
{
"context": "SECURITY",
"pattern": [
"POSITION ANZAHL ERTRÄGNIS BETRAG",
"(?<name>.*) ([\\d+,.]*) Stk. ([\\d+,.]*) (?<currency>\\w{3}+) ([\\d+,.]*) (\\w{3}+)$",
".*",
"(?<isin>.*)"
]
},
{
"pattern": [
"GESAMT ([\\d+,.]*) (\\w{3}+)",
"GESAMT (?<amount>[\\d+,.]*) (?<currency>\\w{3}+)"
]
},
{
"pattern": [
"VERRECHNUNGSKONTO VALUTA BETRAG",
".* (?<date>\\d+.\\d+.\\d{4}+) ([\\d+,.]*) (\\w{3}+)"
]
},
{
"pattern": [
"POSITION ANZAHL ERTRÄGNIS BETRAG",
"(.*) (?<shares>[\\d+,.]*) Stk. ([\\d+,.]*) (\\w{3}+) ([\\d+,.]*) (\\w{3}+)$"
]
},
{
"context": "UNIT",
"isOptional": true,
"pattern": [
"GESAMT (?<fxAmount>[\\d+,.]*) (?<fxCurrency>\\w{3}+)",
"Zwischensumme (?<fxRateToBase>[\\d.,]+) \\w{3}+/\\w{3}+ [\\d.,]+ \\w{3}+"
],
"attributes": {
"type": "GROSS_VALUE"
}
},
{
"context": "UNIT",
"isOptional": true,
"pattern": [
"Kapitalertragssteuer -(?<amount>[\\d.,]+) (?<currency>\\w{3}+)"
],
"attributes": {
"type": "TAX"
}
},
{
"context": "UNIT",
"isOptional": true,
"pattern": [
"Solidaritätszuschlag -(?<amount>[\\d.,]+) (?<currency>\\w{3}+)"
],
"attributes": {
"type": "TAX"
}
},
{
"context": "UNIT",
"isOptional": true,
"pattern": [
"Quellensteuer DE für US-Emittent -(?<fxAmount>[\\d.,]+) (?<fxCurrency>\\w{3}+)",
"Zwischensumme (?<fxRateToBase>[\\d.,]+) \\w{3}+/\\w{3}+ [\\d.,]+ \\w{3}+"
],
"attributes": {
"type": "TAX"
}
}
]
}
]
}
Loading

0 comments on commit 436f5a7

Please sign in to comment.