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

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


      final SABRFormulaData sabrFormulaData = new SABRFormulaData(mp[0], beta, rho, nu);
      final double value = _atmCalculator.calculate(sabrFormulaData, option, forward, atmVol);
      mp[0] = value;
      lsRes = new LeastSquareResults(lsRes.getChiSq(), new DoubleMatrix1D(mp), lsRes.getCovariance());
    }
    return new LeastSquareResultsWithTransform(lsRes, transforms);
    //return new LeastSquareResults(lsRes.getChiSq(), new DoubleMatrix1D(mp), new DoubleMatrix2D(new double[N_PARAMETERS][N_PARAMETERS]), lsRes.getFittingParameterSensitivityToData());
  }
View Full Code Here


    final double[][] start = getStartValues();
    final BitSet[] fixed = getFixedValues();
    final int nStartPoints = start.length;
    Validate.isTrue(fixed.length == nStartPoints);
    for (int trys = 0; trys < nStartPoints; trys++) {
      final LeastSquareResultsWithTransform results = _fitter.solve(new DoubleMatrix1D(start[trys]), fixed[trys]);
      final DoubleMatrix1D res = toStandardForm(results.getModelParameters());

      //debug
      final T fittedModel = _fitter.toSmileModelData(res);
      fittedModel.toString();

      assertEquals(0.0, results.getChiSq(), _chiSqEps);

      final int n = res.getNumberOfElements();
      final T data = getModelData();
      assertEquals(data.getNumberOfParameters(), n);
      for (int i = 0; i < n; i++) {
View Full Code Here

    final double[][] start = getStartValues();
    final BitSet[] fixed = getFixedValues();
    final int nStartPoints = start.length;
    Validate.isTrue(fixed.length == nStartPoints);
    for (int trys = 0; trys < nStartPoints; trys++) {
      final LeastSquareResultsWithTransform results = _fitter.solve(new DoubleMatrix1D(start[trys]), fixed[trys]);
      final DoubleMatrix1D res = toStandardForm(results.getModelParameters());
      final double eps = 1e-2;
      assertTrue(results.getChiSq() < 7);
      final int n = res.getNumberOfElements();
      final T data = getModelData();
      assertEquals(data.getNumberOfParameters(), n);
      for (int i = 0; i < n; i++) {
        assertEquals(data.getParameter(i), res.getEntry(i), eps);
View Full Code Here

    final MixedLogNormalVolatilityFunction model = getModel();

    final MixedLogNormalModelFitter fitter = new MixedLogNormalModelFitter(forward, strikes, expiry, vols, errors, model, 3, true);

    double bestChi2 = Double.POSITIVE_INFINITY;
    LeastSquareResultsWithTransform best = null;
    final int tries = 10;
    int fails = 0;
    for (int i = 0; i < tries; i++) {
      final DoubleMatrix1D start = getRandomStart();
      try {
        final LeastSquareResultsWithTransform res = fitter.solve(start);
        if (res.getChiSq() < bestChi2) {
          bestChi2 = res.getChiSq();
          best = res;
        }
      } catch (final MathException e) {
        fails++;
      } catch (final IllegalArgumentException e) {
View Full Code Here

    return INITIAL_VALUES;
  }

  @Test
  public void testSolutionFlatSurface() {
    final LeastSquareResultsWithTransform results = FITTER.getFitResult(OPTIONS, FLAT_DATA, ERRORS, INITIAL_VALUES, FIXED);
    final DoubleMatrix1D parameters = results.getModelParameters();
    assertEquals("a", SIGMA * SIGMA, parameters.getEntry(0), EPS);
    assertEquals("b", 0.0, parameters.getEntry(1), EPS);
    //TODO investigate why a chi^2 of 0 is not reached
    //assertEquals("chi^2", 0.0, results.getChiSq(), EPS);

View Full Code Here

  }

  @Test
  public void testRecoverParameters() {
    LeastSquareResultsWithTransform results = FITTER.getFitResult(OPTIONS, SMILE_DATA, INITIAL_VALUES, FIXED);
    DoubleMatrix1D fit = results.getModelParameters();
    final double eps = ERRORS[0];
    assertEquals("a", SVI_DATA.getA(), fit.getEntry(0), eps);
    assertEquals("b", SVI_DATA.getB(), fit.getEntry(1), eps);
    assertEquals("rho", SVI_DATA.getRho(), fit.getEntry(2), eps);
    assertEquals("sigma", SVI_DATA.getNu(), fit.getEntry(3), eps * 100);
    assertEquals("m", SVI_DATA.getM(), fit.getEntry(4), eps);
    final double chiSq = results.getChiSq();
    assertEquals("chi^2", 0, chiSq, eps * eps);
    results = FITTER.getFitResult(OPTIONS, SMILE_DATA, ERRORS, INITIAL_VALUES, FIXED);
    fit = results.getModelParameters();
    assertEquals(SVI_DATA.getA(), fit.getEntry(0), eps);
    assertEquals(SVI_DATA.getB(), fit.getEntry(1), eps);
    assertEquals(SVI_DATA.getRho(), fit.getEntry(2), eps);
    assertEquals(SVI_DATA.getNu(), fit.getEntry(3), eps * 100);
    assertEquals(SVI_DATA.getM(), fit.getEntry(4), eps);
    assertEquals(results.getChiSq() * eps * eps, chiSq, eps);
  }
View Full Code Here

  @Test
  (enabled = false)
  public void test() {
    final DoubleMatrix1D initialGuess = new DoubleMatrix1D(new double[] {0.2, 0.3, 0.2, 2.0, 0.95, 0.8 });
    final TwoStateMarkovChainFitter fitter = new TwoStateMarkovChainFitter();
    final LeastSquareResultsWithTransform res = fitter.fit(FORWARD_CURVE, SABR_VOLS, initialGuess);
    System.out.println("chi^2:" + res.getChiSq() + "\n params: " + res.getModelParameters().toString());
  }
View Full Code Here

  @Test(enabled = false)
  public void test() {
    final DoubleMatrix1D initalGuess = new DoubleMatrix1D(new double[] {0.2, 0.8, 0.3, 2.0, 0.9, 0.9 });
    final TwoStateMarkovChainFitter fitter = new TwoStateMarkovChainFitter(THETA);
    final LeastSquareResultsWithTransform res = fitter.fit(FORWARD_CURVE, MARKET_VOLS, initalGuess);
    //System.out.println("chi^2:" + res.getChiSq() + "\n params: " + res.getParameters().toString());
    final double[] modelParms = res.getModelParameters().getData();

    assertEquals(0.0, res.getChiSq(), 1e-3);
    assertEquals(VOL1, modelParms[0], 1e-3);
    assertEquals(DELTA_VOL, modelParms[1], 2e-3);
    assertEquals(LAMBDA12, modelParms[2], 2e-3);
    assertEquals(LAMBDA21, modelParms[3], 2e-3);
    assertEquals(P0, modelParms[4], 1e-3);
View Full Code Here

        final double[] errors = new double[NB_STRIKE];
        for (int loopstr = 0; loopstr < NB_STRIKE; loopstr++) {
          strikeAbs[loopstr] = atm + STRIKE_RELATIVE[loopstr];
          errors[loopstr] = ERROR;
        }
        final LeastSquareResultsWithTransform fittedResult = new SABRModelFitter(atm, strikeAbs, EXPIRY_TIME[loopexpiry], volBlack[loopexpiry][loopmat], errors, SABR_FUNCTION).solve(
            SABR_INITIAL_VALUES, FIXED);
        inverseJacobianMap.put(new DoublesPair(EXPIRY_TIME[loopexpiry], MATURITY_TIME[loopmat]), fittedResult.getModelParameterSensitivityToData());
        expiryTimeVector[vect] = EXPIRY_TIME[loopexpiry];
        maturityTimeVector[vect] = MATURITY_TIME[loopmat];
        alphaVector[vect] = fittedResult.getModelParameters().getEntry(0);
        betaVector[vect] = fittedResult.getModelParameters().getEntry(1);
        rhoVector[vect] = fittedResult.getModelParameters().getEntry(2);
        nuVector[vect] = fittedResult.getModelParameters().getEntry(3);
        vect++;
      }
    }
    final InterpolatedDoublesSurface alphaSurface = InterpolatedDoublesSurface.from(expiryTimeVector, maturityTimeVector, alphaVector, INTERPOLATOR, "SABR alpha surface");
    final InterpolatedDoublesSurface betaSurface = InterpolatedDoublesSurface.from(expiryTimeVector, maturityTimeVector, betaVector, INTERPOLATOR, "SABR beta surface");
View Full Code Here

          final double[] sigma = sigmaList.toDoubleArray();
          final double[] errors = errorsList.toDoubleArray();
          ArrayUtils.reverse(strikes);
          ArrayUtils.reverse(sigma);
          ArrayUtils.reverse(errors);
          final LeastSquareResultsWithTransform fittedResult = new HestonModelFitter(forward, strikes, t, sigma, errors, HESTON_FUNCTION).solve(HESTON_INITIAL_VALUES);
          final DoubleMatrix1D parameters = fittedResult.getModelParameters();
          fittedOptionExpiryList.add(t);
          futureDelayList.add(0);
          kappaList.add(parameters.getEntry(0));
          thetaList.add(parameters.getEntry(1));
          vol0List.add(parameters.getEntry(2));
          omegaList.add(parameters.getEntry(3));
          rhoList.add(parameters.getEntry(4));
          inverseJacobians.put(DoublesPair.of(t.doubleValue(), 0.), fittedResult.getModelParameterSensitivityToData());
          chiSqList.add(fittedResult.getChiSq());
        }
      }
    }
    if (fittedOptionExpiryList.size() < 5) { //don't have sufficient fits to construct a surface
      throw new OpenGammaRuntimeException("Could not construct Heston parameter surfaces; have under 5 surface points");
View Full Code Here

TOP

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

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.