コード例 #1
0
  private void updateActualProfit(
      final Map<String, Double> actualProfits, final Trader trader, final Transaction transaction) {
    double profit;
    if (actualProfits.containsKey(trader.getId())) {
      profit = (actualProfits.get(trader.getId())).doubleValue();
    } else {
      profit = 0;
    }

    profit +=
        Math.abs(trader.getPrivateValue() - transaction.getPrice()) * transaction.getQuantity();
    actualProfits.put(trader.getId(), new Double(profit));
  }
コード例 #2
0
  protected void calculateProfitDispersion() {
    // calculate actual profits of traders
    final Map<String, Double> actualProfits = new HashMap<String, Double>();
    if (transactions != null) {
      final Iterator<Transaction> i = transactions.iterator();
      while (i.hasNext()) {
        final Transaction transaction = i.next();
        updateActualProfit(actualProfits, transaction.getAsk().getTrader(), transaction);
        updateActualProfit(actualProfits, transaction.getBid().getTrader(), transaction);
      }
    }

    // calculate profit dispersion
    final CumulativeDistribution dist = new CumulativeDistribution();
    final Iterator<Trader> itor = traders.iterator();
    double theoProfit, actualProfit;
    while (itor.hasNext()) {
      final Trader trader = itor.next();
      if ((trader.isSeller() && (trader.getPrivateValue() <= equilibriumPrice))
          || (!trader.isSeller() && (trader.getPrivateValue() >= equilibriumPrice))) {
        theoProfit =
            Math.abs(trader.getPrivateValue() - equilibriumPrice) * trader.getEntitlement();
      } else {
        theoProfit = 0;
      }

      if (actualProfits.containsKey(trader.getId())) {
        actualProfit = actualProfits.get(trader.getId()).doubleValue();
      } else {
        actualProfit = 0;
      }

      dist.newData(Math.abs(theoProfit - actualProfit));
    }

    profitDispersion = dist.getStdDev(0);
  }