/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 4.0.2
 *
 * 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 BlackCalibrationHelper extends CalibrationHelper {
  private transient long swigCPtr;
  private transient boolean swigCMemOwnDerived;

  protected BlackCalibrationHelper(long cPtr, boolean cMemoryOwn) {
    super(QuantLibJNI.BlackCalibrationHelper_SWIGSmartPtrUpcast(cPtr), true);
    swigCMemOwnDerived = cMemoryOwn;
    swigCPtr = cPtr;
  }

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

  protected void swigSetCMemOwn(boolean own) {
    swigCMemOwnDerived = own;
    super.swigSetCMemOwn(own);
  }

  @SuppressWarnings("deprecation")
  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwnDerived) {
        swigCMemOwnDerived = false;
        QuantLibJNI.delete_BlackCalibrationHelper(swigCPtr);
      }
      swigCPtr = 0;
    }
    super.delete();
  }

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

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

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

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

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

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

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

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

  public final static class CalibrationErrorType {
    public final static BlackCalibrationHelper.CalibrationErrorType RelativePriceError = new BlackCalibrationHelper.CalibrationErrorType("RelativePriceError");
    public final static BlackCalibrationHelper.CalibrationErrorType PriceError = new BlackCalibrationHelper.CalibrationErrorType("PriceError");
    public final static BlackCalibrationHelper.CalibrationErrorType ImpliedVolError = new BlackCalibrationHelper.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;
  }

}
