diff --git a/data/sims/globalShock.csv b/data/sims/globalShock.csv new file mode 100644 index 0000000000000000000000000000000000000000..d338d39514f97d53485439c582de18c686363848 --- /dev/null +++ b/data/sims/globalShock.csv @@ -0,0 +1,11 @@ +Ensemble,Scenario,AGRI_LAND_EXPANSION_COST_FACTOR,ANNUAL_MAX_IMPORT_CHANGE,BIOENERGY_DEMAND_SHIFT,CROP_TO_PASTURE_COST_FACTOR,FERTILISER_COST_PER_T,INITIAL_PRICE_SHIFT,IRRIG_COST_SCALE_FACTOR,IRRIGATION_EFFICIENCY,LAND_CHANGE_COST,MARKET_LAMBA,MEAT_EFFICIENCY,MIN_NATURAL_RATE,OTHER_INTENSITY_COST,PASTURE_HARVEST_FRACTION,SSP_GDP_PC_FACTOR,SSP_POPULATION_FACTOR,SSP_SCENARIO,TECHNOLOGY_CHANGE_ANNUAL_RATE,TRADE_BARRIER_MULTIPLIER,TRANSPORT_COST,RCP,BIOENERGY_FUTURE_DEMAND_FILENAME,SHOCKS_POSSIBLE,YIELD_DIR_TOP,BIOENERGY_DEMAND_SCENARIO +shocks/noShocks,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,bioenergy_scenario_data.csv,FALSE,rcp45,SSP2_RCP45 +shocks/noShocks,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,bioenergy_scenario_data.csv,FALSE,rcp45,SSP2_RCP45 +shocks/noShocks,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,bioenergy_scenario_data.csv,FALSE,rcp45,SSP2_RCP45 +shocks/noShocks,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,bioenergy_scenario_data.csv,FALSE,rcp45,SSP2_RCP45 +shocks/noShocks,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,bioenergy_scenario_data.csv,FALSE,rcp45,SSP2_RCP45 +shocks/withShocks,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,bioenergy_scenario_data.csv,TRUE,rcp45,SSP2_RCP45 +shocks/withShocks,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,bioenergy_scenario_data.csv,TRUE,rcp45,SSP2_RCP45 +shocks/withShocks,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,bioenergy_scenario_data.csv,TRUE,rcp45,SSP2_RCP45 +shocks/withShocks,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,bioenergy_scenario_data.csv,TRUE,rcp45,SSP2_RCP45 +shocks/withShocks,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,bioenergy_scenario_data.csv,TRUE,rcp45,SSP2_RCP45 diff --git a/data/sims/globalShock_params.csv b/data/sims/globalShock_params.csv new file mode 100644 index 0000000000000000000000000000000000000000..f1329e3df9f7420244a1c1eb471343cbf1e19873 --- /dev/null +++ b/data/sims/globalShock_params.csv @@ -0,0 +1,51 @@ +Ensemble,pname,dist,xmin,xmax,x05,xmode,x95,value +noShocks,AGRI_LAND_EXPANSION_COST_FACTOR,beta,0,2,0.8,1,1.2, +noShocks,ANNUAL_MAX_IMPORT_CHANGE,beta,0.008,0.032,0.017,0.02,0.023, +noShocks,BIOENERGY_DEMAND_SHIFT,unif,0.9,1.1,,,, +noShocks,CROP_TO_PASTURE_COST_FACTOR,unif,0.8,1.2,,,, +noShocks,FERTILISER_COST_PER_T,beta,0.4,2.8,1.3,1.6,1.9, +noShocks,INITIAL_PRICE_SHIFT,unif,0.8,1.2,,,, +noShocks,IRRIG_COST_SCALE_FACTOR,beta,0.00005,0.00065,0.00025,0.00035,0.00045, +noShocks,IRRIGATION_EFFICIENCY,beta,0.4,0.6,0.48,0.5,0.52, +noShocks,LAND_CHANGE_COST,beta,0.05,0.35,0.175,0.2,0.225, +noShocks,MARKET_LAMBA,unif,0.3,0.5,,,, +noShocks,MEAT_EFFICIENCY,beta,0.95,1.05,0.99,1,1.01, +noShocks,MIN_NATURAL_RATE,beta,0,0.2,0.05,0.1,0.15, +noShocks,OTHER_INTENSITY_COST,beta,0.5,0.9,0.65,0.7,0.75, +noShocks,PASTURE_HARVEST_FRACTION,unif,0.4,0.6,,,, +noShocks,SSP_GDP_PC_FACTOR,unif,0.9,1.1,,,, +noShocks,SSP_POPULATION_FACTOR,unif,0.9,1.1,,,, +noShocks,SSP_SCENARIO,value,,,,,,SSP2_v9_130325 +noShocks,TECHNOLOGY_CHANGE_ANNUAL_RATE,beta,-0.004,0.008,0.001,0.002,0.003, +noShocks,TRADE_BARRIER_MULTIPLIER,beta,0,2,0.8,1,1.2, +noShocks,TRANSPORT_COST,beta,0.01,0.09,0.04,0.05,0.06, +noShocks,RCP,value,,,,,,rcp45 +noShocks,BIOENERGY_DEMAND_SCENARIO,value,,,,,,ssp2 +noShocks,YIELD_DIR_TOP,value,,,,,,ssp2 +noShocks,BIOENERGY_FUTURE_DEMAND_FILENAME,value,,,,,,bioenergy_scenario_data.csv +noShocks,SHOCKS_POSSIBLE,value,,,,,,FALSE +withShocks,AGRI_LAND_EXPANSION_COST_FACTOR,beta,0,2,0.8,1,1.2, +withShocks,ANNUAL_MAX_IMPORT_CHANGE,beta,0.008,0.032,0.017,0.02,0.023, +withShocks,BIOENERGY_DEMAND_SHIFT,unif,0.9,1.1,,,, +withShocks,CROP_TO_PASTURE_COST_FACTOR,unif,0.8,1.2,,,, +withShocks,FERTILISER_COST_PER_T,beta,0.4,2.8,1.3,1.6,1.9, +withShocks,INITIAL_PRICE_SHIFT,unif,0.8,1.2,,,, +withShocks,IRRIG_COST_SCALE_FACTOR,beta,0.00005,0.00065,0.00025,0.00035,0.00045, +withShocks,IRRIGATION_EFFICIENCY,beta,0.4,0.6,0.48,0.5,0.52, +withShocks,LAND_CHANGE_COST,beta,0.05,0.35,0.175,0.2,0.225, +withShocks,MARKET_LAMBA,unif,0.3,0.5,,,, +withShocks,MEAT_EFFICIENCY,beta,0.95,1.05,0.99,1,1.01, +withShocks,MIN_NATURAL_RATE,beta,0,0.2,0.05,0.1,0.15, +withShocks,OTHER_INTENSITY_COST,beta,0.5,0.9,0.65,0.7,0.75, +withShocks,PASTURE_HARVEST_FRACTION,unif,0.4,0.6,,,, +withShocks,SSP_GDP_PC_FACTOR,unif,0.9,1.1,,,, +withShocks,SSP_POPULATION_FACTOR,unif,0.9,1.1,,,, +withShocks,SSP_SCENARIO,value,,,,,,SSP2_v9_130325 +withShocks,TECHNOLOGY_CHANGE_ANNUAL_RATE,beta,-0.004,0.008,0.001,0.002,0.003, +withShocks,TRADE_BARRIER_MULTIPLIER,beta,0,2,0.8,1,1.2, +withShocks,TRANSPORT_COST,beta,0.01,0.09,0.04,0.05,0.06, +withShocks,RCP,value,,,,,,rcp45 +withShocks,BIOENERGY_DEMAND_SCENARIO,value,,,,,,ssp2 +withShocks,YIELD_DIR_TOP,value,,,,,,ssp2 +withShocks,BIOENERGY_FUTURE_DEMAND_FILENAME,value,,,,,,bioenergy_scenario_data.csv +withShocks,SHOCKS_POSSIBLE,value,,,,,,TRUE \ No newline at end of file diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 3b9a29836c2b0578584abeb0f70ea0dcdd145fa1..d0c23c3e9b94d4ba954796baa528046bdc6b527c 100755 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -402,4 +402,7 @@ public class ModelConfig { public static final int DIET_CHANGE_START_YEAR = getIntProperty("DIET_CHANGE_START_YEAR", 2020); public static final int DIET_CHANGE_END_YEAR = getIntProperty("DIET_CHANGE_END_YEAR", 2040); public static final String TARGET_DIET_FILE = getProperty("TARGET_DIET_FILE", DATA_DIR + File.separator + "TargetDiet.txt"); + public static final boolean APPLY_EXPORT_TAXES = getBooleanProperty("APPLY_EXPORT_TAXES", false); + public static final double EXPORT_TAX_RATE = getDoubleProperty("EXPORT_TAX_RATE", 1.0); + public static final double EXPORT_TAX_THRESHOLD = getDoubleProperty("EXPORT_TAX_THRESHOLD", 0.1); } diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 9c1d95dec0ac2bd9bbf5c6e8fdd3e6b5c12a3a3a..aae4fe71c5ec8e83c13ad0dfd5116cc49528c8fd 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -136,8 +136,7 @@ public class ModelMain { // loop for iterations. Could check within a tolerance using internationalMarket.findMaxPriceDiff, not doing so as doesn't find a solution due to inelastic consumption for (int i=0; i < ModelConfig.DEMAND_RECALC_MAX_ITERATIONS; i++) { LogWriter.println("\n++ Re-estimating prices and demand " + i); - countryAgents.recalculateDemandForAll(); // recalculate demand from new prices - countryAgents.updateNetImportsForAll(); // calculate imports and exports + countryAgents.recalculateDemandAndNetImportsForAll(); // recalculate demand from new prices and calculate imports and exports internationalMarket.determineInternationalTrade(countryAgents.getAll(), timestep); // calculate prices } internationalMarket.applyPriceShocks(timestep); diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index af808ca9a536e68e7d71be9b485f97aeb8b40843..6ce9ec3a9f9af9a3dc9095e17a422d25962e2547 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -22,6 +22,9 @@ public abstract class AbstractCountryAgent { protected Timestep currentTimestep; protected Map<CommodityType, Map<CropType, Double>> currentMinDemandFract; protected double currentGen2EcDemand; + private double exportTax; + private Map<CropType, Double> previousProducerCropPrices; + protected Map<CropType, Double> currentProducerCropPrices; public AbstractCountryAgent(AbstractDemandManager demandManager,CompositeCountry country, Map<CropType, Double> tradeBarriers) { @@ -47,13 +50,42 @@ public abstract class AbstractCountryAgent { GlobalPrice worldPrice = worldPrices.get(c); Double tb = tradeBarriers.get(c); LogWriter.println(worldPrice + " " + c); - CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), worldPrice.getExportPrice()); + double exportPrice = worldPrice.getExportPrice(); + exportPrice *= (1 - exportTax); + + CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), exportPrice); countryPrices.put(c, prices); } currentCountryPrices = countryPrices; } + protected void calculateProducerCropPrices() { + // save old prices so that comparison can be made after initial time step + previousProducerCropPrices = currentProducerCropPrices; + currentProducerCropPrices = getProducerCropPrices(); + } + + protected void calculateExportTax() { + exportTax = 0; + + if (previousProducerCropPrices != null) { + for (CropType crop : CommodityType.CEREALS.getCropTypes()) { + double newPrice = currentProducerCropPrices.get(crop); + double oldPrice = previousProducerCropPrices.get(crop); + if ((newPrice - oldPrice)/ oldPrice > ModelConfig.EXPORT_TAX_THRESHOLD) { + exportTax = ModelConfig.EXPORT_TAX_RATE; + LogWriter.println(String.format("calculateExportTax: Price Spike: %s: Price increased beyond threshold for %s, newPrice=%.4f, oldPrice=%.4f", country, crop, newPrice, oldPrice)); + break; + } + } + } + + LogWriter.println(String.format("calculateExportTax %s: exportTax is now %s", country, exportTax)); + } + + protected abstract Map<CropType, Double> getProducerCropPrices(); + private void calculateDemand(boolean outputGamsDemand) { Map<CommodityType, Double> producerPrices = getProducerCommodityPrices(); currentProjectedDemand = demandManager.getDemand(country, currentTimestep.getYear(), producerPrices, outputGamsDemand); @@ -62,6 +94,7 @@ public abstract class AbstractCountryAgent { protected void calculateCountryPricesAndDemand(Map<CropType, GlobalPrice> worldPrices, boolean outputGamsDemand) { calculateCountryPrices(worldPrices); + calculateProducerCropPrices(); calculateDemand(outputGamsDemand); } @@ -111,7 +144,8 @@ public abstract class AbstractCountryAgent { } protected void updateNetImportsFromProdAndDemand(Map<CommodityType, Double> demands, Map<CommodityType, Map<CropType, Double>> minDemandFracts, Map<CropType, CropUsageData> cropUsages) { - + LogWriter.println("AbstractCountryAgent: updateNetImportsFromProdAndDemand for " + country); + for (CommodityType commodity : CommodityType.getAllFoodItems()) { if (commodity != CommodityType.CEREALS && commodity != CommodityType.OILCROPSPULSES && commodity.getCropTypes().size() != 1) diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 1b9332868be9f39f1c93b0cb0acd46c16716e386..721d666386c13cbaadaec119970cc5d0bdf57453 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -107,6 +107,9 @@ public class CountryAgent extends AbstractCountryAgent { // project demand calculateCountryPricesAndDemand(worldPrices, false); + if (ModelConfig.APPLY_EXPORT_TAXES && !ModelConfig.IS_CALIBRATION_RUN) + calculateExportTax(); + if (saveGamsGdxFiles && ModelConfig.PRICE_ELASTIC_DEMAND) saveGDXFile("demand"); @@ -201,11 +204,23 @@ public class CountryAgent extends AbstractCountryAgent { protected double getCommPriceFromCropPrice(CommodityType commodity) { double commPricePlum = 0; Map<CropType, Double> demandFract = baseDemandFact.get(commodity); - Map<CropType, CropUsageData> cropUsageMap = previousGamsRasterOutput.getCropUsageData(); for (CropType crop : commodity.getCropTypes()) { - CropUsageData cropUsageData = cropUsageMap.get(crop); + double newCropPrice = currentProducerCropPrices.get(crop); + commPricePlum += newCropPrice * demandFract.get(crop); // weight price by base demand of each cereal crop + } + + return commPricePlum; + } + @Override + protected Map<CropType, Double> getProducerCropPrices() { + Map<CropType, Double> cropPrices = new HashMap<CropType, Double>(); + Map<CropType, CropUsageData> cropUsageMap = previousGamsRasterOutput.getCropUsageData(); + + for (CropType crop : CropType.getImportedTypes()) { + + CropUsageData cropUsageData = cropUsageMap.get(crop); double weighting = Math.max(0, cropUsageData.getShockedNetImports()/(cropUsageData.getProductionExpected()+cropUsageData.getNetImportsExpected())); double importPrice = currentCountryPrices.get(crop).getImportPrice(); @@ -231,11 +246,10 @@ public class CountryAgent extends AbstractCountryAgent { } LogWriter.println(String.format(" Crop %s: import %.4f, export %.4f, prodcost %.4f, newCropPrice %.4f", crop, importPrice, exportPrice, prodCost, newCropPrice)); - - commPricePlum += newCropPrice * demandFract.get(crop); // weight price by base demand of each cereal crop + cropPrices.put(crop, newCropPrice); } - return commPricePlum; + return cropPrices; } public void shockGDP() { diff --git a/src/ac/ed/lurg/country/CountryAgentManager.java b/src/ac/ed/lurg/country/CountryAgentManager.java index bd46adb8eae167d311917ed4c1914f81cb728045..7a9abf49361200c6dee2ad2169964464ef977309 100644 --- a/src/ac/ed/lurg/country/CountryAgentManager.java +++ b/src/ac/ed/lurg/country/CountryAgentManager.java @@ -128,17 +128,12 @@ public class CountryAgentManager { craftyManager.updateWithCraftyData(craftyCountryAgents, timestep, internationalMarket.getWorldPrices()); // this will wait for the marker file from CRAFTY } } - - public void updateNetImportsForAll() { - for (CountryAgent ca : gamsCountryAgents) { - ca.updateNetImportsFromProdAndDemand(); - } - } - public void recalculateDemandForAll() { + public void recalculateDemandAndNetImportsForAll() { for (CountryAgent ca : gamsCountryAgents) { ca.shockGDP(); ca.calculateCountryPricesAndDemand(internationalMarket.getWorldPrices(), true); + ca.updateNetImportsFromProdAndDemand(); } } @@ -166,9 +161,6 @@ public class CountryAgentManager { LogWriter.println("Serialized crop usage data is saved"); } catch (IOException i) { i.printStackTrace(); - } - - - } - + } + } } \ No newline at end of file diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index 3d6ca4450342788d7d6a30fdaa15e01e21ee29fd..1155495029b354f5bf0f2c80d73ece038ab59e8a 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -41,4 +41,10 @@ public class CraftyCountryAgent extends AbstractCountryAgent { } return commPricePlum; } + + @Override + protected Map<CropType, Double> getProducerCropPrices() { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/src/ac/ed/lurg/shock/parameterShocksReader.java b/src/ac/ed/lurg/shock/parameterShocksReader.java index 5a7629cd299b1e082b74f97241d01f9076571f6e..60ce2f9be37578f3c0a0eb2c1e4d6e5306114003 100644 --- a/src/ac/ed/lurg/shock/parameterShocksReader.java +++ b/src/ac/ed/lurg/shock/parameterShocksReader.java @@ -3,11 +3,8 @@ package ac.ed.lurg.shock; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; import ac.ed.lurg.utils.LogWriter;