Class MonteCarloRunner
java.lang.Object
neqsim.process.fielddevelopment.evaluation.MonteCarloRunner
- All Implemented Interfaces:
Serializable
Monte Carlo simulation runner for uncertainty quantification in field development.
Supports various probability distributions (triangular, normal, lognormal, uniform) and integrates with CashFlowEngine for economic uncertainty analysis. Typical use cases include:
- CAPEX/OPEX uncertainty analysis
- Oil price sensitivity
- Production rate uncertainty
- NPV risk assessment (P10, P50, P90)
Example usage:
MonteCarloRunner mc = new MonteCarloRunner(cashFlowEngine);
mc.addVariable("oilPrice", DistributionType.TRIANGULAR, 50.0, 70.0, 120.0);
mc.addVariable("capex", DistributionType.NORMAL, 500.0, 75.0);
mc.setIterations(10000);
mc.run();
double p10 = mc.getPercentile("npv", 10);
double p50 = mc.getPercentile("npv", 50);
double p90 = mc.getPercentile("npv", 90);
- Version:
- 1.0
- Author:
- AGAS
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumProbability distribution types supported by the Monte Carlo runner.static classResults from a single Monte Carlo iteration.static classDefinition of an uncertain variable. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CashFlowEngineCash flow engine for economic calculations.private doubleDiscount rate for NPV calculation.private intNumber of Monte Carlo iterations.private static final org.apache.logging.log4j.LoggerLogger instance.private RandomRandom number generator.private List<MonteCarloRunner.IterationResult> Results from all iterations.private static final longSerial version UID.private List<MonteCarloRunner.UncertainVariable> List of uncertain variables. -
Constructor Summary
ConstructorsConstructorDescriptionMonteCarloRunner(CashFlowEngine engine) Creates a new Monte Carlo runner.MonteCarloRunner(CashFlowEngine engine, long seed) Creates a new Monte Carlo runner with specified seed for reproducibility. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLognormal(String name, double meanOfLog, double stdDevOfLog) Add an uncertain variable with lognormal distribution.voidAdd an uncertain variable with normal distribution.voidaddTriangular(String name, double min, double mode, double max) Add an uncertain variable with triangular distribution.voidaddUniform(String name, double min, double max) Add an uncertain variable with uniform distribution.voidaddVariable(String name, MonteCarloRunner.DistributionType distribution, double param1, double param2, double param3) Add an uncertain variable with specified distribution.private voidapplyVariable(String name, double value) Apply a sampled variable value to the cash flow engine.Generate a summary report of the Monte Carlo results.intGet number of converged iterations.doubleGet discount rate.intGet number of iterations.doubleGet mean value for a metric.private doublegetMetricValue(MonteCarloRunner.IterationResult result, String metric) Get metric value from an iteration result.doubleGet the P10 value (10th percentile - low case).doubleGet the P50 value (50th percentile - base case).doubleGet the P90 value (90th percentile - high case).doublegetPercentile(String metric, double percentile) Get the percentile value for a result metric.doublegetProbabilityNpvExceeds(double threshold) Get the probability that NPV exceeds a threshold.doubleGet the probability of positive NPV.Get all iteration results.doubleGet standard deviation for a metric.booleanrun()Run the Monte Carlo simulation.private doubleSample a value from the specified distribution.private doublesampleLognormal(double meanOfLog, double stdDevOfLog) Sample from lognormal distribution.private doublesampleNormal(double mean, double stdDev) Sample from normal distribution.private doublesampleTriangular(double min, double mode, double max) Sample from triangular distribution.private doublesampleUniform(double min, double max) Sample from uniform distribution.voidsetDiscountRate(double rate) Set discount rate for NPV calculations.voidsetIterations(int iterations) Set number of Monte Carlo iterations.voidsetSeed(long seed) Set random seed for reproducibility.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial version UID.- See Also:
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger instance. -
cashFlowEngine
Cash flow engine for economic calculations. -
variables
List of uncertain variables. -
results
Results from all iterations. -
iterations
private int iterationsNumber of Monte Carlo iterations. -
random
Random number generator. -
discountRate
private double discountRateDiscount rate for NPV calculation.
-
-
Constructor Details
-
MonteCarloRunner
Creates a new Monte Carlo runner.- Parameters:
engine- cash flow engine for economic calculations
-
MonteCarloRunner
Creates a new Monte Carlo runner with specified seed for reproducibility.- Parameters:
engine- cash flow engineseed- random seed
-
-
Method Details
-
addTriangular
Add an uncertain variable with triangular distribution.- Parameters:
name- variable name (e.g., "oilPrice", "capex", "opex")min- minimum valuemode- most likely valuemax- maximum value
-
addNormal
Add an uncertain variable with normal distribution.- Parameters:
name- variable namemean- mean valuestdDev- standard deviation
-
addLognormal
Add an uncertain variable with lognormal distribution.- Parameters:
name- variable namemeanOfLog- mean of underlying normal distributionstdDevOfLog- standard deviation of underlying normal
-
addUniform
Add an uncertain variable with uniform distribution.- Parameters:
name- variable namemin- minimum valuemax- maximum value
-
addVariable
public void addVariable(String name, MonteCarloRunner.DistributionType distribution, double param1, double param2, double param3) Add an uncertain variable with specified distribution.- Parameters:
name- variable namedistribution- distribution typeparam1- first parameter (min for triangular/uniform, mean for normal/lognormal)param2- second parameter (mode for triangular, max for uniform, stddev for normal)param3- third parameter (max for triangular, unused for others)
-
setIterations
public void setIterations(int iterations) Set number of Monte Carlo iterations.- Parameters:
iterations- number of iterations (typically 1000-10000)
-
getIterations
public int getIterations()Get number of iterations.- Returns:
- number of iterations
-
setDiscountRate
public void setDiscountRate(double rate) Set discount rate for NPV calculations.- Parameters:
rate- discount rate as decimal (e.g., 0.08 for 8%)
-
getDiscountRate
public double getDiscountRate()Get discount rate.- Returns:
- discount rate
-
setSeed
public void setSeed(long seed) Set random seed for reproducibility.- Parameters:
seed- random seed
-
sample
Sample a value from the specified distribution.- Parameters:
var- uncertain variable definition- Returns:
- sampled value
-
sampleTriangular
private double sampleTriangular(double min, double mode, double max) Sample from triangular distribution.- Parameters:
min- minimummode- most likelymax- maximum- Returns:
- sampled value
-
sampleNormal
private double sampleNormal(double mean, double stdDev) Sample from normal distribution.- Parameters:
mean- meanstdDev- standard deviation- Returns:
- sampled value
-
sampleLognormal
private double sampleLognormal(double meanOfLog, double stdDevOfLog) Sample from lognormal distribution.- Parameters:
meanOfLog- mean of underlying normalstdDevOfLog- std dev of underlying normal- Returns:
- sampled value
-
sampleUniform
private double sampleUniform(double min, double max) Sample from uniform distribution.- Parameters:
min- minimummax- maximum- Returns:
- sampled value
-
run
public boolean run()Run the Monte Carlo simulation.Executes the specified number of iterations, sampling from each uncertain variable and calculating NPV for each scenario.
- Returns:
- true if simulation completed successfully
-
applyVariable
Apply a sampled variable value to the cash flow engine.- Parameters:
name- variable namevalue- sampled value
-
getPercentile
Get the percentile value for a result metric.- Parameters:
metric- metric name ("npv", "irr", "payback")percentile- percentile (0-100)- Returns:
- percentile value
-
getP10
Get the P10 value (10th percentile - low case).- Parameters:
metric- metric name- Returns:
- P10 value
-
getP50
Get the P50 value (50th percentile - base case).- Parameters:
metric- metric name- Returns:
- P50 value
-
getP90
Get the P90 value (90th percentile - high case).- Parameters:
metric- metric name- Returns:
- P90 value
-
getMean
Get mean value for a metric.- Parameters:
metric- metric name- Returns:
- mean value
-
getStdDev
Get standard deviation for a metric.- Parameters:
metric- metric name- Returns:
- standard deviation
-
getProbabilityPositiveNpv
public double getProbabilityPositiveNpv()Get the probability of positive NPV.- Returns:
- probability (0-1)
-
getProbabilityNpvExceeds
public double getProbabilityNpvExceeds(double threshold) Get the probability that NPV exceeds a threshold.- Parameters:
threshold- NPV threshold in MUSD- Returns:
- probability (0-1)
-
getMetricValue
Get metric value from an iteration result.- Parameters:
result- iteration resultmetric- metric name- Returns:
- metric value
-
getResults
Get all iteration results.- Returns:
- list of iteration results
-
getConvergedCount
public int getConvergedCount()Get number of converged iterations.- Returns:
- converged count
-
generateReport
Generate a summary report of the Monte Carlo results.- Returns:
- formatted report string
-