/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 3.0.12
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package org.quantlib;

public class _CalibrationHelper {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

  protected _CalibrationHelper(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  protected static long getCPtr(_CalibrationHelper obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        QuantLibJNI.delete__CalibrationHelper(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public void setPricingEngine(PricingEngine engine) {
    QuantLibJNI._CalibrationHelper_setPricingEngine(swigCPtr, this, PricingEngine.getCPtr(engine), engine);
  }

  public double marketValue() {
    return QuantLibJNI._CalibrationHelper_marketValue(swigCPtr, this);
  }

  public double modelValue() {
    return QuantLibJNI._CalibrationHelper_modelValue(swigCPtr, this);
  }

  public double calibrationError() {
    return QuantLibJNI._CalibrationHelper_calibrationError(swigCPtr, this);
  }

  public double impliedVolatility(double targetValue, double accuracy, long maxEvaluations, double minVol, double maxVol) {
    return QuantLibJNI._CalibrationHelper_impliedVolatility(swigCPtr, this, targetValue, accuracy, maxEvaluations, minVol, maxVol);
  }

  public double blackPrice(double volatility) {
    return QuantLibJNI._CalibrationHelper_blackPrice(swigCPtr, this, volatility);
  }

  public QuoteHandle volatility() {
    return new QuoteHandle(QuantLibJNI._CalibrationHelper_volatility(swigCPtr, this), true);
  }

  public VolatilityType volatilityType() {
    return VolatilityType.swigToEnum(QuantLibJNI._CalibrationHelper_volatilityType(swigCPtr, this));
  }

  public final static class CalibrationErrorType {
    public final static _CalibrationHelper.CalibrationErrorType RelativePriceError = new _CalibrationHelper.CalibrationErrorType("RelativePriceError");
    public final static _CalibrationHelper.CalibrationErrorType PriceError = new _CalibrationHelper.CalibrationErrorType("PriceError");
    public final static _CalibrationHelper.CalibrationErrorType ImpliedVolError = new _CalibrationHelper.CalibrationErrorType("ImpliedVolError");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static CalibrationErrorType swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + CalibrationErrorType.class + " with value " + swigValue);
    }

    private CalibrationErrorType(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private CalibrationErrorType(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private CalibrationErrorType(String swigName, CalibrationErrorType swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static CalibrationErrorType[] swigValues = { RelativePriceError, PriceError, ImpliedVolError };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

}
