Package com.opengamma.analytics.math.statistics.leastsquare

Examples of com.opengamma.analytics.math.statistics.leastsquare.NonLinearLeastSquare


    ArgumentChecker.isTrue(nbInstruments % _nbInstrumentsBlock == 0, "Number of instruments incompatible with block size");
    final int nbBlocks = nbInstruments / _nbInstrumentsBlock;
    computeCalibrationPrice(curves);
    getCalibrationObjective().setCurves(curves);
    final SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationObjective objective = (SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationObjective) getCalibrationObjective();
    final NonLinearLeastSquare ls = new NonLinearLeastSquare(DecompositionFactory.SV_COMMONS, MatrixAlgebraFactory.OG_ALGEBRA, DEFAULT_PRECISION);
    //    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    for (int loopblock = 0; loopblock < nbBlocks; loopblock++) {
      final InstrumentDerivative[] instruments = new InstrumentDerivative[_nbInstrumentsBlock];
      final double[] prices = new double[_nbInstrumentsBlock];
      for (int loopins = 0; loopins < _nbInstrumentsBlock; loopins++) {
        instruments[loopins] = getBasket().get(loopblock * _nbInstrumentsBlock + loopins);
        prices[loopins] = getCalibrationPrice().get(loopblock * _nbInstrumentsBlock + loopins);
      }
      getCalibrationObjective().setInstruments(instruments);
      getCalibrationObjective().setPrice(prices);
      objective.setStartIndex(_instrumentIndex.get(loopblock * _nbInstrumentsBlock));
      objective.setEndIndex(_instrumentIndex.get((loopblock + 1) * _nbInstrumentsBlock) - 1);
      // Implementation note: the index start is from the first instrument of the block and the index end is from the last instrument of the block.
      final DoubleMatrix1D observedValues = new DoubleMatrix1D(_nbInstrumentsBlock, 0.0);
      @SuppressWarnings("unused")
      final
      LeastSquareResults result = ls.solve(observedValues, getCalibrationObjective(), new DoubleMatrix1D(1.0, 0.0));
      // Implementation note: the start value is a multiplicative factor of one and an additive term of 0 (parameters unchanged).
      //   The observed values are 0 as the function returns the difference between the calculated prices and the targets.
    }
  }
View Full Code Here


    ArgumentChecker.isTrue(nbInstruments % _nbInstrumentsBlock == 0, "Number of instruments incompatible with block size");
    final int nbBlocks = nbInstruments / _nbInstrumentsBlock;
    computeCalibrationPrice(data);
    _calibrationObjective.setMulticurves(data.getMulticurveProvider());
    final SuccessiveLeastSquareLMMDDCalibrationObjective objective = (SuccessiveLeastSquareLMMDDCalibrationObjective) _calibrationObjective;
    final NonLinearLeastSquare ls = new NonLinearLeastSquare(DecompositionFactory.SV_COMMONS, MatrixAlgebraFactory.OG_ALGEBRA, DEFAULT_PRECISION);
    //    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    for (int loopblock = 0; loopblock < nbBlocks; loopblock++) {
      final InstrumentDerivative[] instruments = new InstrumentDerivative[_nbInstrumentsBlock];
      final double[] prices = new double[_nbInstrumentsBlock];
      for (int loopins = 0; loopins < _nbInstrumentsBlock; loopins++) {
        instruments[loopins] = getBasket().get(loopblock * _nbInstrumentsBlock + loopins);
        prices[loopins] = getCalibrationPrices().get(loopblock * _nbInstrumentsBlock + loopins);
      }
      _calibrationObjective.setInstruments(instruments);
      _calibrationObjective.setPrice(prices);
      objective.setStartIndex(_instrumentIndex.get(loopblock * _nbInstrumentsBlock));
      objective.setEndIndex(_instrumentIndex.get((loopblock + 1) * _nbInstrumentsBlock) - 1);
      // Implementation note: the index start is from the first instrument of the block and the index end is from the last instrument of the block.
      final DoubleMatrix1D observedValues = new DoubleMatrix1D(_nbInstrumentsBlock, 0.0);
      @SuppressWarnings("unused")
      final
      LeastSquareResults result = ls.solve(observedValues, _calibrationObjective, new DoubleMatrix1D(1.0, 0.0));
      // Implementation note: the start value is a multiplicative factor of one and an additive term of 0 (parameters unchanged).
      //   The observed values are 0 as the function returns the difference between the calculated prices and the targets.
    }
  }
View Full Code Here

        return a + b * x1 + c * x1 * x1;
      }
    };

    //TODO replace this with an explicit polynomial fitter
    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    final LeastSquareResults lsRes = ls.solve(new DoubleMatrix1D(x), new DoubleMatrix1D(impliedVols), func, new DoubleMatrix1D(0.1, 0.0, 0.0));
    final DoubleMatrix1D fitP = lsRes.getFitParameters();
    return fitP;
  }
View Full Code Here

    for (int i = 0; i < nMarketValues; i++) {
      mrkVols[i] = marketVols.get(i).getSecond();
      sigma[i] = 0.01; //1% error
    }

    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    //solve approx first
    LeastSquareResults solverRes = ls.solve(new DoubleMatrix1D(mrkVols), new DoubleMatrix1D(sigma), funcAppox, TRANSFORMS.transform(initialGuess));
    // now solve pde model
    solverRes = ls.solve(new DoubleMatrix1D(mrkVols), new DoubleMatrix1D(sigma), func, solverRes.getFitParameters());
    return new LeastSquareResultsWithTransform(solverRes, TRANSFORMS);
  }
View Full Code Here

    TRANSFORMS[3] = new SingleRangeLimitTransform(0, LimitType.GREATER_THAN); //sigma
    TRANSFORMS[4] = new NullTransform(); //m
  }

  public SVINonLinearLeastSquareFitter() {
    this(new NonLinearLeastSquare(DecompositionFactory.SV_COLT, MatrixAlgebraFactory.OG_ALGEBRA, 1e-4));
  }
View Full Code Here

    final CapletStrippingJacobian jac = new CapletStrippingJacobian(CAPS, YIELD_CURVES, CURVE_NODES, INTERPOLATORS, TRANSFORMS, null);

    final double[] sigma = new double[MARKET_PRICES.length];
    Arrays.fill(sigma, 0.0001); // 1bps

    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    final LeastSquareResults lsRes = ls.solve(new DoubleMatrix1D(MARKET_VOLS), new DoubleMatrix1D(sigma), func, jac, START);

    final DoubleMatrix1D res = lsRes.getFitParameters();

    assertTrue("chi^2 too large", lsRes.getChiSq() < 0.3);
View Full Code Here

    Arrays.fill(start, NODES.length, NODES.length + 1, TRANSFORMS.get(NAMES[1]).transform(0.5));
    Arrays.fill(start, NODES.length + 1, 2 * NODES.length + 1, TRANSFORMS.get(NAMES[2]).transform(0.0));
    Arrays.fill(start, 2 * NODES.length + 1, 3 * NODES.length + 1, TRANSFORMS.get(NAMES[3]).transform(0.35));
    final DoubleMatrix1D vStart = new DoubleMatrix1D(start);

    final NonLinearLeastSquare ls = new NonLinearLeastSquare();
    final LeastSquareResults lsRes = ls.solve(new DoubleMatrix1D(MARKET_VOLS), new DoubleMatrix1D(SIGMA), func, jac, vStart);

    System.out.println("CapletStrippingMarketDataTest");
    System.out.println("chi2: " + lsRes.getChiSq() + "\n");

    final SABRTermStructureParameters sabrTS = (SABRTermStructureParameters) VOL_MODEL_PROVIDER.evaluate(lsRes.getFitParameters());
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.statistics.leastsquare.NonLinearLeastSquare

Copyright © 2018 www.massapicom. 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.