Skip to content

Commit

Permalink
Enlarged interface ClimateModel to provide abatement and damage costs
Browse files Browse the repository at this point in the history
  • Loading branch information
cfries committed Sep 22, 2023
1 parent 8b03189 commit 1c92fde
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>net.finmath</groupId>
<artifactId>finmath-lib</artifactId>
<version>6.0.15-SNAPSHOT</version>
<version>6.0.16-SNAPSHOT</version>
<packaging>jar</packaging>

<name>finmath lib</name>
Expand Down Expand Up @@ -664,7 +664,7 @@
<url>https://github.com/finmath/finmath-lib</url>
<connection>scm:git:https://github.com/finmath/finmath-lib.git</connection>
<developerConnection>scm:git:https://github.com/finmath/finmath-lib.git</developerConnection>
<tag>HEAD</tag>
<tag>finmath-lib-6.0.15</tag>
</scm>

<ciManagement>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/finmath/climate/models/AbatementModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.finmath.climate.models;

import java.util.function.Function;

import net.finmath.stochastic.RandomVariable;

public interface AbatementModel extends Function<Double, RandomVariable> {

}
30 changes: 27 additions & 3 deletions src/main/java/net/finmath/climate/models/ClimateModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.finmath.climate.models;

import java.util.function.Function;

import net.finmath.stochastic.RandomVariable;
import net.finmath.time.TimeDiscretization;

Expand All @@ -25,14 +27,19 @@ public interface ClimateModel {
RandomVariable getTemperature(double time);

/**
* The value (scenario vector) (discounted)
* The aggregated (discounted) value.
*
* @return The value (scenario vector).
* @return The value (scenario wise).
*/
RandomVariable getValue();

/**
* The random vector of un-discounted values (utilities).
*
* @return random vector of un-discounted values (utilities).
*/
RandomVariable[] getValues();

RandomVariable[] getAbatement();

RandomVariable[] getEmission();
Expand All @@ -44,4 +51,21 @@ public interface ClimateModel {
RandomVariable[] getDamage();

RandomVariable[] getGDP();

RandomVariable[] getConsumptions();

RandomVariable[] getAbatementCosts();

RandomVariable getAbatementCost();

RandomVariable[] getDamageCosts();

RandomVariable getDamageCost();

RandomVariable getNumeraire(double time);

Function<Double, RandomVariable> getAbatementModel();

Function<Double, RandomVariable> getSavingsRateModel();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.finmath.climate.models;

import java.util.function.Function;

import net.finmath.stochastic.RandomVariable;

public interface SavingsRateModel extends Function<Double, RandomVariable> {

}
64 changes: 62 additions & 2 deletions src/main/java/net/finmath/climate/models/dice/DICEModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.function.UnaryOperator;
import java.util.logging.Logger;

import net.finmath.climate.models.AbatementModel;
import net.finmath.climate.models.ClimateModel;
import net.finmath.climate.models.SavingsRateModel;
import net.finmath.climate.models.dice.submodels.AbatementCostFunction;
import net.finmath.climate.models.dice.submodels.CarbonConcentration3DScalar;
import net.finmath.climate.models.dice.submodels.DamageFromTemperature;
Expand Down Expand Up @@ -53,10 +55,13 @@ public class DICEModel implements ClimateModel {
private double[] gdp;
private double[] emission;
private double[] abatement;
private double[] abatementCosts;
private double[] damage;
private double[] damageCosts;
private double[] capital;
private double[] population;
private double[] productivity;
private double[] consumptions;
private double[] welfare;
private double[] value;

Expand All @@ -83,10 +88,13 @@ public DICEModel(TimeDiscretization timeDiscretization, UnaryOperator<Double> ab
gdp = new double[numberOfTimes];
emission = new double[numberOfTimes];
abatement = new double[numberOfTimes];
abatementCosts = new double[numberOfTimes];
damage = new double[numberOfTimes];
damageCosts = new double[numberOfTimes];
capital = new double[numberOfTimes];
population = new double[numberOfTimes];
productivity = new double[numberOfTimes];
consumptions = new double[numberOfTimes];
welfare = new double[numberOfTimes];
value = new double[numberOfTimes];

Expand Down Expand Up @@ -210,7 +218,10 @@ private void init(Map<String, Object> modelProperties) {
damage[timeIndex] = damageFunction.applyAsDouble(temperature[timeIndex].getExpectedTemperatureOfAtmosphere());

double damageCostAbsolute = damage[timeIndex] * gdp[timeIndex];
damageCosts[timeIndex] = damageCostAbsolute;

double abatementCostAbsolute = abatementCostFunction.apply(time, abatement[timeIndex]) * emissionIndustrial;
abatementCosts[timeIndex] = abatementCostAbsolute;

/*
* Evolve economy i -> i+1 (as a function of temperature[i])
Expand All @@ -235,10 +246,11 @@ private void init(Map<String, Object> modelProperties) {

double consumption = (1-savingsRate) * gdpNet;
double investment = savingsRate * gdpNet;

// Allow for an external shift to the emissions (e.g. to calculate SCC).
consumption += isTimeIndexToShift.test(timeIndex) ? initialConsumptionShift : 0.0;

consumptions[timeIndex] = consumption;

capital[timeIndex+1] = evolutionOfCapital.apply(timeIndex).apply(capital[timeIndex], investment);

/*
Expand Down Expand Up @@ -318,4 +330,52 @@ public RandomVariable[] getDamage() {
public RandomVariable[] getGDP() {
return Arrays.stream(gdp).mapToObj(Scalar::of).toArray(RandomVariable[]::new);
}

@Override
public RandomVariable[] getConsumptions() {
return Arrays.stream(consumptions).mapToObj(Scalar::of).toArray(RandomVariable[]::new);
}

@Override
public RandomVariable[] getAbatementCosts() {
return Arrays.stream(abatementCosts).mapToObj(Scalar::of).toArray(RandomVariable[]::new);
}

@Override
public RandomVariable getAbatementCost() {
double abatementCost = 0.0;
for(int timeIndex = 0; timeIndex < timeDiscretization.getNumberOfTimes(); timeIndex++) {
abatementCost += abatementCosts[timeIndex] * Math.exp(- discountRate * timeDiscretization.getTime(timeIndex));
}
return Scalar.of(abatementCost);
}

@Override
public RandomVariable[] getDamageCosts() {
return Arrays.stream(damageCosts).mapToObj(Scalar::of).toArray(RandomVariable[]::new);
}

@Override
public RandomVariable getDamageCost() {
double damageCost = 0.0;
for(int timeIndex = 0; timeIndex < timeDiscretization.getNumberOfTimes(); timeIndex++) {
damageCost += damageCosts[timeIndex] * Math.exp(- discountRate * timeDiscretization.getTime(timeIndex));
}
return Scalar.of(damageCost);
}

@Override
public RandomVariable getNumeraire(double time) {
return Scalar.of(Math.exp(- discountRate * time));
}

@Override
public AbatementModel getAbatementModel() {
return (AbatementModel)abatementFunction.andThen(Scalar::new).andThen(RandomVariable.class::cast);
}

@Override
public SavingsRateModel getSavingsRateModel() {
return (SavingsRateModel)savingsRateFunction.andThen(Scalar::new).andThen(RandomVariable.class::cast);
}
}

0 comments on commit 1c92fde

Please sign in to comment.