public virtual void sensitivity_multi_combined_bond_curve() { CrossGammaParameterSensitivities sensiComputed = CENTRAL.calculateCrossGammaIntraCurve(RatesProviderDataSets.MULTI_BOND_COMBINED, this.sensiCombinedFnBond); DoubleArray timesUsL3 = RatesProviderDataSets.TIMES_2; DoubleArray timesUsRepo = RatesProviderDataSets.TIMES_1; DoubleArray timesUsIssuer1 = RatesProviderDataSets.TIMES_3; DoubleArray timesUsIssuer2 = RatesProviderDataSets.TIMES_2; assertEquals(sensiComputed.size(), 4); DoubleMatrix s1 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; assertEquals(s1.columnCount(), timesUsL3.size()); for (int i = 0; i < timesUsL3.size(); i++) { for (int j = 0; j < timesUsL3.size(); j++) { double expected = 2d * timesUsL3.get(i) * timesUsL3.get(j) * 3d * 3d; assertEquals(s1.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s2 = sensiComputed.getSensitivity(RatesProviderDataSets.US_REPO_CURVE_NAME, USD).Sensitivity; assertEquals(s2.columnCount(), timesUsRepo.size()); for (int i = 0; i < timesUsRepo.size(); i++) { for (int j = 0; j < timesUsRepo.size(); j++) { double expected = 2d * timesUsRepo.get(i) * timesUsRepo.get(j); assertEquals(s2.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s3 = sensiComputed.getSensitivity(RatesProviderDataSets.US_ISSUER_CURVE_1_NAME, USD).Sensitivity; assertEquals(s3.columnCount(), timesUsIssuer1.size()); for (int i = 0; i < timesUsIssuer1.size(); i++) { for (int j = 0; j < timesUsIssuer1.size(); j++) { double expected = 2d * timesUsIssuer1.get(i) * timesUsIssuer1.get(j); assertEquals(s3.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s4 = sensiComputed.getSensitivity(RatesProviderDataSets.US_ISSUER_CURVE_2_NAME, USD).Sensitivity; assertEquals(s4.columnCount(), timesUsIssuer2.size()); for (int i = 0; i < timesUsIssuer2.size(); i++) { for (int j = 0; j < timesUsIssuer2.size(); j++) { double expected = 2d * timesUsIssuer2.get(i) * timesUsIssuer2.get(j); assertEquals(s4.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 20d); } } }
public virtual void sensitivity_intra_multi_curve() { CrossGammaParameterSensitivities sensiComputed = CENTRAL.calculateCrossGammaIntraCurve(RatesProviderDataSets.MULTI_CPI_USD, this.sensiFn); DoubleArray times1 = RatesProviderDataSets.TIMES_1; DoubleArray times2 = RatesProviderDataSets.TIMES_2; DoubleArray times3 = RatesProviderDataSets.TIMES_3; DoubleArray times4 = RatesProviderDataSets.TIMES_4; assertEquals(sensiComputed.size(), 4); DoubleMatrix s1 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_DSC_NAME, USD).Sensitivity; assertEquals(s1.columnCount(), times1.size()); for (int i = 0; i < times1.size(); i++) { for (int j = 0; j < times1.size(); j++) { double expected = 8d * times1.get(i) * times1.get(j); assertEquals(s1.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s2 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; assertEquals(s2.columnCount(), times2.size()); for (int i = 0; i < times2.size(); i++) { for (int j = 0; j < times2.size(); j++) { double expected = 2d * times2.get(i) * times2.get(j); assertEquals(s2.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS); } } DoubleMatrix s3 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L6_NAME, USD).Sensitivity; assertEquals(s3.columnCount(), times3.size()); for (int i = 0; i < times3.size(); i++) { for (int j = 0; j < times3.size(); j++) { double expected = 2d * times3.get(i) * times3.get(j); assertEquals(s3.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS); } } DoubleMatrix s4 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_CPI_NAME, USD).Sensitivity; assertEquals(s4.columnCount(), times4.size()); for (int i = 0; i < times4.size(); i++) { for (int j = 0; j < times4.size(); j++) { double expected = 2d * times4.get(i) * times4.get(j); assertEquals(s4.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS); } } }
public virtual void sensitivity_cross_multi_curve_empty() { CrossGammaParameterSensitivities sensiComputed = CENTRAL.calculateCrossGammaCrossCurve(RatesProviderDataSets.MULTI_CPI_USD, this.sensiModFn); DoubleArray times2 = RatesProviderDataSets.TIMES_2; DoubleArray times3 = RatesProviderDataSets.TIMES_3; int paramsTotal = times2.size() + times3.size(); double[] timesTotal = new double[paramsTotal]; Array.Copy(times2.toArray(), 0, timesTotal, 0, times2.size()); Array.Copy(times3.toArray(), 0, timesTotal, times2.size(), times3.size()); assertEquals(sensiComputed.size(), 2); DoubleMatrix s2 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; assertEquals(s2.columnCount(), paramsTotal); for (int i = 0; i < times2.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times2.get(i) * timesTotal[j]; assertEquals(s2.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS); } } DoubleMatrix s3 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L6_NAME, USD).Sensitivity; assertEquals(s3.columnCount(), paramsTotal); for (int i = 0; i < times3.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times3.get(i) * timesTotal[j]; assertEquals(s3.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS); } } Optional <CrossGammaParameterSensitivity> oisSensi = sensiComputed.findSensitivity(RatesProviderDataSets.USD_DSC_NAME, USD); assertFalse(oisSensi.Present); Optional <CrossGammaParameterSensitivity> priceIndexSensi = sensiComputed.findSensitivity(RatesProviderDataSets.USD_CPI_NAME, USD); assertFalse(priceIndexSensi.Present); }
public virtual void sensitivity_multi_combined_curve() { CrossGammaParameterSensitivities sensiCrossComputed = CENTRAL.calculateCrossGammaCrossCurve(RatesProviderDataSets.MULTI_CPI_USD_COMBINED, this.sensiCombinedFn); DoubleArray times1 = RatesProviderDataSets.TIMES_1; // ois DoubleArray times2 = RatesProviderDataSets.TIMES_2; // l3 DoubleArray times3 = RatesProviderDataSets.TIMES_3; // l6 DoubleArray times4 = RatesProviderDataSets.TIMES_4; // cpi int paramsTotal = times1.size() + times2.size() + times3.size() + times4.size(); double[] timesTotal = new double[paramsTotal]; DoubleArray times1Twice = times1.multipliedBy(2d); Array.Copy(times4.toArray(), 0, timesTotal, 0, times4.size()); Array.Copy(times1Twice.toArray(), 0, timesTotal, times4.size(), times1.size()); Array.Copy(times2.toArray(), 0, timesTotal, times1.size() + times4.size(), times2.size()); Array.Copy(times3.toArray(), 0, timesTotal, times1.size() + times2.size() + times4.size(), times3.size()); assertEquals(sensiCrossComputed.size(), 4); DoubleMatrix s1 = sensiCrossComputed.getSensitivity(RatesProviderDataSets.USD_DSC_NAME, USD).Sensitivity; assertEquals(s1.columnCount(), paramsTotal); for (int i = 0; i < times1.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 4d * times1.get(i) * timesTotal[j]; assertEquals(s1.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s2 = sensiCrossComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; assertEquals(s2.columnCount(), paramsTotal); for (int i = 0; i < times2.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 8d * times2.get(i) * timesTotal[j]; assertEquals(s2.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s3 = sensiCrossComputed.getSensitivity(RatesProviderDataSets.USD_L6_NAME, USD).Sensitivity; assertEquals(s3.columnCount(), paramsTotal); for (int i = 0; i < times3.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times3.get(i) * timesTotal[j]; assertEquals(s3.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s4 = sensiCrossComputed.getSensitivity(RatesProviderDataSets.USD_CPI_NAME, USD).Sensitivity; assertEquals(s4.columnCount(), paramsTotal); for (int i = 0; i < times4.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times4.get(i) * timesTotal[j]; assertEquals(s4.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 20d); } } CrossGammaParameterSensitivities sensiIntraComputed = CENTRAL.calculateCrossGammaIntraCurve(RatesProviderDataSets.MULTI_CPI_USD_COMBINED, this.sensiCombinedFn); DoubleMatrix s1Intra = sensiIntraComputed.getSensitivity(RatesProviderDataSets.USD_DSC_NAME, USD).Sensitivity; DoubleMatrix s2Intra = sensiIntraComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; DoubleMatrix s3Intra = sensiIntraComputed.getSensitivity(RatesProviderDataSets.USD_L6_NAME, USD).Sensitivity; DoubleMatrix s4Intra = sensiIntraComputed.getSensitivity(RatesProviderDataSets.USD_CPI_NAME, USD).Sensitivity; int offsetOis = times4.size(); for (int i = 0; i < times1.size(); i++) { for (int j = 0; j < times1.size(); j++) { assertEquals(s1Intra.get(i, j), s1.get(i, offsetOis + j), TOL); } } int offset3m = times4.size() + times1.size(); for (int i = 0; i < times2.size(); i++) { for (int j = 0; j < times2.size(); j++) { assertEquals(s2Intra.get(i, j), s2.get(i, offset3m + j), TOL); } } int offset6m = times4.size() + times1.size() + times2.size(); for (int i = 0; i < times3.size(); i++) { for (int j = 0; j < times3.size(); j++) { assertEquals(s3Intra.get(i, j), s3.get(i, offset6m + j), TOL); } } for (int i = 0; i < times4.size(); i++) { for (int j = 0; j < times4.size(); j++) { assertEquals(s4Intra.get(i, j), s4.get(i, j), TOL); } } }
public virtual void sensitivity_cross_multi_curve() { CrossGammaParameterSensitivities sensiComputed = CENTRAL.calculateCrossGammaCrossCurve(RatesProviderDataSets.MULTI_CPI_USD, this.sensiFn); DoubleArray times1 = RatesProviderDataSets.TIMES_1; DoubleArray times2 = RatesProviderDataSets.TIMES_2; DoubleArray times3 = RatesProviderDataSets.TIMES_3; DoubleArray times4 = RatesProviderDataSets.TIMES_4; int paramsTotal = times1.size() + times2.size() + times3.size() + times4.size(); double[] timesTotal = new double[paramsTotal]; DoubleArray times1Twice = times1.multipliedBy(2d); Array.Copy(times4.toArray(), 0, timesTotal, 0, times4.size()); Array.Copy(times1Twice.toArray(), 0, timesTotal, times4.size(), times1.size()); Array.Copy(times2.toArray(), 0, timesTotal, times1.size() + times4.size(), times2.size()); Array.Copy(times3.toArray(), 0, timesTotal, times1.size() + times2.size() + times4.size(), times3.size()); assertEquals(sensiComputed.size(), 4); DoubleMatrix s1 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_DSC_NAME, USD).Sensitivity; assertEquals(s1.columnCount(), paramsTotal); for (int i = 0; i < times1.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 4d * times1.get(i) * timesTotal[j]; assertEquals(s1.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s2 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L3_NAME, USD).Sensitivity; assertEquals(s2.columnCount(), paramsTotal); for (int i = 0; i < times2.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times2.get(i) * timesTotal[j]; assertEquals(s2.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s3 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_L6_NAME, USD).Sensitivity; assertEquals(s3.columnCount(), paramsTotal); for (int i = 0; i < times3.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times3.get(i) * timesTotal[j]; assertEquals(s3.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 10d); } } DoubleMatrix s4 = sensiComputed.getSensitivity(RatesProviderDataSets.USD_CPI_NAME, USD).Sensitivity; assertEquals(s4.columnCount(), paramsTotal); for (int i = 0; i < times4.size(); i++) { for (int j = 0; j < paramsTotal; j++) { double expected = 2d * times4.get(i) * timesTotal[j]; assertEquals(s4.get(i, j), expected, Math.Max(Math.Abs(expected), 1d) * EPS * 20d); } } }