Exemplo n.º 1
0
        public virtual void test_withPerturbation()
        {
            CombinedCurve computed = COMBINED_CURVE.withPerturbation((i, v, m) => 2d * v * i);
            CombinedCurve expected = CombinedCurve.of(BASE_CURVE.withPerturbation((i, v, m) => 2d * v * i), SPREAD_CURVE.withPerturbation((i, v, m) => 2d * v * (i + BASE_CURVE.ParameterCount)));

            assertEquals(computed, expected);
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            coverImmutableBean(COMBINED_CURVE);
            CombinedCurve test = CombinedCurve.of(ConstantCurve.of(DefaultCurveMetadata.builder().curveName("name1").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).build(), 1d), ConstantCurve.of(DefaultCurveMetadata.builder().curveName("name2").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).build(), 2d));

            coverBeanEquals(COMBINED_CURVE, test);
        }
Exemplo n.º 3
0
        //-------------------------------------------------------------------------
        public virtual void test_underlyingCurves()
        {
            CurveMetadata          metadata = DefaultCurveMetadata.builder().curveName("newCurve").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).parameterMetadata(PARAM_METADATA_SPREAD).build();
            InterpolatedNodalCurve newCurve = InterpolatedNodalCurve.of(metadata, XVALUES_SPREAD, YVALUES_SPREAD, NATURAL_CUBIC_SPLINE, LINEAR, LINEAR);

            assertEquals(COMBINED_CURVE.withUnderlyingCurve(0, newCurve), CombinedCurve.of(newCurve, SPREAD_CURVE, COMBINED_CURVE.Metadata));
            assertEquals(COMBINED_CURVE.withUnderlyingCurve(1, newCurve), CombinedCurve.of(BASE_CURVE, newCurve, COMBINED_CURVE.Metadata));
            assertEquals(COMBINED_CURVE.split(), ImmutableList.of(BASE_CURVE, SPREAD_CURVE));
            assertThrowsIllegalArg(() => COMBINED_CURVE.withUnderlyingCurve(2, newCurve));
        }
Exemplo n.º 4
0
        public override CombinedCurve withPerturbation(ParameterPerturbation perturbation)
        {
            Curve newBaseCurve   = baseCurve.withPerturbation((idx, value, meta) => perturbation(idx, baseCurve.getParameter(idx), baseCurve.getParameterMetadata(idx)));
            int   offset         = baseCurve.ParameterCount;
            Curve newSpreadCurve = spreadCurve.withPerturbation((idx, value, meta) => perturbation(idx + offset, spreadCurve.getParameter(idx), spreadCurve.getParameterMetadata(idx)));

            IList <ParameterMetadata> newParamMeta = Stream.concat(IntStream.range(0, newBaseCurve.ParameterCount).mapToObj(i => newBaseCurve.getParameterMetadata(i)), IntStream.range(0, newSpreadCurve.ParameterCount).mapToObj(i => newSpreadCurve.getParameterMetadata(i))).collect(toImmutableList());

            return(CombinedCurve.of(newBaseCurve, newSpreadCurve, metadata.withParameterMetadata(newParamMeta)));
        }
Exemplo n.º 5
0
        public virtual void test_withParameter()
        {
            CombinedCurve computed1 = COMBINED_CURVE.withParameter(1, 12.5);
            CombinedCurve expected1 = CombinedCurve.of(BASE_CURVE.withParameter(1, 12.5), SPREAD_CURVE);

            assertEquals(computed1, expected1);
            CombinedCurve computed2 = COMBINED_CURVE.withParameter(5, 7.5);
            CombinedCurve expected2 = CombinedCurve.of(BASE_CURVE, SPREAD_CURVE.withParameter(5 - BASE_CURVE.ParameterCount, 7.5));

            assertEquals(computed2, expected2);
        }
Exemplo n.º 6
0
        //-------------------------------------------------------------------------
        public virtual void test_withMetadata()
        {
            IList <ParameterMetadata> combinedParamMeta = new List <ParameterMetadata>();

            ((IList <ParameterMetadata>)combinedParamMeta).AddRange(PARAM_METADATA_BASE);
            ((IList <ParameterMetadata>)combinedParamMeta).AddRange(PARAM_METADATA_SPREAD);
            CurveMetadata newMetadata = DefaultCurveMetadata.builder().curveName("newName").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).parameterMetadata(combinedParamMeta).build();
            CombinedCurve computed    = COMBINED_CURVE.withMetadata(newMetadata);
            CombinedCurve expected    = CombinedCurve.of(BASE_CURVE, SPREAD_CURVE, newMetadata);

            assertEquals(computed, expected);
        }
Exemplo n.º 7
0
        public virtual void test_dayCount()
        {
            CurveMetadata          baseMetadata      = DefaultCurveMetadata.builder().curveName(BASE_NAME).xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).build();
            CurveMetadata          spreadMetadata    = DefaultCurveMetadata.builder().curveName(SPREAD_NAME).xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(DayCounts.ACT_360).build();
            InterpolatedNodalCurve baseCurve         = InterpolatedNodalCurve.of(baseMetadata, XVALUES_BASE, YVALUES_BASE, NATURAL_CUBIC_SPLINE, LINEAR, LINEAR);
            InterpolatedNodalCurve spreadCurve       = InterpolatedNodalCurve.of(spreadMetadata, XVALUES_SPREAD, YVALUES_SPREAD, PCHIP, LINEAR, LINEAR);
            CurveMetadata          combinedMetadata1 = DefaultCurveMetadata.builder().curveName("CombinedCurve").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(DayCounts.ACT_360).build();

            assertThrowsIllegalArg(() => CombinedCurve.of(baseCurve, spreadCurve, combinedMetadata1));
            CurveMetadata combinedMetadata2 = DefaultCurveMetadata.builder().curveName("CombinedCurve").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).build();

            assertThrowsIllegalArg(() => CombinedCurve.of(baseCurve, spreadCurve, combinedMetadata2));
        }
Exemplo n.º 8
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         CombinedCurve other = (CombinedCurve)obj;
         return(JodaBeanUtils.equal(baseCurve, other.baseCurve) && JodaBeanUtils.equal(spreadCurve, other.spreadCurve) && JodaBeanUtils.equal(metadata, other.metadata));
     }
     return(false);
 }
Exemplo n.º 9
0
        public virtual void test_of()
        {
            CurveMetadata          baseMetadata     = DefaultCurveMetadata.builder().curveName(BASE_NAME).xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).build();
            CurveMetadata          spreadMetadata   = DefaultCurveMetadata.builder().curveName(SPREAD_NAME).xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).build();
            InterpolatedNodalCurve baseCurve        = InterpolatedNodalCurve.of(baseMetadata, XVALUES_BASE, YVALUES_BASE, NATURAL_CUBIC_SPLINE, LINEAR, LINEAR);
            InterpolatedNodalCurve spreadCurve      = InterpolatedNodalCurve.of(spreadMetadata, XVALUES_SPREAD, YVALUES_SPREAD, PCHIP, LINEAR, LINEAR);
            CurveMetadata          combinedMetadata = DefaultCurveMetadata.builder().curveName("CombinedCurve").xValueType(YEAR_FRACTION).yValueType(ZERO_RATE).dayCount(ACT_365F).build();
            CombinedCurve          test             = CombinedCurve.of(baseCurve, spreadCurve, combinedMetadata);

            assertEquals(test.BaseCurve, baseCurve);
            assertEquals(test.SpreadCurve, spreadCurve);
            assertEquals(test.Metadata, combinedMetadata);
            assertEquals(test.Name, combinedMetadata.CurveName);
            assertEquals(test.ParameterCount, baseCurve.ParameterCount + spreadCurve.ParameterCount);
            assertEquals(test.getParameter(1), baseCurve.getParameter(1));
            assertEquals(test.getParameter(6), spreadCurve.getParameter(3));
            assertEquals(test.getParameterMetadata(2), baseCurve.getParameterMetadata(2));
            assertEquals(test.getParameterMetadata(5), spreadCurve.getParameterMetadata(2));
        }