@Test
  public void testErtragsgutschrift() throws IOException {
    DeutscheBankPDFExctractor extractor =
        new DeutscheBankPDFExctractor(new Client()) {
          @Override
          String strip(File file) throws IOException {
            return from("DeutscheBankErtragsgutschrift.txt");
          }
        };
    List<Exception> errors = new ArrayList<Exception>();

    List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);

    // check security
    Security security = assertSecurity(results);

    // check transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDate(), is(LocalDate.parse("2014-12-15")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 1495L)));
    assertThat(transaction.getShares(), is(Values.Share.factorize(123)));
  }
    @Override
    public void execute() {
      BuySellEntry entry = new BuySellEntry(portfolio, account);
      entry.setDate(transaction.getDate());
      entry.setType(PortfolioTransaction.Type.valueOf(transaction.getType().name()));
      entry.setSecurity(transaction.getSecurity());
      entry.setShares(Values.Share.factor());
      entry.setAmount(transaction.getAmount());
      entry.setCurrencyCode(transaction.getCurrencyCode());
      entry.insert();

      account.getTransactions().remove(transaction);
    }
  @Test
  public void testErtragsgutschrift2() throws IOException {
    DeutscheBankPDFExctractor extractor =
        new DeutscheBankPDFExctractor(new Client()) {
          @Override
          String strip(File file) throws IOException {
            return from(file.getName());
          }
        };
    List<Exception> errors = new ArrayList<Exception>();

    List<Item> results =
        extractor.extract(Arrays.asList(new File("DeutscheBankErtragsgutschrift2.txt")), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);

    // check security
    Security security =
        results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity();
    assertThat(security.getName(), is("ISHS-MSCI N. AMERIC.UCITS ETF BE.SH.(DT.ZT.)"));
    assertThat(security.getIsin(), is("DE000A0J2060"));
    assertThat(security.getWkn(), is("A0J206"));
    assertThat(security.getCurrencyCode(), is("USD"));

    // check transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));

    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDate(), is(LocalDate.parse("2015-03-24")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 16_17L)));
    assertThat(transaction.getShares(), is(Values.Share.factorize(123)));

    Optional<Unit> grossValue = transaction.getUnit(Unit.Type.GROSS_VALUE);
    assertThat(grossValue.isPresent(), is(true));
    assertThat(grossValue.get().getAmount(), is(Money.of("EUR", 16_17L)));
    assertThat(grossValue.get().getForex(), is(Money.of("USD", 17_38L)));
    assertThat(
        grossValue.get().getExchangeRate().doubleValue(), IsCloseTo.closeTo(0.930578, 0.000001));
  }
Esempio n. 4
0
  @Test
  public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
    LocalDate startDate = LocalDate.of(2012, 1, 1);
    LocalDate endDate = LocalDate.of(2012, 4, 29); // a weekend
    long startPrice = Values.Quote.factorize(100);

    Client client = new Client();

    Security security =
        new SecurityBuilder() //
            .generatePrices(startPrice, startDate, endDate) //
            .addTo(client);

    PortfolioBuilder portfolio = new PortfolioBuilder(new Account());

    // add some buy transactions
    LocalDate date = startDate;
    while (date.isBefore(endDate)) {
      long p = security.getSecurityPrice(date).getValue();
      portfolio.inbound_delivery(security, date, Values.Share.factorize(100), p);
      date = date.plusDays(20);
    }

    portfolio.addTo(client);

    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);

    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());

    double[] accumulated = index.getAccumulatedPercentage();
    long lastPrice = security.getSecurityPrice(endDate).getValue();

    assertThat(
        (double) (lastPrice - startPrice) / (double) startPrice,
        IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));

    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertThat(
        benchmark.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
  }
  @Test
  public void testErtragsgutschrift7_USD_Freibetrag_nicht_ausgeschoepft() throws IOException {
    ConsorsbankPDFExctractor extractor = new ConsorsbankPDFExctractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    URL url =
        FileLocator.resolve(
            getClass()
                .getResource(
                    "ConsorsbankErtragsgutschrift7_USD_Freibetrag_nicht_ausgeschoepft.pdf"));
    List<Item> results = extractor.extract(Arrays.asList(new File(url.getPath())), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(2));

    // check security
    Security security =
        results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity();
    assertThat(security.getWkn(), is("200417"));
    assertThat(security.getName(), is("ALTRIA GROUP INC."));

    // check dividend transaction
    AccountTransaction t =
        (AccountTransaction)
            results
                .stream()
                .filter(i -> i instanceof TransactionItem)
                .filter(
                    i ->
                        ((AccountTransaction) i.getSubject()).getType()
                            == AccountTransaction.Type.DIVIDENDS)
                .findFirst()
                .get()
                .getSubject();
    assertThat(t.getDate(), is(LocalDate.parse("2016-01-11")));
    assertThat(t.getShares(), is(Values.Share.factorize(650)));
    assertThat(t.getMonetaryAmount(), is(Money.of("EUR", 285_60)));
    assertThat(t.getUnit(Unit.Type.GROSS_VALUE).get().getForex(), is(Money.of("USD", 367_25)));

    // check tax
    assertThat(t.getUnitSum(Type.TAX), is(Money.of("EUR", 50_40))); // QUEST
  }
  @Test
  public void testWertpapierVerkauf2() throws IOException {
    DeutscheBankPDFExctractor extractor =
        new DeutscheBankPDFExctractor(new Client()) {
          @Override
          String strip(File file) throws IOException {
            return from("DeutscheBankVerkauf2.txt");
          }
        };
    List<Exception> errors = new ArrayList<Exception>();

    List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);

    assertSecurity(results);

    // check buy sell transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(BuySellEntry.class));
    BuySellEntry entry = (BuySellEntry) item.get().getSubject();

    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
    assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));

    assertThat(
        entry.getPortfolioTransaction().getMonetaryAmount(),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(453.66))));
    assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2015-01-30")));
    assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(8)));
    assertThat(
        entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
    assertThat(
        entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.90 + 0.60 + 2))));
  }
Esempio n. 7
0
  @Test
  public void testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency() {
    LocalDate startDate = LocalDate.of(2015, 1, 1);
    LocalDate endDate = LocalDate.of(2015, 8, 1);
    long startPrice = Values.Quote.factorize(100);

    Client client = new Client();

    Security security =
        new SecurityBuilder("USD") //
            .generatePrices(startPrice, startDate, endDate) //
            .addTo(client);

    new PortfolioBuilder() //
        .inbound_delivery(security, "2014-01-01", Values.Share.factorize(100), 100) //
        .addTo(client);

    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);

    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter().with(CurrencyUnit.EUR);

    ClientIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());

    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertTrue(warnings.isEmpty());
    assertThat(
        benchmark.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));

    PerformanceIndex investment =
        PerformanceIndex.forInvestment(client, converter, security, period, warnings);
    assertTrue(warnings.isEmpty());
    assertThat(
        investment.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
  }