public virtual void test_parameterSensitivity_withSpread_full() { int periodPerYear = 2; double spread = 0.0011; // 11 bp ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double sensiValue = 25d; ZeroRateSensitivity point = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); point = point.multipliedBy(sensiValue); CurrencyParameterSensitivities sensiObject = test.parameterSensitivity(point); assertEquals(sensiObject.Sensitivities.size(), 1); DoubleArray sensi0 = sensiObject.Sensitivities.get(0).Sensitivity; double shift = 1.0E-6; for (int i = 0; i < X.size(); i++) { DoubleArray yP = Y.with(i, Y.get(i) + shift); InterpolatedNodalCurve curveP = InterpolatedNodalCurve.of(META_ZERO_PERIODIC, X, yP, INTERPOLATOR); double dfP = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, curveP).discountFactorWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); DoubleArray yM = Y.with(i, Y.get(i) - shift); InterpolatedNodalCurve curveM = InterpolatedNodalCurve.of(META_ZERO_PERIODIC, X, yM, INTERPOLATOR); double dfM = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, curveM).discountFactorWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); assertEquals(sensi0.get(i), sensiValue * (dfP - dfM) / (2 * shift), TOLERANCE_DELTA_FD, "With spread - " + i); } }
//------------------------------------------------------------------------- // constructs an interpolated nodal curve internal InterpolatedNodalCurve createCurve(LocalDate date, IList <LoadedCurveNode> curveNodes) { // copy and sort IList <LoadedCurveNode> nodes = new List <LoadedCurveNode>(curveNodes); nodes.sort(System.Collections.IComparer.naturalOrder()); // build each node double[] xValues = new double[nodes.Count]; double[] yValues = new double[nodes.Count]; IList <ParameterMetadata> pointsMetadata = new List <ParameterMetadata>(nodes.Count); for (int i = 0; i < nodes.Count; i++) { LoadedCurveNode point = nodes[i]; double yearFraction = dayCount.yearFraction(date, point.Date); xValues[i] = yearFraction; yValues[i] = point.Value; ParameterMetadata pointMetadata = LabelDateParameterMetadata.of(point.Date, point.Label); pointsMetadata.Add(pointMetadata); } // create metadata CurveMetadata curveMetadata = DefaultCurveMetadata.builder().curveName(curveName).xValueType(xValueType).yValueType(yValueType).dayCount(dayCount).parameterMetadata(pointsMetadata).build(); return(InterpolatedNodalCurve.builder().metadata(curveMetadata).xValues(DoubleArray.copyOf(xValues)).yValues(DoubleArray.copyOf(yValues)).interpolator(interpolator).extrapolatorLeft(extrapolatorLeft).extrapolatorRight(extrapolatorRight).build()); }
static BondFuturesJpyEnd2EndTest() { for (int i = 0; i < NB_UND_BONDS; ++i) { PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE[i], MATURITY_DATE[i], Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID[i])).dayCount(DAY_COUNT).fixedRate(UND_RATES[i] * ONE_PERCENT).legalEntityId(ISSUER_ID).currency(JPY).notional(NOTIONAL).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS).yieldConvention(YIELD_CONVENTION).build(); UND_BOND[i] = product; } UND_BOND_SEP = new FixedCouponBond[NB_UND_BONDS - 2]; Array.Copy(UND_BOND, 2, UND_BOND_SEP, 0, NB_UND_BONDS - 2); UND_BOND_JUN = new FixedCouponBond[NB_UND_BONDS - 1]; Array.Copy(UND_BOND, 1, UND_BOND_JUN, 0, NB_UND_BONDS - 1); double[] timeIssuer = new double[] { 0.25136612021857924, 0.4972677595628415, 1.0139980537465378, 2.013998053746538, 2.857833670184894, 3.857833670184894, 4.860655737704918, 5.857833670184894, 7.104409012650647, 7.857833670184894, 8.857923497267759, 9.863313122239688, 14.857833670184894, 19.857833670184895, 29.857833670184895, 39.11262819073284 }; double[] rateIssuer = new double[] { -0.0013117084834668065, -0.0010851901424876163, -0.0020906775838723216, -0.0022137102045172784, -0.0022695678374162888, -0.0023424568490920798, -0.0021603059162879916, -0.0021667343131861225, -0.0018285921969274823, -0.001355094018965514, -6.763044056712535E-4, 1.9555294306801752E-4, 0.003944125562941363, 0.008054233458390252, 0.012276105941434846, 0.013537766297065804 }; double[] timeRepo = new double[] { 0.00273224043715847, 0.01912568306010929, 0.040983606557377046, 0.05737704918032787, 0.07923497267759563, 0.2459016393442623, 0.4972677595628415, 1.0002994236095515 }; double[] rateRepo = new double[] { 2.599662058772748E-4, -8.403529976927196E-4, -0.0010105103936934236, -0.0011506617573950931, -0.0012708071334455143, -0.00146106683851595, -0.0014710815100096722, -0.001481096281798276 }; CurveMetadata metaIssuer = Curves.zeroRates(ISSUER_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curveIssuer = InterpolatedNodalCurve.of(metaIssuer, DoubleArray.copyOf(timeIssuer), DoubleArray.copyOf(rateIssuer), INTERPOLATOR); DiscountFactors dscIssuer = ZeroRateDiscountFactors.of(JPY, VALUATION, curveIssuer); CurveMetadata metaRepo = Curves.zeroRates(REPO_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of(metaRepo, DoubleArray.copyOf(timeRepo), DoubleArray.copyOf(rateRepo), INTERPOLATOR); DiscountFactors dscRepo = ZeroRateDiscountFactors.of(JPY, VALUATION, curve); LED_PROVIDER = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, JPY), dscIssuer)).issuerCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO, JPY), dscRepo)).repoCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_REPO)).build(); }
private void assertUsdDisc(Curve curve) { assertTrue(curve is InterpolatedNodalCurve); InterpolatedNodalCurve nodalCurve = (InterpolatedNodalCurve)curve; assertEquals(nodalCurve.Metadata.CurveName, CurveName.of("USD-Disc")); LocalDate valuationDate = LocalDate.of(2009, 7, 31); LocalDate[] nodeDates = new LocalDate[] { LocalDate.of(2009, 11, 6), LocalDate.of(2010, 2, 8), LocalDate.of(2010, 8, 6), LocalDate.of(2011, 8, 8), LocalDate.of(2012, 8, 8), LocalDate.of(2014, 8, 6), LocalDate.of(2019, 8, 7) }; string[] labels = new string[] { "3M", "6M", "1Y", "2Y", "3Y", "5Y", "10Y" }; for (int i = 0; i < nodalCurve.XValues.size(); i++) { LocalDate nodeDate = nodeDates[i]; double actualYearFraction = nodalCurve.XValues.get(i); double expectedYearFraction = getYearFraction(valuationDate, nodeDate); assertThat(actualYearFraction).isCloseTo(expectedYearFraction, offset(TOLERANCE)); ParameterMetadata nodeMetadata = nodalCurve.Metadata.ParameterMetadata.get().get(i); assertEquals(nodeMetadata.Label, labels[i]); } DoubleArray expectedYValues = DoubleArray.of(0.001763775, 0.002187884, 0.004437206, 0.011476741, 0.017859057, 0.026257102, 0.035521988); assertEquals(nodalCurve.YValues, expectedYValues); }
//------------------------------------------------------------------------- public virtual void test_load_all_curves() { ListMultimap <LocalDate, RatesCurveGroup> allGroups = RatesCurvesCsvLoader.loadAllDates(ResourceLocator.of(GROUPS_1), ResourceLocator.of(SETTINGS_1), ImmutableList.of(ResourceLocator.of(CURVES_1), ResourceLocator.of(CURVES_2), ResourceLocator.of(CURVES_3))); assertEquals(allGroups.size(), 2); assertCurves(allGroups.get(CURVE_DATE)); IList <RatesCurveGroup> curves3 = allGroups.get(CURVE_DATE_CURVES_3); assertEquals(curves3.Count, 1); RatesCurveGroup group = curves3[0]; // All curve points are set to 0 in test data to ensure these are really different curve instances Curve usdDisc = group.findDiscountCurve(Currency.USD).get(); InterpolatedNodalCurve usdDiscNodal = (InterpolatedNodalCurve)usdDisc; assertEquals(usdDiscNodal.Metadata.CurveName, CurveName.of("USD-Disc")); assertTrue(usdDiscNodal.YValues.equalZeroWithTolerance(0d)); Curve usd3ml = group.findForwardCurve(IborIndices.USD_LIBOR_3M).get(); InterpolatedNodalCurve usd3mlNodal = (InterpolatedNodalCurve)usd3ml; assertEquals(usd3mlNodal.Metadata.CurveName, CurveName.of("USD-3ML")); assertTrue(usd3mlNodal.YValues.equalZeroWithTolerance(0d)); }
private void assertUsd3ml(Curve curve) { assertTrue(curve is InterpolatedNodalCurve); InterpolatedNodalCurve nodalCurve = (InterpolatedNodalCurve)curve; assertEquals(nodalCurve.Metadata.CurveName, CurveName.of("USD-3ML")); LocalDate valuationDate = LocalDate.of(2009, 7, 31); LocalDate[] nodeDates = new LocalDate[] { LocalDate.of(2009, 11, 4), LocalDate.of(2010, 8, 4), LocalDate.of(2011, 8, 4), LocalDate.of(2012, 8, 6), LocalDate.of(2014, 8, 5), LocalDate.of(2019, 8, 6) }; string[] labels = new string[] { "3M", "1Y", "2Y", "3Y", "5Y", "10Y" }; for (int i = 0; i < nodalCurve.XValues.size(); i++) { LocalDate nodeDate = nodeDates[i]; double actualYearFraction = nodalCurve.XValues.get(i); double expectedYearFraction = getYearFraction(valuationDate, nodeDate); assertThat(actualYearFraction).isCloseTo(expectedYearFraction, offset(TOLERANCE)); ParameterMetadata nodeMetadata = nodalCurve.Metadata.ParameterMetadata.get().get(i); assertEquals(nodeMetadata.Label, labels[i]); } DoubleArray expectedYValues = DoubleArray.of(0.007596889, 0.008091541, 0.015244398, 0.021598026, 0.029984216, 0.039245812); assertEquals(nodalCurve.YValues, expectedYValues); }
// modified sensitivity function - CombinedCurve involved private CurrencyParameterSensitivities sensiCombinedFnBond(ImmutableLegalEntityDiscountingProvider provider) { CurrencyParameterSensitivities sensi = CurrencyParameterSensitivities.empty(); double sum = sumCombine(provider); // repo curves ImmutableMap <Pair <RepoGroup, Currency>, DiscountFactors> mapCurrency = provider.RepoCurves; foreach (KeyValuePair <Pair <RepoGroup, Currency>, DiscountFactors> entry in mapCurrency.entrySet()) { CombinedCurve curveComb = (CombinedCurve)getCurve(entry.Value); InterpolatedNodalCurve baseCurveInt = checkInterpolated(curveComb.BaseCurve); InterpolatedNodalCurve spreadCurveInt = checkInterpolated(curveComb.SpreadCurve); sensi = sensi.combinedWith(CurrencyParameterSensitivity.of(baseCurveInt.Name, USD, DoubleArray.of(baseCurveInt.ParameterCount, i => 2d * sum * baseCurveInt.XValues.get(i)))); sensi = sensi.combinedWith(CurrencyParameterSensitivity.of(spreadCurveInt.Name, USD, DoubleArray.of(spreadCurveInt.ParameterCount, i => 2d * sum * spreadCurveInt.XValues.get(i)))); } // issuer curves ImmutableMap <Pair <LegalEntityGroup, Currency>, DiscountFactors> mapIndex = provider.IssuerCurves; foreach (KeyValuePair <Pair <LegalEntityGroup, Currency>, DiscountFactors> entry in mapIndex.entrySet()) { CombinedCurve curveComb = (CombinedCurve)getCurve(entry.Value); InterpolatedNodalCurve baseCurveInt = checkInterpolated(curveComb.BaseCurve); InterpolatedNodalCurve spreadCurveInt = checkInterpolated(curveComb.SpreadCurve); sensi = sensi.combinedWith(CurrencyParameterSensitivity.of(baseCurveInt.Name, USD, DoubleArray.of(baseCurveInt.ParameterCount, i => 2d * sum * baseCurveInt.XValues.get(i)))); sensi = sensi.combinedWith(CurrencyParameterSensitivity.of(spreadCurveInt.Name, USD, DoubleArray.of(spreadCurveInt.ParameterCount, i => 2d * sum * spreadCurveInt.XValues.get(i)))); } return(sensi); }
public virtual void relative() { IList <LabelDateParameterMetadata> nodeMetadata = ImmutableList.of(LabelDateParameterMetadata.of(date(2011, 3, 8), TNR_1M), LabelDateParameterMetadata.of(date(2011, 5, 8), TNR_3M), LabelDateParameterMetadata.of(date(2011, 8, 8), TNR_6M)); // This should create 4 scenarios. Scenario zero has no shifts and scenario 3 doesn't have shifts on all nodes PointShifts shift = PointShifts.builder(ShiftType.RELATIVE).addShift(1, TNR_1W, 0.1).addShift(1, TNR_1M, 0.2).addShift(1, TNR_3M, 0.3).addShift(2, TNR_1M, 0.4).addShift(2, TNR_3M, 0.5).addShift(2, TNR_6M, 0.6).addShift(3, TNR_3M, 0.7).build(); Curve curve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("curve"), DayCounts.ACT_365F, nodeMetadata), DoubleArray.of(1, 2, 3), DoubleArray.of(5, 6, 7), INTERPOLATOR); MarketDataBox <ParameterizedData> shiftedCurveBox = shift.applyTo(MarketDataBox.ofSingleValue(curve), REF_DATA); Curve scenario1Curve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("curve"), DayCounts.ACT_365F, nodeMetadata), DoubleArray.of(1, 2, 3), DoubleArray.of(6, 7.8, 7), INTERPOLATOR); Curve scenario2Curve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("curve"), DayCounts.ACT_365F, nodeMetadata), DoubleArray.of(1, 2, 3), DoubleArray.of(7, 9, 11.2), INTERPOLATOR); Curve scenario3Curve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("curve"), DayCounts.ACT_365F, nodeMetadata), DoubleArray.of(1, 2, 3), DoubleArray.of(5, 10.2, 7), INTERPOLATOR); // Scenario zero has no perturbations so the expected curve is the same as the input IList <Curve> expectedCurves = ImmutableList.of(curve, scenario1Curve, scenario2Curve, scenario3Curve); for (int scenarioIndex = 0; scenarioIndex < 4; scenarioIndex++) { // Check every point from 0 to 4 in steps of 0.1 is the same on the bumped curve and the expected curve for (int xIndex = 0; xIndex <= 40; xIndex++) { double xValue = xIndex * 0.1; Curve expectedCurve = expectedCurves[scenarioIndex]; Curve shiftedCurve = (Curve)shiftedCurveBox.getValue(scenarioIndex); double shiftedY = shiftedCurve.yValue(xValue); double expectedY = expectedCurve.yValue(xValue); assertThat(shiftedY).overridingErrorMessage("Curve differed in scenario %d at x value %f, expected %f, actual %f", scenarioIndex, xValue, expectedY, shiftedY).isEqualTo(expectedY); } } }
static DiscountingNotionalExchangePricerTest() { DoubleArray time_gbp = DoubleArray.of(0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0); DoubleArray rate_gbp = DoubleArray.of(0.0160, 0.0135, 0.0160, 0.0185, 0.0185, 0.0195, 0.0200, 0.0210); DISCOUNT_CURVE_GBP = InterpolatedNodalCurve.of(Curves.zeroRates("GBP-Discount", ACT_ACT_ISDA), time_gbp, rate_gbp, INTERPOLATOR); }
private DoubleArray sensitivityDeposit(InterpolatedNodalCurve curve, double termDepositYearFraction, int index, double fixedRate) { int nNode = curve.ParameterCount; double[] sensi = new double[nNode]; sensi[index] = curve.XValues.get(index) * (1d + fixedRate * termDepositYearFraction) / termDepositYearFraction; return(DoubleArray.ofUnsafe(sensi)); }
public virtual void test_loadAllDates() { LocalDate sampleDate = ALL_DATES[3]; // 2017-04-21 ImmutableList <LocalDate> expDates = ImmutableList.of(LocalDate.of(2017, 0x7, 21), LocalDate.of(2017, 10, 0x7), LocalDate.of(2018, 4, 13), LocalDate.of(2019, 4, 12), LocalDate.of(2020, 3, 20), LocalDate.of(2021, 3, 19), LocalDate.of(2022, 3, 19), LocalDate.of(2023, 3, 17), LocalDate.of(2024, 6, 17), LocalDate.of(2025, 3, 18), LocalDate.of(2026, 3, 20), LocalDate.of(2027, 3, 20), LocalDate.of(2031, 12, 19), LocalDate.of(2037, 3, 17), LocalDate.of(2047, 3, 17), LocalDate.of(2056, 3, 17)); ImmutableList <string> expTenors = ImmutableList.of("3M", "6M", "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "15Y", "20Y", "30Y", "40Y"); RepoGroup repoGroup = RepoGroup.of("JP-REPO"); DoubleArray expRepoXValues = DoubleArray.of(3, n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n))); DoubleArray expRepoYValues = DoubleArray.of(-0.0019521, -0.0016021, -0.0022521); ImmutableList <LabelDateParameterMetadata> expRepoMetadata = IntStream.range(0, 3).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList()); LegalEntityGroup legalEntityGroup = LegalEntityGroup.of("JP-GOVT"); DoubleArray expIssuerXValues = DoubleArray.of(expDates.size(), n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n))); DoubleArray expIssuerYValues = DoubleArray.of(-0.0019511690511744527, -0.001497422302092893, -0.0021798583657932176, -0.002215700360912938, -0.0021722324679574866, -0.001922059591219172, -0.0015461646763548528, -0.0014835851245462084, -0.001118669580570464, -5.476767138782941E-4, -2.2155596172855965E-4, 2.0333291172821893E-5, 0.00284500423293463, 0.005876533417933958, 0.007957581583531789, 0.009134630405512047); ImmutableList <LabelDateParameterMetadata> expIssuerMetadata = IntStream.range(0, expDates.size()).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList()); ImmutableListMultimap <LocalDate, LegalEntityCurveGroup> allCurves = LegalEntityRatesCurvesCsvLoader.loadAllDates(ResourceLocator.of(GROUPS), ResourceLocator.of(SETTINGS), ImmutableList.of(ResourceLocator.of(CURVES_1), ResourceLocator.of(CURVES_2))); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: assertTrue(allCurves.Keys.containsAll(ALL_DATES)); ImmutableList <LegalEntityCurveGroup> groups = allCurves.get(sampleDate); assertEquals(groups.size(), 2); // group 0 LegalEntityCurveGroup group0 = groups.get(0); assertEquals(group0.Name, CurveGroupName.of("Default1")); // repo assertEquals(group0.RepoCurves.size(), 1); Curve repoCurve = group0.RepoCurves.get(Pair.of(repoGroup, JPY)); InterpolatedNodalCurve expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-1"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(repoCurve, expectedRepoCurve); // issuer assertEquals(group0.IssuerCurves.size(), 2); Curve issuerCurve = group0.IssuerCurves.get(Pair.of(legalEntityGroup, JPY)); InterpolatedNodalCurve expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-1"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(issuerCurve, expectedIssuerCurve); Curve usIssuerCurve = group0.IssuerCurves.get(Pair.of(LegalEntityGroup.of("US-GOVT"), USD)); expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("US-GOVT"), ACT_360, expIssuerMetadata), DoubleArray.of(expDates.size(), n => ACT_360.relativeYearFraction(sampleDate, expDates.get(n))), expIssuerYValues, CurveInterpolators.NATURAL_SPLINE, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(usIssuerCurve, expectedIssuerCurve); // group 1 LegalEntityCurveGroup group1 = groups.get(1); assertEquals(group1.Name, CurveGroupName.of("Default2")); // repo repoCurve = group1.RepoCurves.get(Pair.of(repoGroup, JPY)); expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-2"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR); assertEquals(repoCurve, expectedRepoCurve); // issuer assertEquals(group1.IssuerCurves.size(), 1); issuerCurve = group1.IssuerCurves.get(Pair.of(legalEntityGroup, JPY)); expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-2"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR); assertEquals(issuerCurve, expectedIssuerCurve); }
static DiscountingFraProductPricerTest() { CurveInterpolator interp = CurveInterpolators.DOUBLE_QUADRATIC; DoubleArray time_gbp = DoubleArray.of(0.0, 0.1, 0.25, 0.5, 0.75, 1.0, 2.0); DoubleArray rate_gbp = DoubleArray.of(0.0160, 0.0165, 0.0155, 0.0155, 0.0155, 0.0150, 0.014); InterpolatedNodalCurve dscCurve = InterpolatedNodalCurve.of(Curves.zeroRates("GBP-Discount", DAY_COUNT), time_gbp, rate_gbp, interp); DoubleArray time_index = DoubleArray.of(0.0, 0.25, 0.5, 1.0); DoubleArray rate_index = DoubleArray.of(0.0180, 0.0180, 0.0175, 0.0165); InterpolatedNodalCurve indexCurve = InterpolatedNodalCurve.of(Curves.zeroRates("GBP-GBPIBOR3M", DAY_COUNT), time_index, rate_index, interp); IMM_PROV = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, dscCurve).iborIndexCurve(GBP_LIBOR_3M, indexCurve).build(); }
public virtual void test_of_badCurve() { InterpolatedNodalCurve notYearFraction = InterpolatedNodalCurve.of(Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); InterpolatedNodalCurve notDiscountFactor = InterpolatedNodalCurve.of(Curves.zeroRates(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata noDayCountMetadata = DefaultCurveMetadata.builder().curveName(NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.DISCOUNT_FACTOR).build(); InterpolatedNodalCurve notDayCount = InterpolatedNodalCurve.of(noDayCountMetadata, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); assertThrowsIllegalArg(() => SimpleDiscountFactors.of(GBP, DATE_VAL, notYearFraction)); assertThrowsIllegalArg(() => SimpleDiscountFactors.of(GBP, DATE_VAL, notDiscountFactor)); assertThrowsIllegalArg(() => SimpleDiscountFactors.of(GBP, DATE_VAL, notDayCount)); }
private double sumSingle(InterpolatedNodalCurve interpolatedNodalCurve) { double result = 0.0; int nbNodePoints = interpolatedNodalCurve.ParameterCount; for (int i = 0; i < nbNodePoints; i++) { result += interpolatedNodalCurve.XValues.get(i) * interpolatedNodalCurve.YValues.get(i); } return(result); }
//------------------------------------------------------------------------- public virtual void coverage() { SabrIborCapletFloorletVolatilityCalibrationDefinition test1 = SabrIborCapletFloorletVolatilityCalibrationDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_365F, BETA_RHO, ALPHA_KNOTS, BETA_RHO_KNOTS, NU_KNOTS, DOUBLE_QUADRATIC, FLAT, LINEAR, HAGAN); coverImmutableBean(test1); Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knots = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, DoubleArray.of(1.1)); SabrIborCapletFloorletVolatilityCalibrationDefinition test2 = SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().betaCurve(betaCurve).dayCount(ACT_360).extrapolatorLeft(LINEAR).extrapolatorRight(FLAT).interpolator(PCHIP).index(GBP_LIBOR_3M).initialParameters(initial).name(IborCapletFloorletVolatilitiesName.of("other")).parameterCurveNodes(knots).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build(); coverBeanEquals(test1, test2); }
static CurveSensitivityUtilsJacobianTest() { Tenor[] tenors = new Tenor[] { Tenor.TENOR_1D, Tenor.TENOR_1M, Tenor.TENOR_3M, Tenor.TENOR_6M, Tenor.TENOR_1Y, Tenor.TENOR_2Y, Tenor.TENOR_3Y, Tenor.TENOR_4Y, Tenor.TENOR_5Y, Tenor.TENOR_7Y, Tenor.TENOR_10Y, Tenor.TENOR_15Y, Tenor.TENOR_20Y, Tenor.TENOR_30Y }; IList <TenorParameterMetadata> metadataList = new List <TenorParameterMetadata>(); for (int looptenor = 0; looptenor < tenors.Length; looptenor++) { metadataList.Add(TenorParameterMetadata.of(tenors[looptenor])); } DoubleArray rate_eur = DoubleArray.of(0.0160, 0.0165, 0.0155, 0.0155, 0.0155, 0.0150, 0.0150, 0.0160, 0.0165, 0.0155, 0.0155, 0.0155, 0.0150, 0.0140); InterpolatedNodalCurve curve_single_eur = InterpolatedNodalCurve.builder().metadata(DefaultCurveMetadata.builder().curveName(EUR_SINGLE_NAME).parameterMetadata(metadataList).dayCount(ACT_365F).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).build()).xValues(TIME_EUR).yValues(rate_eur).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).interpolator(CurveInterpolators.LINEAR).build(); MULTICURVE_EUR_SINGLE_INPUT = ImmutableRatesProvider.builder(VALUATION_DATE).discountCurve(EUR, curve_single_eur).iborIndexCurve(EUR_EURIBOR_6M, curve_single_eur).build(); LIST_CURVE_NAMES_1.Add(CurveParameterSize.of(EUR_SINGLE_NAME, TIME_EUR.size())); }
public virtual void test_of() { IsdaCreditCurveDefinition test = IsdaCreditCurveDefinition.of(NAME, USD, CURVE_VALUATION_DATE, ACT_ACT_ISDA, NODES, true, false); assertEquals(test.Currency, USD); assertEquals(test.CurveNodes, NODES); assertEquals(test.CurveValuationDate, CURVE_VALUATION_DATE); assertEquals(test.DayCount, ACT_ACT_ISDA); assertEquals(test.ComputeJacobian, true); assertEquals(test.StoreNodeTrade, false); DoubleArray time = DoubleArray.of(1, 2, 3); DoubleArray rate = DoubleArray.of(0.01, 0.014, 0.02); InterpolatedNodalCurve expectedCurve = InterpolatedNodalCurve.of(Curves.zeroRates(NAME, ACT_ACT_ISDA), time, rate, CurveInterpolators.PRODUCT_LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.PRODUCT_LINEAR); assertEquals(test.curve(time, rate), expectedCurve); }
public virtual void test_of_fail() { DefaultCurveMetadata metadata = DefaultCurveMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).curveName("yieldUsd").build(); InterpolatedNodalCurve curveNoDcc = InterpolatedNodalCurve.of(metadata, TIME, RATE, CurveInterpolators.PRODUCT_LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.PRODUCT_LINEAR); assertThrowsIllegalArg(() => IsdaCreditDiscountFactors.of(USD, VALUATION, curveNoDcc)); InterpolatedNodalCurve curveWrongLeft = InterpolatedNodalCurve.of(METADATA, TIME, RATE, CurveInterpolators.PRODUCT_LINEAR, CurveExtrapolators.PRODUCT_LINEAR, CurveExtrapolators.PRODUCT_LINEAR); assertThrowsIllegalArg(() => IsdaCreditDiscountFactors.of(USD, VALUATION, curveWrongLeft)); InterpolatedNodalCurve curveWrongInterp = InterpolatedNodalCurve.of(METADATA, TIME, RATE, CurveInterpolators.NATURAL_SPLINE, CurveExtrapolators.FLAT, CurveExtrapolators.PRODUCT_LINEAR); assertThrowsIllegalArg(() => IsdaCreditDiscountFactors.of(USD, VALUATION, curveWrongInterp)); InterpolatedNodalCurve curveWrongRight = InterpolatedNodalCurve.of(METADATA, TIME, RATE, CurveInterpolators.PRODUCT_LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertThrowsIllegalArg(() => IsdaCreditDiscountFactors.of(USD, VALUATION, curveWrongRight)); }
private double sumMod(ImmutableRatesProvider provider) { double result = 0.0; // Index ImmutableMap <Index, Curve> mapIndex = provider.IndexCurves; foreach (KeyValuePair <Index, Curve> entry in mapIndex.entrySet()) { if (entry.Key is IborIndex) { InterpolatedNodalCurve curveInt = checkInterpolated(entry.Value); result += sumSingle(curveInt); } } return(result); }
//------------------------------------------------------------------------- internal static ScenarioMarketData marketData(CurveName curveName) { DoubleMatrix jacobian = DoubleMatrix.ofUnsafe(new double[][] { new double[] { 0.985d, 0.01d, 0d }, new double[] { 0.01d, 0.98d, 0.01d }, new double[] { 0.005d, 0.01d, 0.99d } }); JacobianCalibrationMatrix jcm = JacobianCalibrationMatrix.of(ImmutableList.of(CurveParameterSize.of(curveName, 3)), jacobian); DoubleArray time = DoubleArray.of(0.1, 0.25, 0.5d); DoubleArray rate = DoubleArray.of(0.01, 0.015, 0.008d); Curve curve = InterpolatedNodalCurve.of(Curves.zeroRates(curveName, ACT_360).withInfo(CurveInfoType.JACOBIAN, jcm), time, rate, NATURAL_SPLINE); TestMarketDataMap md = new TestMarketDataMap(VAL_DATE, ImmutableMap.of(FORWARD_CURVE_ID, curve, QUOTE_KEY, MARKET_PRICE), ImmutableMap.of()); return(md); }
private readonly DayCount dayCount; // cached, not a property //------------------------------------------------------------------------- /// <summary> /// Creates an instance from the underlying curve. /// </summary> /// <param name="currency"> the currency </param> /// <param name="valuationDate"> the valuation date </param> /// <param name="curve"> the underlying curve </param> /// <returns> the instance </returns> public static IsdaCreditDiscountFactors of(Currency currency, LocalDate valuationDate, NodalCurve curve) { curve.Metadata.XValueType.checkEquals(YEAR_FRACTION, "Incorrect x-value type for zero-rate discount curve"); curve.Metadata.YValueType.checkEquals(ZERO_RATE, "Incorrect y-value type for zero-rate discount curve"); if (curve is InterpolatedNodalCurve) { InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve)curve; ArgChecker.isTrue(interpolatedCurve.Interpolator.Equals(CurveInterpolators.PRODUCT_LINEAR), "Interpolator must be PRODUCT_LINEAR"); ArgChecker.isTrue(interpolatedCurve.ExtrapolatorLeft.Equals(CurveExtrapolators.FLAT), "Left extrapolator must be FLAT"); ArgChecker.isTrue(interpolatedCurve.ExtrapolatorRight.Equals(CurveExtrapolators.PRODUCT_LINEAR), "Right extrapolator must be PRODUCT_LINEAR"); } else { ArgChecker.isTrue(curve is ConstantNodalCurve, "the underlying curve must be InterpolatedNodalCurve or ConstantNodalCurve"); } return(new IsdaCreditDiscountFactors(currency, valuationDate, curve)); }
public virtual void test_of_badCurve() { InterpolatedNodalCurve notYearFraction = InterpolatedNodalCurve.of(Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); InterpolatedNodalCurve notZeroRate = InterpolatedNodalCurve.of(Curves.discountFactors(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata noDayCountMetadata = DefaultCurveMetadata.builder().curveName(NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).addInfo(CurveInfoType.COMPOUNDING_PER_YEAR, 4).build(); InterpolatedNodalCurve notDayCount = InterpolatedNodalCurve.of(noDayCountMetadata, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata metaNoCompoundPerYear = DefaultCurveMetadata.builder().curveName(NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(ACT_365F).build(); InterpolatedNodalCurve notCompoundPerYear = InterpolatedNodalCurve.of(metaNoCompoundPerYear, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata metaNegativeNb = DefaultCurveMetadata.builder().curveName(NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(ACT_365F).addInfo(CurveInfoType.COMPOUNDING_PER_YEAR, -1).build(); InterpolatedNodalCurve curveNegativeNb = InterpolatedNodalCurve.of(metaNegativeNb, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); assertThrowsIllegalArg(() => ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, notYearFraction)); assertThrowsIllegalArg(() => ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, notZeroRate)); assertThrowsIllegalArg(() => ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, notDayCount)); assertThrowsIllegalArg(() => ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, notCompoundPerYear)); assertThrowsIllegalArg(() => ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, curveNegativeNb)); }
// modified sensitivity function - sensitivities are computed only for ibor index curves private CurrencyParameterSensitivities sensiModFn(ImmutableRatesProvider provider) { CurrencyParameterSensitivities sensi = CurrencyParameterSensitivities.empty(); // Index ImmutableMap <Index, Curve> mapIndex = provider.IndexCurves; foreach (KeyValuePair <Index, Curve> entry in mapIndex.entrySet()) { if (entry.Key is IborIndex) { InterpolatedNodalCurve curveInt = checkInterpolated(entry.Value); double sumSqrt = sumMod(provider); sensi = sensi.combinedWith(CurrencyParameterSensitivity.of(curveInt.Name, USD, DoubleArray.of(curveInt.ParameterCount, i => 2d * sumSqrt * curveInt.XValues.get(i)))); } } return(sensi); }
private static IList <string> curveSettings(Curve curve) { ArgChecker.isTrue(curve is InterpolatedNodalCurve, "Curve must be an InterpolatedNodalCurve"); if (!VALUE_TYPE_MAP.inverse().containsKey(curve.Metadata.YValueType)) { throw new System.ArgumentException(Messages.format("Unsupported ValueType in curve settings: {}", curve.Metadata.YValueType)); } InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve)curve; IList <string> line = new List <string>(); line.Add(curve.Name.Name); line.Add(VALUE_TYPE_MAP.inverse().get(curve.Metadata.YValueType)); line.Add(curve.Metadata.getInfo(CurveInfoType.DAY_COUNT).ToString()); line.Add(interpolatedCurve.Interpolator.ToString()); line.Add(interpolatedCurve.ExtrapolatorLeft.ToString()); line.Add(interpolatedCurve.ExtrapolatorRight.ToString()); return(line); }
public virtual void test_build_fail() { Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve rhoCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Rho", ACT_365F, SABR_RHO), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knotsEmptyBeta = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, NU_KNOTS); ImmutableList <DoubleArray> knotsEmptyRho = ImmutableList.of(ALPHA_KNOTS, BETA_RHO_KNOTS, DoubleArray.of(), NU_KNOTS); // beta, rho not set assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // beta set, but rho knots not defined assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyRho).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // beta rho set assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).rhoCurve(rhoCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // wrong initial value array size assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(DoubleArray.of(0.34, 0.5, -0.22)).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(ImmutableList.of(ALPHA_KNOTS, BETA_RHO_KNOTS, NU_KNOTS)).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); }
// add each node to the csv file private static void nodeLines(string valuationDateStr, Curve curve, CsvOutput csv) { ArgChecker.isTrue(curve is InterpolatedNodalCurve, "interpolated"); InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve)curve; int nbPoints = interpolatedCurve.XValues.size(); for (int i = 0; i < nbPoints; i++) { ArgChecker.isTrue(interpolatedCurve.getParameterMetadata(i) is DatedParameterMetadata, "Curve metadata must contain a date, but was " + interpolatedCurve.getParameterMetadata(i).GetType().Name); DatedParameterMetadata metadata = (DatedParameterMetadata)interpolatedCurve.getParameterMetadata(i); IList <string> line = new List <string>(); line.Add(valuationDateStr); line.Add(curve.Name.Name.ToString()); line.Add(metadata.Date.ToString()); line.Add(decimal.valueOf(interpolatedCurve.YValues.get(i)).toPlainString()); line.Add(metadata.Label); csv.writeLine(line); } }
/// <summary> /// Test parameter sensitivity with finite difference sensitivity calculator. No cutoff period. </summary> public virtual void rateChfNoCutOffParameterSensitivity() { LocalDate[] valuationDate = new LocalDate[] { date(2015, 1, 1), date(2015, 1, 8) }; DoubleArray time = DoubleArray.of(0.0, 0.5, 1.0, 2.0, 5.0, 10.0); DoubleArray rate = DoubleArray.of(0.0100, 0.0110, 0.0115, 0.0130, 0.0135, 0.0135); for (int loopvaldate = 0; loopvaldate < 2; loopvaldate++) { Curve onCurve = InterpolatedNodalCurve.of(Curves.zeroRates("ON", ACT_ACT_ISDA), time, rate, INTERPOLATOR); ImmutableRatesProvider prov = ImmutableRatesProvider.builder(valuationDate[loopvaldate]).overnightIndexCurve(CHF_TOIS, onCurve, TIME_SERIES).build(); OvernightAveragedRateComputation ro = OvernightAveragedRateComputation.of(CHF_TOIS, START_DATE, END_DATE, 0, REF_DATA); ForwardOvernightAveragedRateComputationFn obsFn = ForwardOvernightAveragedRateComputationFn.DEFAULT; PointSensitivityBuilder sensitivityBuilderComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov); CurrencyParameterSensitivities parameterSensitivityComputed = prov.parameterSensitivity(sensitivityBuilderComputed.build()); CurrencyParameterSensitivities parameterSensitivityExpected = CAL_FD.sensitivity(prov, (p) => CurrencyAmount.of(CHF_TOIS.Currency, obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, (p)))); assertTrue(parameterSensitivityComputed.equalWithTolerance(parameterSensitivityExpected, EPS_FD * 10.0)); } }
public virtual void test_builder() { Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knots = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, NU_KNOTS); SabrIborCapletFloorletVolatilityCalibrationDefinition test = SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().betaCurve(betaCurve).dayCount(ACT_365F).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knots).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build(); assertEquals(test.BetaCurve.get(), betaCurve); assertEquals(test.DayCount, ACT_365F); assertEquals(test.ExtrapolatorLeft, FLAT); assertEquals(test.ExtrapolatorRight, FLAT); assertEquals(test.Index, USD_LIBOR_3M); assertEquals(test.InitialParameters, initial); assertEquals(test.Interpolator, DOUBLE_QUADRATIC); assertEquals(test.Name, NAME); assertFalse(test.RhoCurve.Present); assertEquals(test.SabrVolatilityFormula, HAGAN); assertEquals(test.ShiftCurve, shiftCurve); }
public virtual void test_createSabrParameterCurve() { DoubleArray nuKnots = DoubleArray.of(5.0); SabrIborCapletFloorletVolatilityCalibrationDefinition fixedBeta = SabrIborCapletFloorletVolatilityCalibrationDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_365F, BETA_RHO, ALPHA_KNOTS, BETA_RHO_KNOTS, nuKnots, DOUBLE_QUADRATIC, FLAT, LINEAR, HAGAN); SabrIborCapletFloorletVolatilityCalibrationDefinition fixedRho = SabrIborCapletFloorletVolatilityCalibrationDefinition.ofFixedRho(NAME, USD_LIBOR_3M, ACT_365F, BETA_RHO, ALPHA_KNOTS, BETA_RHO_KNOTS, nuKnots, DOUBLE_QUADRATIC, FLAT, LINEAR, HAGAN); ImmutableList <CurveMetadata> metadata = fixedBeta.createSabrParameterMetadata(); DoubleArray newValues = DoubleArray.of(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.05); DoubleArray newValues1 = DoubleArray.of(0.01, 0.01, 0.01, 0.01, 0.01, 0.01); DoubleArray newValues2 = DoubleArray.of(0.02, 0.02, 0.02); DoubleArray newValues3 = DoubleArray.of(0.05); IList <Curve> computedFixedBeta = fixedBeta.createSabrParameterCurve(metadata, newValues); IList <Curve> computedFixedRho = fixedRho.createSabrParameterCurve(metadata, newValues); Curve curveAlpha = InterpolatedNodalCurve.of(metadata.get(0), ALPHA_KNOTS, newValues1, DOUBLE_QUADRATIC, FLAT, LINEAR); Curve curveBeta = InterpolatedNodalCurve.of(metadata.get(1), BETA_RHO_KNOTS, newValues2, DOUBLE_QUADRATIC, FLAT, LINEAR); Curve curveRho = InterpolatedNodalCurve.of(metadata.get(2), BETA_RHO_KNOTS, newValues2, DOUBLE_QUADRATIC, FLAT, LINEAR); Curve curveNu = ConstantNodalCurve.of(metadata.get(3), nuKnots.get(0), newValues3.get(0)); assertEquals(computedFixedBeta, ImmutableList.of(curveAlpha, fixedBeta.BetaCurve.get(), curveRho, curveNu)); assertEquals(computedFixedRho, ImmutableList.of(curveAlpha, curveBeta, fixedRho.RhoCurve.get(), curveNu)); }
private double sumCombine(ImmutableRatesProvider provider) { double result = 0.0; // Currency ImmutableMap <Currency, Curve> mapCurrency = provider.DiscountCurves; foreach (KeyValuePair <Currency, Curve> entry in mapCurrency.entrySet()) { if (entry.Value is CombinedCurve) { InterpolatedNodalCurve baseCurveInt = checkInterpolated(entry.Value.Split().get(0)); InterpolatedNodalCurve spreadCurveInt = checkInterpolated(entry.Value.Split().get(1)); result += 0.25d * sumSingle(baseCurveInt); result += sumSingle(spreadCurveInt); } else { InterpolatedNodalCurve curveInt = checkInterpolated(entry.Value); result += sumSingle(curveInt); } } // Index ImmutableMap <Index, Curve> mapIndex = provider.IndexCurves; foreach (KeyValuePair <Index, Curve> entry in mapIndex.entrySet()) { if (entry.Value is CombinedCurve) { InterpolatedNodalCurve baseCurveInt = checkInterpolated(entry.Value.Split().get(0)); InterpolatedNodalCurve spreadCurveInt = checkInterpolated(entry.Value.Split().get(1)); result += 0.25d * sumSingle(baseCurveInt); result += sumSingle(spreadCurveInt); } else { InterpolatedNodalCurve curveInt = checkInterpolated(entry.Value); result += entry.Key.Equals(IborIndices.USD_LIBOR_3M) ? 0.25d * sumSingle(curveInt) : sumSingle(curveInt); } } return(result); }