Пример #1
0
  public Map<InvestmentVehicle, AssetPosition> getPositionsByVehicle() {
    Map<InvestmentVehicle, AssetPosition> answer = new HashMap<InvestmentVehicle, AssetPosition>();

    long assets = getAssets();

    for (SecurityPosition p : jointPortfolio.getPositions())
      answer.put(p.getSecurity(), new AssetPosition(p.getSecurity(), p, assets));

    for (AccountSnapshot a : accounts) {
      SecurityPosition sp = new SecurityPosition(null);
      sp.setShares(Values.Share.factor());
      sp.setPrice(new SecurityPrice(getTime(), a.getFunds()));
      answer.put(a.getAccount(), new AssetPosition(a.getAccount(), sp, assets));
    }
    return answer;
  }
Пример #2
0
  public static PortfolioSnapshot merge(List<PortfolioSnapshot> snapshots) {
    if (snapshots.isEmpty())
      throw new RuntimeException(
          "Error: PortfolioSnapshots to be merged must not be empty"); //$NON-NLS-1$

    Portfolio portfolio = new Portfolio();
    portfolio.setName(Messages.LabelJointPortfolio);

    Map<Security, SecurityPosition> securities = new HashMap<Security, SecurityPosition>();
    for (PortfolioSnapshot s : snapshots) {
      portfolio.addAllTransaction(s.getSource().getTransactions());
      for (SecurityPosition p : s.getPositions()) {
        SecurityPosition pos = securities.get(p.getSecurity());
        if (pos == null) securities.put(p.getSecurity(), p);
        else securities.put(p.getSecurity(), SecurityPosition.merge(pos, p));
      }
    }

    return new PortfolioSnapshot(
        portfolio,
        snapshots.get(0).getTime(),
        new ArrayList<SecurityPosition>(securities.values()));
  }
Пример #3
0
  public static PortfolioSnapshot create(Portfolio portfolio, Date time) {
    Map<Security, SecurityPosition> positions = new HashMap<Security, SecurityPosition>();

    for (PortfolioTransaction t : portfolio.getTransactions()) {
      if (t.getDate().getTime() <= time.getTime()) {
        switch (t.getType()) {
          case TRANSFER_IN:
          case BUY:
          case DELIVERY_INBOUND:
            {
              SecurityPosition p = positions.get(t.getSecurity());
              if (p == null)
                positions.put(t.getSecurity(), p = new SecurityPosition(t.getSecurity()));
              p.addTransaction(t);
              break;
            }
          case TRANSFER_OUT:
          case SELL:
          case DELIVERY_OUTBOUND:
            {
              SecurityPosition p = positions.get(t.getSecurity());
              if (p == null)
                positions.put(t.getSecurity(), p = new SecurityPosition(t.getSecurity()));
              p.addTransaction(t);
              break;
            }
          default:
            throw new UnsupportedOperationException(
                "Unsupported operation: " + t.getType()); // $NON-NLS-1$
        }
      }
    }

    ArrayList<SecurityPosition> collection = new ArrayList<SecurityPosition>(positions.values());
    for (Iterator<SecurityPosition> iter = collection.iterator(); iter.hasNext(); ) {
      SecurityPosition p = iter.next();

      if (p.getShares() == 0) {
        iter.remove();
      } else {
        SecurityPrice price = p.getSecurity().getSecurityPrice(time);
        p.setPrice(price);
      }
    }

    return new PortfolioSnapshot(portfolio, time, collection);
  }
Пример #4
0
 public Map<Security, SecurityPosition> getPositionsBySecurity() {
   Map<Security, SecurityPosition> map = new HashMap<Security, SecurityPosition>();
   for (SecurityPosition p : positions) map.put(p.getSecurity(), p);
   return map;
 }