Search in sources :

Example 21 with PortfolioTransaction

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));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 22 with PortfolioTransaction

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));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 23 with PortfolioTransaction

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));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 24 with PortfolioTransaction

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));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 25 with PortfolioTransaction

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()));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) EnumMap(java.util.EnumMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) LocalDate(java.time.LocalDate) Map(java.util.Map) Collections(java.util.Collections) Portfolio(name.abuchen.portfolio.model.Portfolio) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28