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); } } }
//------------------------------------------------------------------------- public virtual void coverage() { PointShifts test = PointShifts.builder(ShiftType.RELATIVE).addShift(0, Tenor.TENOR_1W, 0.1).addShift(0, Tenor.TENOR_1M, 0.2).addShift(0, Tenor.TENOR_3M, 0.3).build(); coverImmutableBean(test); PointShifts test2 = PointShifts.builder(ShiftType.ABSOLUTE).addShift(0, Tenor.TENOR_1M, 0.2).addShift(0, Tenor.TENOR_3M, 0.3).build(); coverBeanEquals(test, test2); }
//----------------------------------------------------------------------- public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { PointShifts other = (PointShifts)obj; return(JodaBeanUtils.equal(shiftType, other.shiftType) && JodaBeanUtils.equal(shifts, other.shifts) && JodaBeanUtils.equal(nodeIndices, other.nodeIndices)); } return(false); }