16 package emlab.gen.role.investment;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.beans.factory.annotation.Configurable;
20 import org.springframework.data.annotation.Transient;
21 import org.springframework.data.neo4j.annotation.NodeEntity;
22 import org.springframework.transaction.annotation.Transactional;
60 .getPowerGeneratingTechnologyPercentageOfYearlyTargetFulfillments()) {
61 if(tgtFulfillment.getPowerGeneratingTechnology().getName().equals(pgt.getName()))
62 targetFulfillment = tgtFulfillment;
65 PowerGridNode installationNode = targetInvestor.getSpecificPowerGridNode();
67 if (installationNode == null)
68 reps.powerGeneratingTechnologyNodeLimitRepository.findOneByTechnologyAndMarket(pgt,
69 targetInvestor.getInvestorMarket());
71 long futureTimePoint = getCurrentTick()+pgt.getExpectedLeadtime()+pgt.getExpectedPermittime();
72 double expectedInstalledCapacity = reps.powerPlantRepository.calculateCapacityOfExpectedOperationalPowerPlantsInMarketAndTechnology(targetInvestor.getInvestorMarket(), pgt, futureTimePoint);
73 double pgtNodeLimit = Double.MAX_VALUE;
77 .findOneByTechnologyAndNode(pgt, installationNode);
78 if (pgtLimit != null) {
79 pgtNodeLimit = pgtLimit.getUpperCapacityLimit(futureTimePoint);
84 double expectedDismantledPowerPlantCapacityOfTechnologyAndOwner = reps.powerPlantRepository
85 .calculateCapacityOfExpectedDismantledPowerPlantsByOwnerByTechnology(futureTimePoint, targetInvestor, pgt);
86 double targetInstallationDelta = (target.getTrend().getValue(futureTimePoint) - target.getTrend().getValue(
88 + expectedDismantledPowerPlantCapacityOfTechnologyAndOwner;
93 targetInstallationDelta = targetInstallationDelta * targetFulfillment.getTrend().getValue(futureTimePoint);
96 double installedCapacityDeviation = 0;
97 if (pgtNodeLimit > expectedInstalledCapacity + targetInstallationDelta) {
98 installedCapacityDeviation = targetInstallationDelta;
100 installedCapacityDeviation = pgtNodeLimit - expectedInstalledCapacity;
103 if (installedCapacityDeviation > 0) {
105 double powerPlantCapacityRatio = installedCapacityDeviation/pgt.getCapacity();
108 plant.specifyNotPersist(getCurrentTick(), targetInvestor, installationNode, pgt);
109 plant.setActualNominalCapacity(pgt.getCapacity()*powerPlantCapacityRatio);
111 BigBank bigbank = reps.genericRepository.findFirst(BigBank.class);
113 double investmentCostPayedByEquity = plant.getActualInvestedCapital() * (1 - targetInvestor.getDebtRatioOfInvestments())*powerPlantCapacityRatio;
114 double investmentCostPayedByDebt = plant.getActualInvestedCapital() * targetInvestor.getDebtRatioOfInvestments()*powerPlantCapacityRatio;
115 double downPayment = investmentCostPayedByEquity;
116 createSpreadOutDownPayments(targetInvestor, manufacturer, downPayment, plant);
118 double amount = determineLoanAnnuities(investmentCostPayedByDebt, plant.getTechnology().getDepreciationTime(),
119 targetInvestor.getLoanInterestRate());
121 Loan loan = reps.loanRepository.createLoan(targetInvestor, bigbank, amount, plant.getTechnology().getDepreciationTime(),
122 getCurrentTick(), plant);
124 plant.createOrUpdateLoan(loan);
133 int buildingTime = (int) plant.getActualLeadtime();
134 for (
int i = 0; i < buildingTime; i++) {
135 reps.nonTransactionalCreateRepository.createCashFlow(agent, manufacturer, totalDownPayment / buildingTime,
136 CashFlow.DOWNPAYMENT, getCurrentTick() + i, plant);
141 public double determineLoanAnnuities(
double totalLoan,
double payBackTime,
double interestRate) {
143 double q = 1 + interestRate;
144 double annuity = totalLoan * (Math.pow(q, payBackTime) * (q - 1)) / (Math.pow(q, payBackTime) - 1);