Class MonteCarloRunner

java.lang.Object
neqsim.process.fielddevelopment.evaluation.MonteCarloRunner
All Implemented Interfaces:
Serializable

public class MonteCarloRunner extends Object implements 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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial version UID.
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger instance.
    • cashFlowEngine

      private CashFlowEngine cashFlowEngine
      Cash flow engine for economic calculations.
    • variables

      List of uncertain variables.
    • results

      Results from all iterations.
    • iterations

      private int iterations
      Number of Monte Carlo iterations.
    • random

      private Random random
      Random number generator.
    • discountRate

      private double discountRate
      Discount rate for NPV calculation.
  • Constructor Details

    • MonteCarloRunner

      public MonteCarloRunner(CashFlowEngine engine)
      Creates a new Monte Carlo runner.
      Parameters:
      engine - cash flow engine for economic calculations
    • MonteCarloRunner

      public MonteCarloRunner(CashFlowEngine engine, long seed)
      Creates a new Monte Carlo runner with specified seed for reproducibility.
      Parameters:
      engine - cash flow engine
      seed - random seed
  • Method Details

    • addTriangular

      public void addTriangular(String name, double min, double mode, double max)
      Add an uncertain variable with triangular distribution.
      Parameters:
      name - variable name (e.g., "oilPrice", "capex", "opex")
      min - minimum value
      mode - most likely value
      max - maximum value
    • addNormal

      public void addNormal(String name, double mean, double stdDev)
      Add an uncertain variable with normal distribution.
      Parameters:
      name - variable name
      mean - mean value
      stdDev - standard deviation
    • addLognormal

      public void addLognormal(String name, double meanOfLog, double stdDevOfLog)
      Add an uncertain variable with lognormal distribution.
      Parameters:
      name - variable name
      meanOfLog - mean of underlying normal distribution
      stdDevOfLog - standard deviation of underlying normal
    • addUniform

      public void addUniform(String name, double min, double max)
      Add an uncertain variable with uniform distribution.
      Parameters:
      name - variable name
      min - minimum value
      max - 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 name
      distribution - distribution type
      param1 - 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

      private double sample(MonteCarloRunner.UncertainVariable var)
      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 - minimum
      mode - most likely
      max - maximum
      Returns:
      sampled value
    • sampleNormal

      private double sampleNormal(double mean, double stdDev)
      Sample from normal distribution.
      Parameters:
      mean - mean
      stdDev - standard deviation
      Returns:
      sampled value
    • sampleLognormal

      private double sampleLognormal(double meanOfLog, double stdDevOfLog)
      Sample from lognormal distribution.
      Parameters:
      meanOfLog - mean of underlying normal
      stdDevOfLog - std dev of underlying normal
      Returns:
      sampled value
    • sampleUniform

      private double sampleUniform(double min, double max)
      Sample from uniform distribution.
      Parameters:
      min - minimum
      max - 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

      private void applyVariable(String name, double value)
      Apply a sampled variable value to the cash flow engine.
      Parameters:
      name - variable name
      value - sampled value
    • getPercentile

      public double getPercentile(String metric, double percentile)
      Get the percentile value for a result metric.
      Parameters:
      metric - metric name ("npv", "irr", "payback")
      percentile - percentile (0-100)
      Returns:
      percentile value
    • getP10

      public double getP10(String metric)
      Get the P10 value (10th percentile - low case).
      Parameters:
      metric - metric name
      Returns:
      P10 value
    • getP50

      public double getP50(String metric)
      Get the P50 value (50th percentile - base case).
      Parameters:
      metric - metric name
      Returns:
      P50 value
    • getP90

      public double getP90(String metric)
      Get the P90 value (90th percentile - high case).
      Parameters:
      metric - metric name
      Returns:
      P90 value
    • getMean

      public double getMean(String metric)
      Get mean value for a metric.
      Parameters:
      metric - metric name
      Returns:
      mean value
    • getStdDev

      public double getStdDev(String metric)
      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

      private double getMetricValue(MonteCarloRunner.IterationResult result, String metric)
      Get metric value from an iteration result.
      Parameters:
      result - iteration result
      metric - metric name
      Returns:
      metric value
    • getResults

      public List<MonteCarloRunner.IterationResult> getResults()
      Get all iteration results.
      Returns:
      list of iteration results
    • getConvergedCount

      public int getConvergedCount()
      Get number of converged iterations.
      Returns:
      converged count
    • generateReport

      public String generateReport()
      Generate a summary report of the Monte Carlo results.
      Returns:
      formatted report string