Examples of MixedLogNormalModelData


Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

  }

  @Override
  protected MixedLogNormalModelData toSmileModelData(final DoubleMatrix1D modelParameters) {
    ArgumentChecker.notNull(modelParameters, "model parameters");
    return new MixedLogNormalModelData(modelParameters.getData());
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    if (n == 3) {
      if (gRes.getChiSq() / n > 1.0) {
        s_logger.warn("chi^2 on SABR fit to ", +n + " points is " + gRes.getChiSq());
      }
      modelParams[0] = new MixedLogNormalModelData(gRes.getModelParameters().getData());
    } else {
      //impose a global beta on the remaining 3 point fits
      //final double[] gFitParms = gRes.getModelParameters().getData();
      //final double theta = gFitParms[2];
      //start = new DoubleMatrix1D(gFitParms[0], gFitParms[1], gFitParms[3]);
      start = gRes.getModelParameters();
      fixed.set(2); //fixed weight
      //final BroydenVectorRootFinder rootFinder = new BroydenVectorRootFinder(1e-8, 1e-8, 100, new SVDecompositionCommons());

      double[] tStrikes = new double[4];
      double[] tVols = new double[4];

      for (int i = 0; i < n - 2; i++) {
        tStrikes = Arrays.copyOfRange(strikes, i, i + 3);
        tVols = Arrays.copyOfRange(impliedVols, i, i + 3);
        errors = new double[3];
        Arrays.fill(errors, 0.0001); //1bps
        //        Function1D<DoubleMatrix1D, DoubleMatrix1D> func = getVolDiffFunc(forward, tStrikes, expiry, tVols, theta);
        //        Function1D<DoubleMatrix1D, DoubleMatrix2D> jac = getVolJacFunc(forward, tStrikes, expiry, theta);
        //        NonLinearTransformFunction tf = new NonLinearTransformFunction(func, jac, TRANSFORM);
        //
        //        DoubleMatrix1D res = rootFinder.getRoot(tf.getFittingFunction(),tf.getFittingJacobian(), start);
        //        double[] root = TRANSFORM.inverseTransform(res).getData();

        final SmileModelFitter<MixedLogNormalModelData> fitter = new MixedLogNormalModelFitter(forward, tStrikes, expiry, tVols, errors, MODEL, 2, true);
        final LeastSquareResultsWithTransform lRes = fitter.solve(start, fixed);
        if (lRes.getChiSq() > 3.0) {
          s_logger.warn("chi^2 on 3-point SABR fit #" + i + " is " + lRes.getChiSq());
        }
        modelParams[i] = new MixedLogNormalModelData(lRes.getModelParameters().getData());

        // modelParams[i] = new MixedLogNormalModelData(new double[] {root[0], root[1], theta, root[2] });
      }
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

        final double sigma = x.getEntry(0);
        final double dSigma = x.getEntry(1);

        final double phi = x.getEntry(2);
        final double[] params = new double[] {sigma, dSigma, theta, phi };
        final MixedLogNormalModelData data = new MixedLogNormalModelData(params);
        final double[] vols = func.evaluate(data);
        final double[] res = new double[n];
        for (int i = 0; i < n; i++) {
          res[i] = vols[i] - impliedVols[i];
        }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

      public DoubleMatrix2D evaluate(final DoubleMatrix1D x) {
        final double sigma = x.getEntry(0);
        final double dTheta = x.getEntry(1);
        final double phi = x.getEntry(2);
        final double[] params = new double[] {sigma, dTheta, theta, phi };
        final MixedLogNormalModelData data = new MixedLogNormalModelData(params);

        final double[][] temp = adjointFunc.evaluate(data);
        //remove the theta sense
        final double[][] res = new double[3][3];
        for (int i = 0; i < 3; i++) {
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

      @Override
      public Double evaluate(final Double strike) {
        final EuropeanVanillaOption option = new EuropeanVanillaOption(strike, expiry, true);
        final int index = SurfaceArrayUtils.getLowerBoundIndex(strikes, strike);
        if (index == 0) {
          final MixedLogNormalModelData p = modelParams[0];
          return MODEL.getVolatility(option, forward, p);
        }
        if (index >= n - 2) {
          final MixedLogNormalModelData p = modelParams[n - 3];
          return MODEL.getVolatility(option, forward, p);
        }
        final double w = _weightingFunction.getWeight(strikes, index, strike);
        if (w == 1) {
          final MixedLogNormalModelData p1 = modelParams[index - 1];
          return MODEL.getVolatility(option, forward, p1);
        } else if (w == 0) {
          final MixedLogNormalModelData p2 = modelParams[index];
          return MODEL.getVolatility(option, forward, p2);
        } else {
          final MixedLogNormalModelData p1 = modelParams[index - 1];
          final MixedLogNormalModelData p2 = modelParams[index];
          return w * MODEL.getVolatility(option, forward, p1) + (1 - w) * MODEL.getVolatility(option, forward, p2);
        }
      }
    };
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    for (int i = 0; i < nNorms - 1; ++i) {
      paramsY[i + nNorms] = params[i + 2 * nNorms];
      paramsY[i + 2 * nNorms - 1] = params[i + 4 * nNorms - 2];
    }

    final MixedLogNormalModelData dataX = new MixedLogNormalModelData(paramsX, true);
    final MixedLogNormalModelData dataY = new MixedLogNormalModelData(paramsY, true);

    final double[] res = new double[nData];
    Arrays.fill(res, 0.);

    for (int j = 0; j < nX; ++j) {
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    for (int i = 0; i < nNorms - 1; ++i) {
      paramsY[i + nNorms] = params[i + 2 * nNorms];
      paramsY[i + 2 * nNorms - 1] = params[i + 4 * nNorms - 2];
    }

    final MixedLogNormalModelData dataX = new MixedLogNormalModelData(paramsX, true);
    final MixedLogNormalModelData dataY = new MixedLogNormalModelData(paramsY, true);

    final double[][] res = new double[nData][nParams];
    for (int i = 0; i < nData; ++i) {
      Arrays.fill(res[i], 0.);
    }

    final double[] weightsX = dataX.getWeights();
    final double[] weightsY = dataY.getWeights();
    final double[] sigmasX = dataX.getVolatilities();
    final double[] sigmasY = dataY.getVolatilities();
    final double[] relativeForwardsX = dataX.getRelativeForwards();
    final double[] relativeForwardsY = dataY.getRelativeForwards();
    final double[][] weightsJacobianX = dataX.getWeightsJacobian();
    final double[][] weightsJacobianY = dataY.getWeightsJacobian();
    final double[][] relativeForwardsJacobianX = dataX.getRelativeForwardsJacobian();
    final double[][] relativeForwardsJacobianY = dataY.getRelativeForwardsJacobian();

    for (int j = 0; j < nX; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(dataStrs[j], time, true);
      final double impVolX = getVolatility(option, fwdX, dataX);
      for (int i = 0; i < nNorms; ++i) {
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    final double[] inSigmasX = {0.25, 0.7 };
    final double[] inSigmasY = {0.3, 0.5 };

    final double[] inWeights = {0.7, 0.3 };

    final MixedLogNormalModelData inObjX = new MixedLogNormalModelData(inWeights, inSigmasX, inRelativePartialForwardsX);
    final MixedLogNormalModelData inObjY = new MixedLogNormalModelData(inWeights, inSigmasY, inRelativePartialForwardsY);

    xx = new double[] {0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8, 0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8 };

    final MixedLogNormalVolatilityFunction volfunc = MixedLogNormalVolatilityFunction.getInstance();
    Arrays.fill(yy, 0.);

    for (int j = 0; j < nDataPtsX; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdX, inObjX);
    }

    for (int j = nDataPtsX; j < nDataPts; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdY, inObjY);
    }

    for (int i = 0; i < nNorms; ++i) {
      rhos[i] = 0.3 * (i + 1.);
    }

    System.out.println("true values: " + inSigmasX[0] + "\t" + inSigmasX[1]);
    System.out.println("\n");

    //    for (int i = 0; i < nParams; ++i) {
    //      aaGuess1[i] = 1e-2 + obj.nextDouble(); //Too small guess values may cause instability of fitting
    //      System.out.println(aaGuess1[i]);
    //    }

    aaGuess1 = new double[] {0.7754891006466627, 0.43606844423507685, 0.012213666603921194, 0.29500288815152165, 0.5444481098115485, 0.5291315433000237, 0.2231641334515797 };

    MixedBivariateLogNormalFitter fitter1 = new MixedBivariateLogNormalFitter();

    final boolean fitDone = false;
    int counter = 0;

    while (fitDone == false && counter <= 100000) {
      counter += 1;

      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      MixedLogNormalModelData tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      double[] tmpSigmasX = tmpObj1X.getVolatilities();

      System.out.println("guess: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);

      fitter1.doFit(aaGuess1, xx, yy, time, fwdX, fwdY, nNorms, nDataPtsX, 1);
      aaGuess1 = fitter1.getParams();
      System.out.println("inintial sq: " + fitter1.getInitialSq());
      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      tmpSigmasX = tmpObj1X.getVolatilities();

      System.out.println("answer: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);
      System.out.println("sq: " + fitter1.getFinalSq());
      System.out.println("\n");

View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    final double[] inSigmasX = {0.25, 0.7 };
    final double[] inSigmasY = {0.3, 0.5 };

    final double[] inWeights = {0.7, 0.3 };

    final MixedLogNormalModelData inObjX = new MixedLogNormalModelData(inWeights, inSigmasX, inRelativePartialForwardsX);
    final MixedLogNormalModelData inObjY = new MixedLogNormalModelData(inWeights, inSigmasY, inRelativePartialForwardsY);

    final double[] xx = new double[] {0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8, 0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8 };

    final MixedLogNormalVolatilityFunction volfunc = MixedLogNormalVolatilityFunction.getInstance();
    Arrays.fill(yy, 0.);

    for (int j = 0; j < nDataPtsX; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdX, inObjX);
    }

    for (int j = nDataPtsX; j < nDataPts; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdY, inObjY);
    }

    for (int i = 0; i < nNorms; ++i) {
      rhos[i] = 0.2 * (0.5 * i + 1.);
    }

    System.out.println("true values: " + inSigmasX[0] + "\t" + inSigmasX[1]);
    System.out.println("\n");

    for (int i = 0; i < nParams; ++i) {
      aaGuess1[i] = 1e-2 + obj.nextDouble();
    }
    MixedBivariateLogNormalFitter fitter1 = new MixedBivariateLogNormalFitter();

    boolean fitDone = false;

    while (fitDone == false) {

      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      MixedLogNormalModelData tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      double[] tmpSigmasX = tmpObj1X.getVolatilities();

      System.out.println("guess: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);
      fitter1.doFit(aaGuess1, xx, yy, time, fwdX, fwdY, nNorms, nDataPtsX, 1);
      aaGuess1 = fitter1.getParams();
      System.out.println("inintial sq: " + fitter1.getInitialSq());

      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      tmpSigmasX = tmpObj1X.getVolatilities();

      if (fitter1.getFinalSq() <= fitter1.getInitialSq() * 1e-14) {
        fitDone = true;
        System.out.println("\n");
        System.out.println("answer: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);
        System.out.println("sq: " + fitter1.getFinalSq());
        System.out.println("\n");
        System.out.println("\n");
      } else {
        for (int i = 0; i < nParams; ++i) {
          aaGuess1[i] = 1e-2 + obj.nextDouble();
        }
        fitter1 = new MixedBivariateLogNormalFitter();
      }

    }

    for (int i = 0; i < nNorms; ++i) {
      aaGuess1X[i] = aaGuess1[i];
      aaGuess1Y[i] = aaGuess1[i + nNorms];
    }
    for (int i = 0; i < nNorms - 1; ++i) {
      aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
      aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
      aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
      aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
    }

    final MixedLogNormalModelData objAns1X = new MixedLogNormalModelData(aaGuess1X, true);
    final double[] weights = objAns1X.getWeights();
    final double[] sigmasX = objAns1X.getVolatilities();
    final double[] relativePartialForwardsX = objAns1X.getRelativeForwards();

    final MixedLogNormalModelData objAns1Y = new MixedLogNormalModelData(aaGuess1Y, true);
    final double[] sigmasY = objAns1Y.getVolatilities();
    final double[] relativePartialForwardsY = objAns1Y.getRelativeForwards();

    final MixedBivariateLogNormalModelVolatility objZ = new MixedBivariateLogNormalModelVolatility(weights, sigmasX,
        sigmasY, relativePartialForwardsX, relativePartialForwardsY, rhos);

    final double[] ansVolsX = new double[100];
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.smile.function.MixedLogNormalModelData

    final double[] inSigmasX = {0.25, 0.7 };
    final double[] inSigmasY = {0.3, 0.5 };

    final double[] inWeights = {0.7, 0.3 };

    final MixedLogNormalModelData inObjX = new MixedLogNormalModelData(inWeights, inSigmasX, inRelativePartialForwardsX);
    final MixedLogNormalModelData inObjY = new MixedLogNormalModelData(inWeights, inSigmasY, inRelativePartialForwardsY);

    xx = new double[] {0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8, 0.5, 0.7, 0.9, 1.0, 1.2, 1.5, 1.8 };

    final MixedLogNormalVolatilityFunction volfunc = MixedLogNormalVolatilityFunction.getInstance();
    Arrays.fill(yy, 0.);

    for (int j = 0; j < nDataPtsX; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdX, inObjX);
    }

    for (int j = nDataPtsX; j < nDataPts; ++j) {
      final EuropeanVanillaOption option = new EuropeanVanillaOption(xx[j], time, true);
      yy[j] = volfunc.getVolatility(option, fwdY, inObjY);
    }

    for (int i = 0; i < nNorms; ++i) {
      rhos[i] = 0.2 * (0.5 * i + 1.);
    }

    //   System.out.println("true values: " + inSigmasX[0] + "\t" + inSigmasX[1]);
    //  System.out.println("\n");

    for (int i = 0; i < nParams; ++i) {
      aaGuess1[i] = 1e-2 + obj.nextDouble();
    }
    MixedBivariateLogNormalFitter fitter1 = new MixedBivariateLogNormalFitter();

    boolean fitDone = false;

    while (fitDone == false) {

      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      //  MixedLogNormalModelData tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      //double[] tmpSigmasX = tmpObj1X.getVolatilities();

      // System.out.println("guess: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);
      fitter1.doFit(aaGuess1, xx, yy, time, fwdX, fwdY, nNorms, nDataPtsX, 1.);
      aaGuess1 = fitter1.getParams();
      System.out.println("inintial sq: " + fitter1.getInitialSq());
      System.out.println("final sq: " + fitter1.getFinalSq());
      System.out.println("\n");

      for (int i = 0; i < nNorms; ++i) {
        aaGuess1X[i] = aaGuess1[i];
        aaGuess1Y[i] = aaGuess1[i + nNorms];
      }
      for (int i = 0; i < nNorms - 1; ++i) {
        aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
        aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
        aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
      }

      //   tmpObj1X = new MixedLogNormalModelData(aaGuess1X, true);
      //  tmpSigmasX = tmpObj1X.getVolatilities();

      if (fitter1.getFinalSq() <= fitter1.getInitialSq() * 1e-14) {
        fitDone = true;
        //System.out.println("\n");
        //System.out.println("answer: " + tmpSigmasX[0] + "\t" + tmpSigmasX[1]);

        System.out.println("XY Fitting Done");
        System.out.println("\n");
      } else {
        for (int i = 0; i < nParams; ++i) {
          aaGuess1[i] = 1e-2 + obj.nextDouble();
        }
        fitter1 = new MixedBivariateLogNormalFitter();
      }

    }

    for (int i = 0; i < nNorms; ++i) {
      aaGuess1X[i] = aaGuess1[i];
      aaGuess1Y[i] = aaGuess1[i + nNorms];
    }
    for (int i = 0; i < nNorms - 1; ++i) {
      aaGuess1X[i + nNorms] = aaGuess1[i + 2 * nNorms];
      aaGuess1X[i + 2 * nNorms - 1] = aaGuess1[i + 3 * nNorms - 1];
      aaGuess1Y[i + nNorms] = aaGuess1[i + 2 * nNorms];
      aaGuess1Y[i + 2 * nNorms - 1] = aaGuess1[i + 4 * nNorms - 2];
    }

    final MixedLogNormalModelData objAns1X = new MixedLogNormalModelData(aaGuess1X, true);
    final double[] weights = objAns1X.getWeights();
    final double[] sigmasX = objAns1X.getVolatilities();
    final double[] relativePartialForwardsX = objAns1X.getRelativeForwards();

    final MixedLogNormalModelData objAns1Y = new MixedLogNormalModelData(aaGuess1Y, true);
    final double[] sigmasY = objAns1Y.getVolatilities();
    final double[] relativePartialForwardsY = objAns1Y.getRelativeForwards();

    final MixedBivariateLogNormalModelVolatility objTrueZ = new MixedBivariateLogNormalModelVolatility(inWeights, inSigmasX,
        inSigmasY, inRelativePartialForwardsX, inRelativePartialForwardsY, rhos);

    final double[] xxZ = new double[nDataPtsX];
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.