diff --git a/data/global_stocks.csv b/data/global_stocks.csv index 69c06771186276afb2943d05d27c67aede01dff5..439a5d4764adc1a68131ed95de3bf2a2afb550cf 100644 --- a/data/global_stocks.csv +++ b/data/global_stocks.csv @@ -1,11 +1,12 @@ -plumCropItem,V1 -FruitVeg,182.092751337307 -WheatBarleyOats,879.537641313273 -Pulses,46.532195 -Starchy Roots,410.796684630225 -Oilcrops,378.961539547602 -MaizeMilletSorghum,810.753713560517 -Sugar,1484.01363920056 -Rice (Paddy Equivalent),439.184612481259 -Ruminants,412.1217514 -Monogastrics,45.6726812 +plumCropItem,V1 +FruitVeg,182.092751337307 +WheatBarleyOats,879.537641313273 +Pulses,46.532195 +Starchy Roots,410.796684630225 +Oilcrops,378.961539547602 +MaizeMilletSorghum,810.753713560517 +Sugar,1484.01363920056 +Rice (Paddy Equivalent),439.184612481259 +Ruminants,412.1217514 +Monogastrics,45.6726812 +Energy crops,20 \ No newline at end of file diff --git a/src/ac/ed/lurg/InternationalMarket.java b/src/ac/ed/lurg/InternationalMarket.java index 36e807fe416d177fd173493d97e7c7e17301fa14..d8e529197609f625248707c988a972098b063f70 100644 --- a/src/ac/ed/lurg/InternationalMarket.java +++ b/src/ac/ed/lurg/InternationalMarket.java @@ -69,7 +69,7 @@ public class InternationalMarket { GlobalPrice prevPrice = worldPrices.get(crop); double imports = totalImportCommodities.containsKey(crop) ? totalImportCommodities.get(crop) : 0.0; double exportsBeforeTransportLosses = totalExportCommodities.containsKey(crop) ? totalExportCommodities.get(crop) : 0.0; - LogWriter.print(timestep.getYear() + " Updating " + crop.getGamsName() + " prices : "); + LogWriter.println(timestep.getYear() + " Updating " + crop.getGamsName() + " prices"); GlobalPrice adjustedPrice = prevPrice.createWithUpdatedMarketPrices(imports, exportsBeforeTransportLosses, timestep, totalProduction.get(crop)); LogWriter.println( String.format("Price for %s updated from %s to %s \n", crop.getGamsName(), prevPrice, adjustedPrice)); worldPrices.put(crop, adjustedPrice); diff --git a/src/ac/ed/lurg/country/GlobalPrice.java b/src/ac/ed/lurg/country/GlobalPrice.java index 3848361056a0f5890b6f5c64e3d1c83c926fe2b7..310b1e4cd0b6fcdd7e6e48c7efcb1e34b9e774f3 100644 --- a/src/ac/ed/lurg/country/GlobalPrice.java +++ b/src/ac/ed/lurg/country/GlobalPrice.java @@ -67,50 +67,47 @@ public class GlobalPrice { public GlobalPrice createWithUpdatedMarketPrices(double newImports, double newExportAmountBeforeLoss, Timestep timestep, double production) { - double transportLossRate = (!ModelConfig.SHOCKS_POSSIBLE) ? ModelConfig.TRANSPORT_LOSSES : ModelConfig.getParameter(Parameter.TRANSPORT_LOSSES, timestep.getYear()); - double newTransportLosses = newExportAmountBeforeLoss * transportLossRate; - double exportsAfterTransportLosses = newExportAmountBeforeLoss - newTransportLosses; - - if (newImports > 0 || exportsAfterTransportLosses > 0) { - double oldDiff = 0; - if (timestep.getTimestep() == timestepId) // if recomputing for same year need to back our previous adjustment - oldDiff = exportAmountBeforeLoss - transportLosses - importAmount; - double newDiff = newExportAmountBeforeLoss - newTransportLosses - newImports; - double updatedStock = stockLevel + newDiff - oldDiff; - - LogWriter.println(String.format(" global stocks from %.2f to %.2f due to newDiff %.2f oldDiff %.2f", stockLevel, updatedStock, newDiff, oldDiff)); + if (newImports > 0 || newExportAmountBeforeLoss > 0) { + double oldDiff = timestep.getTimestep() != timestepId ? 0.0 : exportAmountBeforeLoss - transportLosses - importAmount; // if recomputing for same year need to back our previous adjustment + double transportLossRate = (!ModelConfig.SHOCKS_POSSIBLE) ? ModelConfig.TRANSPORT_LOSSES : ModelConfig.getParameter(Parameter.TRANSPORT_LOSSES, timestep.getYear()); + double newTransportLosses = newExportAmountBeforeLoss * transportLossRate; + double stockChange = newExportAmountBeforeLoss - newTransportLosses - newImports - oldDiff; + double updatedStock = stockLevel + stockChange; + + LogWriter.println(String.format(" imports %.2f, exports %.2f", newImports, newExportAmountBeforeLoss - newTransportLosses)); + LogWriter.println(String.format(" updatedStock %.2f, previous %.2f (last timestep %.2f), stockChange %.2f, oldDiff %.2f", updatedStock, stockLevel, stockLevel-oldDiff, stockChange, oldDiff)); if (updatedStock < 0) LogWriter.println(String.format("Global stocks are below zero")); - double newPrice, adjustment; + double adjustment; double financialSpeculationMultiplier = (!ModelConfig.SHOCKS_POSSIBLE)? 1.0 : ModelConfig.getParameter(Parameter.FINANCIAL_SPECULATION_MULTIPLIER,timestep.getYear()); if (!ModelConfig.MARKET_ADJ_PRICE) { adjustment = 1; } else if (ModelConfig.PRICE_UPDATE_BY_MARKET_IMBALANCE) { - double ratio = (newImports-exportsAfterTransportLosses)/(newImports-exportsAfterTransportLosses+production); - adjustment = Math.exp(ratio * ModelConfig.MARKET_LAMBA); - LogWriter.println(String.format("Price update market imbalance: adjustment= %.4f, imports %.1f, exports %.1f", adjustment, newImports, getExportsAfterTransportLosses())); + double ratio = stockChange/(production-stockChange); + adjustment = Math.exp(-ratio * ModelConfig.MARKET_LAMBA); + LogWriter.println(String.format(" initally imbalance ratio= %.4f", ratio)); } else { - double ratio = (stockTarget - updatedStock) / stockTarget; - - if (ratio >= 0) { - adjustment = 1 + ModelConfig.MARKET_LAMBA * ratio/(1 - ratio*ratio); - if (adjustment > ModelConfig.MAX_PRICE_INCREASE || ratio > 1) - adjustment = ModelConfig.MAX_PRICE_INCREASE; // default to max up change - } - else { - adjustment = 1 / ( 1 - ModelConfig.MARKET_LAMBA * ratio/(1 - ratio*ratio)); - if (adjustment < ModelConfig.MAX_PRICE_DECREASE || ratio < -1) - adjustment = ModelConfig.MAX_PRICE_DECREASE; // default to max down change - } + if (stockChange >= 0) // stock increasing, so decrease price. stockChange is positive so adjustment < 1 + adjustment = 1 - ModelConfig.MARKET_LAMBA * stockChange/production; + else // stock decreasing, so increase price. stockChange is negative so adjustment > 1 + adjustment = 1 - ModelConfig.MARKET_LAMBA * stockChange/Math.max(0, stockLevel); - LogWriter.println(String.format("Price update from stock target: adjustment= %.4f, ratio= %.4f", adjustment, ratio)); + LogWriter.print(String.format(" initally adjustment= %.4f", adjustment)); } - newPrice = exportPrice * adjustment * financialSpeculationMultiplier; + if (adjustment < ModelConfig.MAX_PRICE_DECREASE) + adjustment = ModelConfig.MAX_PRICE_DECREASE; // default to max down change + + if (adjustment > ModelConfig.MAX_PRICE_INCREASE) + adjustment = ModelConfig.MAX_PRICE_INCREASE; // default to max up change + + LogWriter.println(String.format(", after limit %.4f", adjustment)); + + double newPrice = exportPrice * adjustment * financialSpeculationMultiplier; return new GlobalPrice(timestep.getTimestep(), newPrice, updatedStock, stockTarget, newImports, newExportAmountBeforeLoss, newTransportLosses); } else { @@ -127,5 +124,4 @@ public class GlobalPrice { public double getStockChange() { return exportAmountBeforeLoss - transportLosses - importAmount; } -} - +} \ No newline at end of file