Examples of PSplineFitter


Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

    for (int i = 0; i < n; i++) {
      x.add(k[i]);
      y.add(vols[i]);
      sigma.add(1e-5);
    }
    final PSplineFitter pfitter = new PSplineFitter();
    final GeneralizedLeastSquareResults<Double> temp = pfitter.solve(x, y, sigma, 0.5, 1.7, 50, 3, 100000000, 2);
    final Function1D<Double, Double> func3 = temp.getFunction();

    for (int i = 0; i < 101; i++) {
      final double strike = 0.5 + 1.0 * i / 100.;
      System.out.println(strike + "\t" + func.evaluate(strike) + "\t" + func2.evaluate(strike) + "\t" + func3.evaluate(strike));
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

  private final DoubleMatrix2D _penalty;

  public CapletStrippingSingleStrikeDirect(final List<CapFloor> caps, final YieldCurveBundle yieldCurves) {
    super(caps, yieldCurves);

    final PSplineFitter psf = new PSplineFitter();
    _penalty = (DoubleMatrix2D) MA.scale(psf.getPenaltyMatrix(getnCaplets(), DIFFERENCE_ORDER), LAMBDA);
    _interpolator = DEFAULT_INTERPOLATOR;
    // _altCapletStripper = new CapletStrippingAbsoluteStrikeInterpolation(caps, yieldCurves);
  }
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

    final double[] t = getPricer().getCapletExpiries();
    final int n = t.length;
    _bSplines = GEN.generateSet(t[0], t[n - 1], n, 1);

    _nWeights = _bSplines.size();
    final PSplineFitter psf = new PSplineFitter();
    _penalty = (DoubleMatrix2D) MA.scale(psf.getPenaltyMatrix(_nWeights, DIFFERENCE_ORDER), LAMBDA);
    _volModel = new BasisSplineVolatilityTermStructureProvider(_bSplines);
  }
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

  }

  @Test
  public void testPSplineFit2D() {

    final PSplineFitter psf = new PSplineFitter();
    final GeneralizedLeastSquareResults<double[]> results = psf.solve(X_COS_EXP, Y_COS_EXP, SIGMA_COS_EXP, new double[] {0.0, 0.0 }, new double[] {10.0, 10.0 }, new int[] {10, 10 },
        new int[] {3, 3 },
        new double[] {0.001, 0.001 }, new int[] {3, 3 });

    assertEquals(0.0, results.getChiSq(), 1e-9);
    final Function1D<double[], Double> spline = results.getFunction();
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

  public void linearTest() {
    final boolean print = false;
    if(print) {
      System.out.println("NonLinearLeastSquareWithPenaltyTest.linearTest");
    }
    final PSplineFitter psf = new PSplineFitter();
    final int nWeights = 20;
    final int diffOrder = 2;
    final double lambda = 100.0;
    final DoubleMatrix2D penalty = (DoubleMatrix2D) MA.scale(psf.getPenaltyMatrix(nWeights, diffOrder), lambda);
    // final boolean[] on = new boolean[nWeights];
    final int[] onIndex = new int[] {1, 4, 11, 12, 15, 17};
    final double[] obs = new double[] {0, 1.0, 1.0, 1.0, 0.0, 0.0};
    final int n = onIndex.length;
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

    }

    final List<Function1D<double[], Double>> bSplines = _generator.generateSet(xa, xb, nKnots, degree);
    final int nWeights = bSplines.size();

    final PSplineFitter psf = new PSplineFitter();
    DoubleMatrix2D ma = (DoubleMatrix2D) _algebra.scale(psf.getPenaltyMatrix(sizes, differenceOrder[0], 0), lambda[0]);
    for (int i = 1; i < dim; i++) {
      if (lambda[i] > 0.0) {
        final DoubleMatrix2D d = psf.getPenaltyMatrix(sizes, differenceOrder[i], i);
        ma = (DoubleMatrix2D) _algebra.add(ma, _algebra.scale(d, lambda[i]));
      }
    }
    final DoubleMatrix2D penalty = ma;//(DoubleMatrix2D) _algebra.multiply(_algebra.getTranspose(ma), ma);
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

        return debug;
      }

    };

    final PSplineFitter psf = new PSplineFitter();
    final DoubleMatrix2D penalty = (DoubleMatrix2D) _algebra.scale(psf.getPenaltyMatrix(nKnots, 2), 0.01);

    final double[] start = new double[nKnots];
    // Arrays.fill(start, 0.4);
    for (int i = 0; i < nKnots; i++) {
      start[i] = TRANSFORM.transform(IMP_VOL + 0.05 * (random.nextDouble() - 0.5));
View Full Code Here

Examples of com.opengamma.analytics.math.interpolation.PSplineFitter

    final int[] nKnots = new int[] {8, 20 };
    final int[] degree = new int[] {3, 3 };
    final int[] diff = new int[] {2, 2 };
    final double[] lambda = new double[] {0.1, 0.3 };

    final PSplineFitter splineFitter = new PSplineFitter();
    final GeneralizedLeastSquareResults<double[]> res = splineFitter.solve(tk, vols, sigmas, new double[] {0.0, 0.0 }, new double[] {2.0, 3.0 }, nKnots, degree, lambda, diff);

    System.out.println(res.getChiSq());
    final Function1D<double[], Double> func = res.getFunction();

    final Function<Double, Double> temp2 = new Function<Double, Double>() {
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.