Beispiel #1
0
  public static ClientSnapshot create(Client client, Date time) {
    ClientSnapshot snapshot = new ClientSnapshot(client, time);

    for (Account account : client.getAccounts())
      snapshot.accounts.add(AccountSnapshot.create(account, time));

    for (Portfolio portfolio : client.getPortfolios())
      snapshot.portfolios.add(PortfolioSnapshot.create(portfolio, time));

    if (snapshot.portfolios.isEmpty())
      snapshot.jointPortfolio = PortfolioSnapshot.create(new Portfolio(), time);
    else if (snapshot.portfolios.size() == 1) snapshot.jointPortfolio = snapshot.portfolios.get(0);
    else snapshot.jointPortfolio = PortfolioSnapshot.merge(snapshot.portfolios);

    return snapshot;
  }
  @Override
  public void notifyModelUpdated() {
    CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(getClient(), converter, LocalDate.now());

    assetViewer.setInput(snapshot);
    updateTitle();
  }
Beispiel #3
0
  public static ClientIRRYield create(
      Client client, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd) {
    Date start = snapshotStart.getTime();
    Date end = snapshotEnd.getTime();

    List<Transaction> transactions = new ArrayList<Transaction>();
    collectAccountTransactions(client, start, end, transactions);
    collectPortfolioTransactions(client, start, end, transactions);
    Collections.sort(transactions, new Transaction.ByDate());

    List<Date> dates = new ArrayList<Date>();
    List<Double> values = new ArrayList<Double>();

    collectDatesAndValues(start, end, snapshotStart, snapshotEnd, transactions, dates, values);

    double irr = IRR.calculate(dates, values);

    return new ClientIRRYield(snapshotStart, snapshotEnd, transactions, irr * 100);
  }
Beispiel #4
0
  private static void collectDatesAndValues(
      Date start,
      Date end,
      ClientSnapshot snapshotStart,
      ClientSnapshot snapshotEnd,
      List<Transaction> transactions,
      List<Date> dates,
      List<Double> values) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(start);
    dates.add(cal.getTime());
    values.add(-(snapshotStart.getAssets()) / Values.Amount.divider());

    for (Transaction t : transactions) {
      cal.setTime(t.getDate());
      dates.add(cal.getTime());

      if (t instanceof AccountTransaction) {
        AccountTransaction at = (AccountTransaction) t;
        long amount = at.getAmount();
        if (at.getType() == Type.DEPOSIT || at.getType() == Type.TRANSFER_IN) amount = -amount;
        values.add(amount / Values.Amount.divider());
      } else if (t instanceof PortfolioTransaction) {
        PortfolioTransaction pt = (PortfolioTransaction) t;

        long amount = pt.getAmount();
        if (pt.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND
            || pt.getType() == PortfolioTransaction.Type.TRANSFER_IN) amount = -amount;
        values.add(amount / Values.Amount.divider());
      } else {
        throw new UnsupportedOperationException();
      }
    }

    cal.setTime(end);
    dates.add(cal.getTime());
    values.add(snapshotEnd.getAssets() / Values.Amount.divider());
  }
  @Test
  public void testThatAccountTransactionsWithoutSecurity() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);

    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            null, //
            AccountTransaction.Type.BUY,
            1));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0).getAvailableFixes().get(0), is(DeleteTransactionFix.class));

    applyFixes(client, issues);

    ClientSnapshot.create(client, Dates.today());
  }
Beispiel #6
0
  public static ClientIRRYield create(Client client, Date start, Date end) {
    ClientSnapshot snapshotStart = ClientSnapshot.create(client, start);
    ClientSnapshot snapshotEnd = ClientSnapshot.create(client, end);

    return create(client, snapshotStart, snapshotEnd);
  }