Example #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;
  }
  private static void addPseudoValuationTansactions(
      Portfolio portfolio,
      CurrencyConverter converter,
      ReportingPeriod period,
      Map<Security, SecurityPerformanceRecord> records) {
    PortfolioSnapshot snapshot =
        PortfolioSnapshot.create(portfolio, converter, period.getStartDate());
    for (SecurityPosition position : snapshot.getPositions()) {
      records
          .get(position.getSecurity())
          .addTransaction(new DividendInitialTransaction(position, period.getStartDate()));
    }

    snapshot = PortfolioSnapshot.create(portfolio, converter, period.getEndDate());
    for (SecurityPosition position : snapshot.getPositions()) {
      records
          .get(position.getSecurity())
          .addTransaction(new DividendFinalTransaction(position, period.getEndDate()));
    }
  }