EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
MarketStabilityReserveRole.java
1 /*******************************************************************************
2  * Copyright 2013 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.role.co2policy;
17 
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.data.annotation.Transient;
20 import org.springframework.data.neo4j.support.Neo4jTemplate;
21 import org.springframework.transaction.annotation.Transactional;
22 
23 import agentspring.role.AbstractRole;
24 import agentspring.role.RoleComponent;
28 
33 @RoleComponent
34 public class MarketStabilityReserveRole extends AbstractRole<Government> {
35 
36  @Transient
37  @Autowired
38  Reps reps;
39 
40  @Transient
41  @Autowired
42  StrategicReserveOperatorRepository strategicReserveOperatorRepository;
43 
44  @Autowired
45  Neo4jTemplate template;
46 
47  @Transactional
48  public void act(Government government) {
49  double allowancesInCirculation = reps.decarbonizationAgentRepository.determinePreviouslyBankedCO2Certificates();
50  double inflowToMarketReserve = calculateInflowToMarketReserveForTimeStep(getCurrentTick(),
51  allowancesInCirculation, government);
52  government.setStabilityReserve(government.getStabilityReserve() + inflowToMarketReserve);
53  government.getCo2CapTrend().setValue(getCurrentTick(),
54  government.getCo2CapTrend().getValue(getCurrentTick()) - inflowToMarketReserve);
55  }
56 
57  public double calculateInflowToMarketReserveForTimeStep(long clearingTick, double bankedCertificatesInTick,
58  Government government) {
59  double allowancesInCirculation = bankedCertificatesInTick;
60  if (allowancesInCirculation > government.getStabilityReserveUpperTriggerTrend().getValue(clearingTick)) {
61  double allowancesToBeAddedToReserve = Math.max(
62  allowancesInCirculation
63  * government.getStabilityReserveAddingPercentageTrend().getValue(clearingTick),
64  government
65  .getStabilityReserveAddingMinimumTrend().getValue(clearingTick));
66  return allowancesToBeAddedToReserve;
67  } else if (allowancesInCirculation < government.getStabilityReserveLowerTriggerTrend().getValue(clearingTick)) {
68  double allowancesToBeReleased = Math.min(government.getStabilityReserve(),
69  government
70  .getStabilityReserveReleaseQuantityTrend().getValue(clearingTick));
71  return -allowancesToBeReleased;
72  }
73  return 0;
74  }
75 }