Search in sources :

Example 1 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class CrossEntryCheckTest method testThatNotTheSamePortfolioIsMatched.

@Test
public void testThatNotTheSamePortfolioIsMatched() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);
    LocalDateTime date = LocalDateTime.now();
    portfolio.addTransaction(new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_IN, 1, 0));
    PortfolioTransaction umatched = new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_OUT, 1, 0);
    portfolio.addTransaction(umatched);
    second.addTransaction(new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_OUT, 1, 0));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(instanceOf(MissingPortfolioTransferIssue.class)));
    assertThat(portfolio.getTransactions(), hasItem(umatched));
    assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(second.getTransactions().get(0).getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
    applyFixes(client, issues);
}
Also used : LocalDateTime(java.time.LocalDateTime) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 2 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class CrossEntryCheckTest method testThatAccountTransactionsWithoutSecurity.

@Test
public void testThatAccountTransactionsWithoutSecurity() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);
    account.addTransaction(new AccountTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 1, null, AccountTransaction.Type.BUY));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0).getAvailableFixes().get(0), is(instanceOf(DeleteTransactionFix.class)));
    applyFixes(client, issues);
    ClientSnapshot.create(client, new TestCurrencyConverter(), LocalDate.now());
}
Also used : Issue(name.abuchen.portfolio.checks.Issue) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test)

Example 3 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class CheckCurrenciesBuySellEntryTest method testBuySellEntry.

@Test
public void testBuySellEntry() {
    Account account = new Account();
    account.setCurrencyCode("EUR");
    Security security = new Security();
    security.setCurrencyCode("USD");
    Portfolio portfolio = new Portfolio();
    BuySellEntry entry = new BuySellEntry();
    entry.setType(PortfolioTransaction.Type.BUY);
    entry.setSecurity(security);
    entry.setMonetaryAmount(Money.of("EUR", 100_00));
    entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 80_00), Money.of("USD", 100_00), BigDecimal.valueOf(0.8)));
    assertThat(action.process(entry, account, portfolio).getCode(), is(Status.Code.OK));
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 4 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 5 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8