Ejemplo n.º 1
0
  /**
   * Date calculations
   *
   * @see <a
   *     href="http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412">http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412</a>
   */
  @Override
  public Date valueDate(final Date fixingDate) {
    // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :
    // In the case of EUR the Value Date shall be two TARGET
    // business days after the Fixing Date.

    QL.require(isValidFixingDate(fixingDate), "Fixing date " + fixingDate + " is not valid");
    return this.target.advance(fixingDate, fixingDays, TimeUnit.Days);
  }
Ejemplo n.º 2
0
  /**
   * Constructor which initializes {@latex$ \mu } and {@latex \sigma }.
   *
   * @param average
   * @param sigma
   */
  public NormalDistribution(final double average, final double sigma) {
    QL.require(sigma > 0.0, "sigma must be greater than 0.0"); // TODO: message

    this.average = average;
    this.sigma = sigma;

    this.normalizationFactor = Constants.M_SQRT_2 * Constants.M_1_SQRTPI / sigma;
    this.denormalizationFactor = sigma * sigma;
    this.denominator = 2.0 * denormalizationFactor;
  }
Ejemplo n.º 3
0
 @Override
 public double op(final double x) {
   QL.require(x > 0.0, "strike must be positive: " + x + " not allowed");
   return (new Sabr())
       .sabrVolatility(
           x,
           forward_,
           itsCoeffs.t_,
           itsCoeffs.alpha_,
           itsCoeffs.beta_,
           itsCoeffs.nu_,
           itsCoeffs.rho_);
 }
Ejemplo n.º 4
0
    public SABRCoeffHolder(
        final @Time double t,
        final double forward,
        final double alpha,
        final double beta,
        final double nu,
        final double rho,
        final boolean alphaIsFixed,
        final boolean betaIsFixed,
        final boolean nuIsFixed,
        final boolean rhoIsFixed) {
      t_ = t;
      forward_ = forward;
      alpha_ = alpha;
      beta_ = beta;
      nu_ = nu;
      rho_ = rho;
      alphaIsFixed_ = false;
      betaIsFixed_ = false;
      nuIsFixed_ = false;
      rhoIsFixed_ = false;
      weights_ = new Array(0); // ZH:TBD:verify with QL097, it is vector<Real> in QL097
      error_ = Constants.NULL_REAL;
      maxError_ = Constants.NULL_REAL;
      SABREndCriteria_ = EndCriteria.Type.None;

      QL.require(t > 0.0, "expiry time must be positive: " + t + " not allowed");
      if (!Double.isNaN(alpha_)) {
        alphaIsFixed_ = alphaIsFixed;
      } else {
        alpha_ = Math.sqrt(0.2);
      }
      if (!Double.isNaN(beta_)) {
        betaIsFixed_ = betaIsFixed;
      } else {
        beta_ = 0.5;
      }
      if (!Double.isNaN(nu_)) {
        nuIsFixed_ = nuIsFixed;
      } else {
        nu_ = Math.sqrt(0.4);
      }
      if (!Double.isNaN(rho_)) {
        rhoIsFixed_ = rhoIsFixed;
      } else {
        rho_ = 0.0;
      }
      (new Sabr()).validateSabrParameters(alpha_, beta_, nu_, rho_);
    }
Ejemplo n.º 5
0
  public EURLibor(final Period tenor, final YieldTermStructure h) {
    super(
        "EURLibor",
        tenor,
        2, // settlement days
        new EURCurrency(),
        new JointCalendar(
            new UnitedKingdom(Market.Exchange), new Target(), JointCalendarRule.JoinBusinessDays),
        eurliborConvention(tenor),
        eurliborEOM(tenor),
        new Actual360(),
        h);
    QL.require(
        tenor().units() != TimeUnit.Days,
        "for daily tenors dedicated DailyTenor constructor must be used");

    this.target = new Target();
  }
Ejemplo n.º 6
0
  @Override
  public void fetchResults(final PricingEngine.Results r) {
    super.fetchResults(r);

    QL.require(
        OneAssetOption.Results.class.isAssignableFrom(r.getClass()),
        ReflectConstants.WRONG_ARGUMENT_TYPE); // QA:[RG]::verified
    // final Greeks results = (Greeks)(r);

    final OneAssetOption.ResultsImpl ri = (OneAssetOption.ResultsImpl) r;
    final GreeksImpl results = ri.greeks();

    QL.ensure(results != null, "no greeks returned from pricing engine");
    /* no check on null values - just copy.
       this allows:
       a) to decide in derived options what to do when null
       results are returned (throw? numerical calculation?)
       b) to implement slim engines which only calculate the
       value---of course care must be taken not to call
       the greeks methods when using these.
    */
    delta_ = results.delta;
    gamma_ = results.gamma;
    theta_ = results.theta;
    vega_ = results.vega;
    rho_ = results.rho;
    dividendRho_ = results.dividendRho;

    final MoreGreeksImpl moreResults = ri.moreGreeks();
    QL.ensure(moreResults != null, "no more greeks returned from pricing engine");
    /* no check on null values - just copy.
       this allows:
       a) to decide in derived options what to do when null
       results are returned (throw? numerical calculation?)
       b) to implement slim engines which only calculate the
       value---of course care must be taken not to call
       the greeks methods when using these.
    */
    deltaForward_ = moreResults.deltaForward;
    elasticity_ = moreResults.elasticity;
    thetaPerDay_ = moreResults.thetaPerDay;
    strikeSensitivity_ = moreResults.strikeSensitivity;
    itmCashProbability_ = moreResults.itmCashProbability;
  }
Ejemplo n.º 7
0
    @Override
    public void update() {
      // forward_ might have changed
      QL.require(
          forward_ > 0.0,
          "at the money forward rate must be " + "positive: " + forward_ + " not allowed");

      // we should also check that y contains positive values only

      // we must update weights if it is vegaWeighted
      if (vegaWeighted_) {
        // itsCoeffs.weights_.clear();
        double weightsSum = 0.0;
        for (int i = 0; i < vx.size(); i++) {
          final double x = vx.get(i);
          final double y = vy.get(i);
          final double stdDev = Math.sqrt(y * y * itsCoeffs.t_);
          itsCoeffs.weights_.set(i, BlackFormula.blackFormulaStdDevDerivative(x, forward_, stdDev));
          weightsSum += itsCoeffs.weights_.get(i);
        }
        // weight normalization
        for (int i = 0; i < itsCoeffs.weights_.size(); i++) {
          itsCoeffs.weights_.set(i, itsCoeffs.weights_.get(i) / weightsSum);
        }
      }

      // there is nothing to optimize
      if (itsCoeffs.alphaIsFixed_
          && itsCoeffs.betaIsFixed_
          && itsCoeffs.nuIsFixed_
          && itsCoeffs.rhoIsFixed_) {
        itsCoeffs.error_ = interpolationError();
        itsCoeffs.maxError_ = interpolationMaxError();
        itsCoeffs.SABREndCriteria_ = EndCriteria.Type.None;
        return;

      } else {

        final SABRError costFunction = new SABRError(this);
        transformation_ = new SabrParametersTransformation();

        final Array guess = new Array(4);
        guess.set(0, itsCoeffs.alpha_);
        guess.set(1, itsCoeffs.beta_);
        guess.set(2, itsCoeffs.nu_);
        guess.set(3, itsCoeffs.rho_);

        final boolean[] parameterAreFixed = new boolean[4];
        parameterAreFixed[0] = itsCoeffs.alphaIsFixed_;
        parameterAreFixed[1] = itsCoeffs.betaIsFixed_;
        parameterAreFixed[2] = itsCoeffs.nuIsFixed_;
        parameterAreFixed[3] = itsCoeffs.rhoIsFixed_;

        final Array inversedTransformatedGuess = new Array(transformation_.inverse(guess));

        final ProjectedCostFunction constrainedSABRError =
            new ProjectedCostFunction(costFunction, inversedTransformatedGuess, parameterAreFixed);

        final Array projectedGuess =
            new Array(constrainedSABRError.project(inversedTransformatedGuess));

        final NoConstraint constraint = new NoConstraint();
        final Problem problem = new Problem(constrainedSABRError, constraint, projectedGuess);
        itsCoeffs.SABREndCriteria_ = optMethod_.minimize(problem, endCriteria_);
        final Array projectedResult = new Array(problem.currentValue());
        final Array transfResult = new Array(constrainedSABRError.include(projectedResult));

        final Array result = transformation_.direct(transfResult);
        itsCoeffs.alpha_ = result.get(0);
        itsCoeffs.beta_ = result.get(1);
        itsCoeffs.nu_ = result.get(2);
        itsCoeffs.rho_ = result.get(3);
      }
      itsCoeffs.error_ = interpolationError();
      itsCoeffs.maxError_ = interpolationMaxError();
    }
Ejemplo n.º 8
0
 public double gamma() {
   calculate();
   QL.require(gamma_ != Constants.NULL_REAL, "gamma not provided");
   return gamma_;
 }
Ejemplo n.º 9
0
 public double elasticity() {
   calculate();
   QL.require(elasticity_ != Constants.NULL_REAL, "elasticity not provided");
   return elasticity_;
 }
Ejemplo n.º 10
0
 public double thetaPerDay() {
   calculate();
   QL.require(thetaPerDay_ != Constants.NULL_REAL, "theta per-day not provided");
   return thetaPerDay_;
 }
Ejemplo n.º 11
0
 public double delta() {
   calculate();
   QL.require(delta_ != Constants.NULL_REAL, "delta not provided");
   return delta_;
 }
Ejemplo n.º 12
0
 public double itmCashProbability() {
   calculate();
   QL.require(
       itmCashProbability_ != Constants.NULL_REAL, "in-the-money cash probability not provided");
   return itmCashProbability_;
 }
Ejemplo n.º 13
0
 public double strikeSensitivity() {
   calculate();
   QL.require(strikeSensitivity_ != Constants.NULL_REAL, "strike sensitivity not provided");
   return strikeSensitivity_;
 }
Ejemplo n.º 14
0
 public double dividendRho() {
   calculate();
   QL.require(dividendRho_ != Constants.NULL_REAL, "dividend rho not provided");
   return dividendRho_;
 }
Ejemplo n.º 15
0
 public double rho() {
   calculate();
   QL.require(rho_ != Constants.NULL_REAL, "rho not provided");
   return rho_;
 }
Ejemplo n.º 16
0
 public double vega() {
   calculate();
   QL.require(vega_ != Constants.NULL_REAL, "vega not provided");
   return vega_;
 }
Ejemplo n.º 17
0
 public double deltaForward() /* @ReadOnly */ {
   calculate();
   QL.require(deltaForward_ != Constants.NULL_REAL, "forward delta not provided");
   return deltaForward_;
 }
Ejemplo n.º 18
0
 public double theta() {
   calculate();
   QL.require(theta_ != Constants.NULL_REAL, "theta not provided");
   return theta_;
 }