use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionHasGrossValueMatchingSecurityCurrency.
@Test
public void testTransactionHasGrossValueMatchingSecurityCurrency() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "USD");
Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
PortfolioTransaction t = new PortfolioTransaction();
t.setType(Type.DELIVERY_INBOUND);
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
t.addUnit(unit);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.removeUnit(unit);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
Unit other = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("JPY", 2_00), BigDecimal.valueOf(0.5));
t.addUnit(other);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionForexTaxesAndFees.
@Test
public void testTransactionForexTaxesAndFees() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "USD");
Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 10_00), Money.of("USD", 20_00), BigDecimal.valueOf(0.5));
Unit tax = new Unit(Unit.Type.TAX, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
Unit tax2 = new Unit(Unit.Type.TAX, Money.of("EUR", 1_00));
Unit fee = new Unit(Unit.Type.FEE, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
PortfolioTransaction t = new PortfolioTransaction();
t.setType(Type.DELIVERY_OUTBOUND);
t.setMonetaryAmount(Money.of("EUR", 20_00));
t.setSecurity(security);
t.addUnit(grossValue);
t.addUnit(fee);
t.addUnit(tax);
t.addUnit(tax2);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.removeUnit(fee);
t.addUnit(new Unit(Unit.Type.FEE, Money.of("EUR", 5_00), Money.of("JPY", 10_00), BigDecimal.valueOf(0.5)));
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionIfSecurityIsIndex.
@Test
public void testTransactionIfSecurityIsIndex() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", null);
PortfolioTransaction t = new PortfolioTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setType(Type.DELIVERY_OUTBOUND);
t.setSecurity(security);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CheckValidTypesActionTest method testPortfolioTransaction.
@Test
public void testPortfolioTransaction() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "EUR");
PortfolioTransaction t = new PortfolioTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
t.setType(PortfolioTransaction.Type.BUY);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.SELL);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.TRANSFER_IN);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class ClientPerformanceSnapshot method addCapitalGains.
private void addCapitalGains() {
Map<Security, MutableMoney> valuation = new HashMap<>();
for (Security s : client.getSecurities()) valuation.put(s, MutableMoney.of(converter.getTermCurrency()));
snapshotStart.getJointPortfolio().getPositions().stream().forEach(p -> valuation.get(p.getInvestmentVehicle()).subtract(p.calculateValue().with(converter.at(snapshotStart.getTime()))));
for (PortfolioTransaction t : snapshotStart.getJointPortfolio().getSource().getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
switch(t.getType()) {
case BUY:
case DELIVERY_INBOUND:
case TRANSFER_IN:
valuation.get(t.getSecurity()).subtract(t.getGrossValue().with(converter.at(t.getDateTime())));
break;
case SELL:
case DELIVERY_OUTBOUND:
case TRANSFER_OUT:
valuation.get(t.getSecurity()).add(t.getGrossValue().with(converter.at(t.getDateTime())));
break;
default:
throw new UnsupportedOperationException();
}
}
snapshotEnd.getJointPortfolio().getPositions().stream().forEach(p -> valuation.get(p.getInvestmentVehicle()).add(p.calculateValue().with(converter.at(snapshotEnd.getTime()))));
Category capitalGains = categories.get(CategoryType.CAPITAL_GAINS);
// add securities w/ capital gains to the positions
capitalGains.positions = //
valuation.entrySet().stream().filter(entry -> !entry.getValue().isZero()).map(entry -> new Position(entry.getKey(), entry.getValue().toMoney())).sorted(//
(p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())).collect(Collectors.toList());
// total capital gains -> sum it up
capitalGains.valuation = //
capitalGains.positions.stream().map(//
p -> p.getValuation()).collect(MoneyCollectors.sum(converter.getTermCurrency()));
}
Aggregations