/* (non-Javadoc)
  * @see jmab.strategies.DividendsStrategy#payDividends()
  */
 @Override
 public void payDividends() {
   MacroAgent dividendPayer = (MacroAgent) this.agent;
   double profits = dividendPayer.getPassedValue(profitsLagId, 0);
   if (profits > 0) {
     Population receivers =
         ((MacroPopulation) ((SimulationController) this.scheduler).getPopulation())
             .getPopulation(receiversId);
     double totalNW = 0;
     for (Agent receiver : receivers.getAgents()) {
       totalNW += ((MacroAgent) receiver).getNetWealth();
     }
     if (dividendPayer instanceof Bank) {
       Deposit payerDep = (Deposit) dividendPayer.getItemStockMatrix(true, reservesId);
       // if(profits>payerDep.getValue()){
       // profits=payerDep.getValue();
       // }
       Bank bank = (Bank) dividendPayer;
       bank.setDividends(profits * profitShare);
       for (Agent rec : receivers.getAgents()) {
         Households receiver = (Households) rec;
         double nw = receiver.getNetWealth();
         Deposit recDep = (Deposit) receiver.getItemStockMatrix(true, depositId);
         double toPay = profits * profitShare * nw / totalNW;
         recDep.setValue(recDep.getValue() + toPay);
         payerDep.setValue(payerDep.getValue() - toPay);
         Deposit otherBankReserves =
             (Deposit) ((Bank) recDep.getLiabilityHolder()).getItemStockMatrix(true, reservesId);
         otherBankReserves.setValue(otherBankReserves.getValue() + toPay);
         receiver.setDividendsReceived(receiver.getDividendsReceived() + toPay);
       }
     } else {
       if (dividendPayer.getItemStockMatrix(true, depositId).getValue() > profits * profitShare) {
         Deposit payerDep = (Deposit) dividendPayer.getItemStockMatrix(true, depositId);
         if (profits > payerDep.getValue()) {
           profits = payerDep.getValue();
         }
         AbstractFirm firm = (AbstractFirm) dividendPayer;
         firm.setDividends(profits * profitShare);
         for (Agent rec : receivers.getAgents()) {
           Households receiver = (Households) rec;
           double nw = receiver.getNetWealth();
           double toPay = profits * profitShare * nw / totalNW;
           Deposit recDep = (Deposit) receiver.getItemStockMatrix(true, depositId);
           ((Bank) payerDep.getLiabilityHolder()).transfer(payerDep, recDep, toPay);
           receiver.setDividendsReceived(receiver.getDividendsReceived() + toPay);
         }
       }
     }
   }
 }
Esempio n. 2
0
 /* (non-Javadoc)
  * @see jmab.report.VariableComputer#computeVariable(jmab.simulations.MacroSimulation)
  */
 @Override
 public double computeVariable(MacroSimulation sim) {
   MacroPopulation macroPop = (MacroPopulation) sim.getPopulation();
   double investments = 0;
   for (int i = 0; i < investorsPopIds.length; i++) {
     Population pop = macroPop.getPopulation(investorsPopIds[i]);
     for (Agent j : pop.getAgents()) {
       MacroAgent agent = (MacroAgent) j;
       if (!agent.isDead()) {
         for (int h = 0; h < capitalSMIds.length; h++) {
           List<Item> items = agent.getItemsStockMatrix(true, capitalSMIds[h]);
           for (Item item : items) {
             if (item.getAge() < 0) {
               investments += item.getValue();
             }
           }
         }
       }
     }
   }
   return investments;
 }