use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class ClassificationIndexTest method testThatTaxesAreNotIncludedInTTWRORCalculation.
@Test
public void testThatTaxesAreNotIncludedInTTWRORCalculation() {
Client client = new Client();
Security security = //
new SecurityBuilder().addPrice("2015-12-31", //
Values.Quote.factorize(100)).addPrice("2016-12-31", //
Values.Quote.factorize(110)).addTo(client);
Account account = //
new AccountBuilder().deposit_("2014-01-01", Values.Amount.factorize(1000)).addTo(client);
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DIVIDENDS);
t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
t.setSecurity(security);
t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
t.setShares(Values.Share.factorize(10));
account.addTransaction(t);
Portfolio portfolio = //
new PortfolioBuilder(account).addTo(client);
BuySellEntry buy = new BuySellEntry(portfolio, account);
buy.setType(PortfolioTransaction.Type.BUY);
buy.setDate(LocalDateTime.parse("2015-12-31T00:00"));
buy.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1000)));
buy.setShares(Values.Share.factorize(10));
buy.setSecurity(security);
buy.insert();
BuySellEntry sell = new BuySellEntry(portfolio, account);
sell.setType(PortfolioTransaction.Type.SELL);
sell.setDate(LocalDateTime.parse("2016-12-31T00:00"));
sell.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1070)));
sell.setShares(Values.Share.factorize(10));
sell.setSecurity(security);
sell.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(30))));
sell.insert();
Classification classification = new Classification(null, null);
classification.addAssignment(new Assignment(security));
List<Exception> warnings = new ArrayList<Exception>();
PerformanceIndex index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
assertThat(warnings.isEmpty(), is(true));
// dividend payment 10% * quote change 10%
assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.1 * 1.1) - 1, 0.000000001d));
// add taxes to dividend payment
t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
// dividend payment 15% * quote change 10%
assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.15 * 1.1) - 1, 0.000000001d));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCurrencyGainsWithTransferalInOtherCurrencies.
@Test
public void testCurrencyGainsWithTransferalInOtherCurrencies() {
Client client = new Client();
Account usd = //
new AccountBuilder("USD").deposit_("2015-01-01", //
1000_00).addTo(client);
Account cad = //
new AccountBuilder("CAD").deposit_("2015-01-01", //
1000_00).addTo(client);
// insert account transfer
AccountTransferEntry entry = new AccountTransferEntry(usd, cad);
entry.setDate(LocalDateTime.parse("2015-01-10T00:00"));
AccountTransaction source = entry.getSourceTransaction();
AccountTransaction target = entry.getTargetTransaction();
source.setMonetaryAmount(Money.of("USD", 500_00));
target.setMonetaryAmount(Money.of("CAD", 1000_00));
source.addUnit(new Unit(Unit.Type.GROSS_VALUE, source.getMonetaryAmount(), target.getMonetaryAmount(), BigDecimal.valueOf(.5)));
entry.insert();
// check currency gain calculation of client performance snapshot
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new //
ClientPerformanceSnapshot(//
client, //
converter, LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-15"));
MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
currencyGains.add(snapshot.getValue(CategoryType.FEES));
currencyGains.add(snapshot.getValue(CategoryType.TAXES));
currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class SecurityPositionTest method testSplittingPositionsWithForexGrossValue.
@Test
public void testSplittingPositionsWithForexGrossValue() {
Security security = new Security("", CurrencyUnit.EUR);
SecurityPrice price = new SecurityPrice(LocalDate.of(2016, Month.DECEMBER, 2), Values.Quote.factorize(10.19));
PortfolioTransaction inbound_delivery = new PortfolioTransaction();
inbound_delivery.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
inbound_delivery.setDateTime(LocalDateTime.parse("2016-01-01T00:00"));
inbound_delivery.setSecurity(security);
inbound_delivery.setMonetaryAmount(Money.of(CurrencyUnit.USD, Values.Amount.factorize(27409.55)));
inbound_delivery.setShares(Values.Share.factorize(2415.794));
Unit grossValue = new //
Unit(//
Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.USD, Values.Amount.factorize(27409.55)), Money.of(CurrencyUnit.EUR, Values.Amount.factorize(24616.95)), BigDecimal.valueOf(1.1134421608));
inbound_delivery.addUnit(grossValue);
SecurityPosition position = new SecurityPosition(security, new TestCurrencyConverter(), price, Arrays.asList(inbound_delivery));
// 20%
SecurityPosition third = SecurityPosition.split(position, 20 * Values.Weight.factor());
// 24616.95 EUR * 0.2 = 4923,39 EUR
assertThat(third.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4923.39))));
assertThat(third.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, Math.round(position.getFIFOPurchaseValue().getAmount() * 0.2))));
assertThat(third.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4923.39))));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class IRRCalculationTest method testDividendPaymentsWithTaxes.
@Test
public void testDividendPaymentsWithTaxes() {
List<Transaction> tx = new ArrayList<>();
Security security = new Security();
tx.add(new //
PortfolioTransaction(//
LocalDateTime.of(2015, Month.DECEMBER, 31, 0, 0), //
CurrencyUnit.EUR, //
Values.Amount.factorize(1000), //
security, //
Values.Share.factorize(10), //
PortfolioTransaction.Type.BUY, Values.Amount.factorize(10), 0));
DividendTransaction t = new DividendTransaction();
t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
t.setSecurity(security);
t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
t.setShares(Values.Share.factorize(10));
t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
tx.add(t);
tx.add(new //
PortfolioTransaction(//
LocalDateTime.of(2016, Month.DECEMBER, 31, 0, 0), //
CurrencyUnit.EUR, //
Values.Amount.factorize(1200), //
security, //
Values.Share.factorize(10), //
PortfolioTransaction.Type.SELL, Values.Amount.factorize(10), Values.Amount.factorize(30)));
IRRCalculation calculation = Calculation.perform(IRRCalculation.class, new TestCurrencyConverter(), tx);
// Excel verification
// 31.12.15 -1000
// 01.06.16 150
// 31.12.16 1230
// =XINTZINSFUSS(B1:B3;A1:A3) = 0,412128788
assertThat(calculation.getIRR(), IsCloseTo.closeTo(0.412128788d, 0.00000001d));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class BankSLMPDFExtractor method addForexGrossValue.
@SuppressWarnings("nls")
private void addForexGrossValue(Transaction<BuySellEntry> extractor) {
//
extractor.section("forexSum", "forexCurrency", "grossValue", "currency", "exchangeRate").optional().match(//
"Total Kurswert (?<forexCurrency>\\w{3}+) (?<forexSum>[\\d.'-]+)").match(//
"Change .../... (?<exchangeRate>[\\d.']+) (?<currency>\\w{3}+) (?<grossValue>[\\d.'-]+)").assign((t, v) -> {
Money grossValue = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("grossValue")));
Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forexSum")));
BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate"));
Unit unit = new Unit(Unit.Type.GROSS_VALUE, grossValue, forex, exchangeRate);
// security actually matches
if (unit.getForex().getCurrencyCode().equals(t.getPortfolioTransaction().getSecurity().getCurrencyCode()))
t.getPortfolioTransaction().addUnit(unit);
});
}
Aggregations