/** * Creates an instance. * <p> * The epsilon is the parameter used in {@link NonLinearLeastSquare}, where the iteration stops when certain * quantities are smaller than this parameter. * * @param pricer the cap pricer * @param sabrPricer the SABR cap pricer * @param epsilon the epsilon parameter * @param referenceData the reference data * @return the instance */ public static SabrIborCapletFloorletVolatilityCalibrator of( VolatilityIborCapFloorLegPricer pricer, SabrIborCapFloorLegPricer sabrPricer, double epsilon, ReferenceData referenceData) { NonLinearLeastSquare solver = new NonLinearLeastSquare(SV_COMMONS, OG_ALGEBRA, epsilon); return new SabrIborCapletFloorletVolatilityCalibrator(pricer, sabrPricer, solver, referenceData); }
/** * Creates an instance. * <p> * The epsilon is the parameter used in {@link NonLinearLeastSquare}, where the iteration stops when certain * quantities are smaller than this parameter. * * @param pricer the cap/floor pricer to convert quoted volatilities to prices * @param sabrPeriodPricer the SABR pricer * @param epsilon the epsilon parameter * @param referenceData the reference data * @return the instance */ public static SabrIborCapletFloorletVolatilityBootstrapper of( VolatilityIborCapFloorLegPricer pricer, SabrIborCapletFloorletPeriodPricer sabrPeriodPricer, double epsilon, ReferenceData referenceData) { NonLinearLeastSquare solver = new NonLinearLeastSquare(SV_COMMONS, OG_ALGEBRA, epsilon); return new SabrIborCapletFloorletVolatilityBootstrapper(pricer, sabrPeriodPricer, solver, referenceData); }
public void solveExactWithoutGradientTest() { final DoubleArray start = DoubleArray.of(1.2, 0.8, -0.2, -0.3); final NonLinearLeastSquare ls = new NonLinearLeastSquare(); final LeastSquareResults result = ls.solve(X, Y, SIGMA, PARAM_FUNCTION, start); assertEquals(0.0, result.getChiSq(), 1e-8); assertEquals(1.0, result.getFitParameters().get(0), 1e-8); assertEquals(1.0, result.getFitParameters().get(1), 1e-8); assertEquals(0.0, result.getFitParameters().get(2), 1e-8); assertEquals(0.0, result.getFitParameters().get(3), 1e-8); }
public void solveRandomNoiseTest() { final MatrixAlgebra ma = new OGMatrixAlgebra(); final double[] y = new double[20]; for (int i = 0; i < 20; i++) { y[i] = Y.get(i) + SIGMA.get(i) * NORMAL.nextRandom(); } final DoubleArray start = DoubleArray.of(0.7, 1.4, 0.2, -0.3); final NonLinearLeastSquare ls = new NonLinearLeastSquare(); final LeastSquareResults res = ls.solve(X, DoubleArray.copyOf(y), SIGMA, PARAM_FUNCTION, PARAM_GRAD, start); final double chiSqDoF = res.getChiSq() / 16; assertTrue(chiSqDoF > 0.25); assertTrue(chiSqDoF < 3.0); final DoubleArray trueValues = DoubleArray.of(1, 1, 0, 0); final DoubleArray delta = (DoubleArray) ma.subtract(res.getFitParameters(), trueValues); final LUDecompositionCommons decmp = new LUDecompositionCommons(); final LUDecompositionResult decmpRes = decmp.apply(res.getCovariance()); final DoubleMatrix invCovariance = decmpRes.solve(DoubleMatrix.identity(4)); double z = ma.getInnerProduct(delta, ma.multiply(invCovariance, delta)); z = Math.sqrt(z); assertTrue(z < 3.0); }
public void smallPertubationTest() { final MatrixAlgebra ma = new OGMatrixAlgebra(); final double[] dy = new double[20]; for (int i = 0; i < 20; i++) { dy[i] = 0.1 * SIGMA.get(i) * NORMAL.nextRandom(); } final DoubleArray deltaY = DoubleArray.copyOf(dy); final DoubleArray solution = DoubleArray.of(1.0, 1.0, 0.0, 0.0); final NonLinearLeastSquare ls = new NonLinearLeastSquare(); final DoubleMatrix res = ls.calInverseJacobian(SIGMA, FUNCTION, GRAD, solution); final DoubleArray deltaParms = (DoubleArray) ma.multiply(res, deltaY); final DoubleArray y = (DoubleArray) ma.add(Y, deltaY); final LeastSquareResults lsRes = ls.solve(X, y, SIGMA, PARAM_FUNCTION, PARAM_GRAD, solution); final DoubleArray trueDeltaParms = (DoubleArray) ma.subtract(lsRes.getFitParameters(), solution); assertEquals(trueDeltaParms.get(0), deltaParms.get(0), 5e-5); assertEquals(trueDeltaParms.get(1), deltaParms.get(1), 5e-5); assertEquals(trueDeltaParms.get(2), deltaParms.get(2), 5e-5); assertEquals(trueDeltaParms.get(3), deltaParms.get(3), 5e-5); }