public String getColumnText(Object element, int columnIndex) {
      TransactionPair<?> pair = (TransactionPair<?>) element;
      Transaction t = pair.getTransaction();

      switch (columnIndex) {
        case 0:
          return Values.Date.format(t.getDate());
        case 1:
          if (t instanceof AccountTransaction) return ((AccountTransaction) t).getType().toString();
          else if (t instanceof PortfolioTransaction)
            return ((PortfolioTransaction) t).getType().toString();
          return null;
        case 2:
          return Values.Share.format(t.getShares());
        case 3:
          if (model.isChangeTransactions() && t.getDate().before(model.getExDate())) {
            long shares = t.getShares() * model.getNewShares() / model.getOldShares();
            return Values.Share.format(shares);
          }
          return null;
        case 4:
          return pair.getOwner().toString();
        default:
          return null;
      }
    }
Пример #2
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;
  }
Пример #3
0
  private void updateChart(Security security) {
    ISeries series = chart.getSeriesSet().getSeries(Messages.ColumnQuote);
    if (series != null) chart.getSeriesSet().deleteSeries(Messages.ColumnQuote);
    chart.clearMarkerLines();

    if (security == null || security.getPrices().isEmpty()) {
      chart.getTitle().setText(security == null ? "..." : security.getName()); // $NON-NLS-1$
      chart.redraw();
      return;
    }

    chart.getTitle().setText(security.getName());

    List<SecurityPrice> prices = security.getPrices();

    int index;
    Date[] dates;
    double[] values;

    if (chartPeriod == null) {
      index = 0;
      dates = new Date[prices.size()];
      values = new double[prices.size()];
    } else {
      index =
          Math.abs(
              Collections.binarySearch(
                  prices, new SecurityPrice(chartPeriod, 0), new SecurityPrice.ByDate()));

      if (index >= prices.size()) {
        // no data available
        chart.redraw();
        return;
      }

      dates = new Date[prices.size() - index];
      values = new double[prices.size() - index];
    }

    for (int ii = 0; index < prices.size(); index++, ii++) {
      SecurityPrice p = prices.get(index);
      dates[ii] = p.getTime();
      values[ii] = p.getValue() / Values.Quote.divider();
    }

    ILineSeries lineSeries =
        (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, Messages.ColumnQuote);
    lineSeries.setXDateSeries(dates);
    lineSeries.setLineWidth(2);
    lineSeries.enableArea(true);
    lineSeries.setSymbolType(PlotSymbolType.NONE);
    lineSeries.setYSeries(values);
    lineSeries.setAntialias(SWT.ON);

    chart.getAxisSet().adjustRange();

    for (Portfolio portfolio : getClient().getPortfolios()) {
      for (PortfolioTransaction t : portfolio.getTransactions()) {
        if (t.getSecurity() == security
            && (chartPeriod == null || chartPeriod.before(t.getDate()))) {
          String label = Values.Share.format(t.getShares());
          switch (t.getType()) {
            case BUY:
            case TRANSFER_IN:
            case DELIVERY_INBOUND:
              chart.addMarkerLine(t.getDate(), new RGB(0, 128, 0), label);
              break;
            case SELL:
            case TRANSFER_OUT:
            case DELIVERY_OUTBOUND:
              chart.addMarkerLine(t.getDate(), new RGB(128, 0, 0), "-" + label); // $NON-NLS-1$
              break;
            default:
              throw new UnsupportedOperationException();
          }
        }
      }
    }

    chart.redraw();
  }