예제 #1
0
        public virtual void createScenarioValueFromSingleValue()
        {
            MarketDataBox <double> box         = MarketDataBox.ofSingleValue(3d);
            QuoteScenarioArray     quotesArray = KEY.createScenarioValue(box, 3);

            assertThat(quotesArray.Quotes).isEqualTo(DoubleArray.of(3d, 3d, 3d));
        }
예제 #2
0
        //-------------------------------------------------------------------------
        public virtual void test_getValue_fxIdentity()
        {
            BuiltScenarioMarketData test = BuiltScenarioMarketData.builder(MarketDataBox.ofSingleValue(VAL_DATE)).build();

            assertEquals(test.ScenarioCount, 1);
            assertEquals(test.getValue(FxRateId.of(GBP, GBP)), MarketDataBox.ofSingleValue(FxRate.of(GBP, GBP, 1)));
        }
        public virtual void test_toZonedDateTime_single()
        {
            ValuationZoneTimeDefinition   test     = ValuationZoneTimeDefinition.of(LOCAL_TIME_4, ZONE_ID);
            MarketDataBox <LocalDate>     dates    = MarketDataBox.ofSingleValue(LocalDate.of(2016, 10, 21));
            MarketDataBox <ZonedDateTime> computed = test.toZonedDateTime(dates);
            MarketDataBox <ZonedDateTime> expected = MarketDataBox.ofSingleValue(dates.SingleValue.atTime(LOCAL_TIME_4).atZone(ZONE_ID));

            assertEquals(computed, expected);
        }
예제 #4
0
        public virtual void test_getValue_withUnknownFailure()
        {
            BuiltScenarioMarketData test = BuiltScenarioMarketData.builder(MarketDataBox.ofSingleValue(VAL_DATE)).build();

            assertEquals(test.ValuationDate, MarketDataBox.ofSingleValue(VAL_DATE));
            assertEquals(test.containsValue(ID), false);
            assertEquals(test.Ids, ImmutableSet.of());
            assertEquals(test.findValue(ID), null);
            assertThrows(() => test.getValue(ID), typeof(MarketDataNotFoundException));
        }
예제 #5
0
        public virtual void test_getValue_withKnownFailure()
        {
            string failureMessage        = "Something went wrong";
            BuiltScenarioMarketData test = BuiltScenarioMarketData.builder(MarketDataBox.ofSingleValue(VAL_DATE)).addResult(ID, Result.failure(FailureReason.ERROR, failureMessage)).build();

            assertEquals(test.ValuationDate, MarketDataBox.ofSingleValue(VAL_DATE));
            assertEquals(test.containsValue(ID), false);
            assertEquals(test.Ids, ImmutableSet.of());
            assertEquals(test.findValue(ID), null);
            assertThrows(() => test.getValue(ID), typeof(FailureException), failureMessage);
        }
        public virtual void test_relative()
        {
            CurveParallelShifts test = CurveParallelShifts.relative(0.1d, 0.2d, 0.4d);

            Curve baseCurve = InterpolatedNodalCurve.of(Curves.zeroRates("curve", DayCounts.ACT_365F), DoubleArray.of(1, 2, 3), DoubleArray.of(5, 6, 7), CurveInterpolators.LOG_LINEAR);

            MarketDataBox <Curve> shiftedCurveBox = test.applyTo(MarketDataBox.ofSingleValue(baseCurve), REF_DATA);

            assertEquals(shiftedCurveBox.getValue(0), ParallelShiftedCurve.relative(baseCurve, 0.1d));
            assertEquals(shiftedCurveBox.getValue(1), ParallelShiftedCurve.relative(baseCurve, 0.2d));
            assertEquals(shiftedCurveBox.getValue(2), ParallelShiftedCurve.relative(baseCurve, 0.4d));
        }
예제 #7
0
        public virtual void test_multipleCurves()
        {
            Curve              curve1     = ConstantCurve.of(CURVE_NAME1, (double)1);
            Curve              curve2     = ConstantCurve.of(CURVE_NAME2, (double)2);
            CurveId            curveId1   = CurveId.of(GROUP_NAME, CURVE_NAME1);
            CurveId            curveId2   = CurveId.of(GROUP_NAME, CURVE_NAME2);
            RatesCurveGroupId  groupId    = RatesCurveGroupId.of(GROUP_NAME);
            RatesCurveGroup    curveGroup = RatesCurveGroup.of(GROUP_NAME, ImmutableMap.of(Currency.AUD, curve1, Currency.GBP, curve2), ImmutableMap.of());
            ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValue(groupId, curveGroup).build();
            MarketDataConfig   config     = MarketDataConfig.builder().add(GROUP_NAME, RatesCurveGroupDefinition.builder().name(GROUP_NAME).build()).build();

            CurveMarketDataFunction test    = new CurveMarketDataFunction();
            MarketDataBox <Curve>   result1 = test.build(curveId1, config, marketData, REF_DATA);

            assertEquals(result1, MarketDataBox.ofSingleValue(curve1));
            MarketDataBox <Curve> result2 = test.build(curveId2, config, marketData, REF_DATA);

            assertEquals(result2, MarketDataBox.ofSingleValue(curve2));
        }
예제 #8
0
        public virtual void test_applyTo()
        {
            double baseValue = 3d;
            MarketDataBox <double> marketData     = MarketDataBox.ofSingleValue(baseValue);
            GenericDoubleShifts    testScaled     = GenericDoubleShifts.of(ShiftType.SCALED, SHIFT_AMOUNT, SPREAD);
            MarketDataBox <double> computedScaled = testScaled.applyTo(marketData, REF_DATA);
            MarketDataBox <double> expectedScaled = MarketDataBox.ofScenarioValues(ImmutableList.of((baseValue + SPREAD) * SHIFT_AMOUNT.get(0) - SPREAD, (baseValue + SPREAD) * SHIFT_AMOUNT.get(1) - SPREAD, (baseValue + SPREAD) * SHIFT_AMOUNT.get(2) - SPREAD));

            assertEquals(computedScaled, expectedScaled);
            GenericDoubleShifts    testRelative     = GenericDoubleShifts.of(ShiftType.RELATIVE, SHIFT_AMOUNT, SPREAD);
            MarketDataBox <double> computedRelative = testRelative.applyTo(marketData, REF_DATA);
            MarketDataBox <double> expectedRelative = MarketDataBox.ofScenarioValues(ImmutableList.of((baseValue + SPREAD) * (1d + SHIFT_AMOUNT.get(0)) - SPREAD, (baseValue + SPREAD) * (1d + SHIFT_AMOUNT.get(1)) - SPREAD, (baseValue + SPREAD) * (1d + SHIFT_AMOUNT.get(2)) - SPREAD));

            assertEquals(computedRelative, expectedRelative);
            GenericDoubleShifts    testAbsolute     = GenericDoubleShifts.of(ShiftType.ABSOLUTE, SHIFT_AMOUNT);
            MarketDataBox <double> computedAbsolute = testAbsolute.applyTo(marketData, REF_DATA);
            MarketDataBox <double> expectedAbsolute = MarketDataBox.ofScenarioValues(ImmutableList.of(baseValue + SHIFT_AMOUNT.get(0), baseValue + SHIFT_AMOUNT.get(1), baseValue + SHIFT_AMOUNT.get(2)));

            assertEquals(computedAbsolute, expectedAbsolute);
        }
예제 #9
0
        public virtual void test_pointShifts()
        {
            SabrParametersSwaptionVolatilities @base = SabrParametersSwaptionVolatilities.of(NAME, CONV, DATE_TIME, PARAM);
            PointShiftsBuilder builder = PointShifts.builder(ShiftType.ABSOLUTE);

            for (int i = 0; i < @base.ParameterCount; ++i)
            {
                builder.addShift(0, @base.getParameterMetadata(i).Identifier, 0.1d * (i + 1d));
                builder.addShift(1, @base.getParameterMetadata(i).Identifier, 10d * (i + 1d));
            }
            PointShifts shifts = builder.build();
            MarketDataBox <ParameterizedData>  resBox    = shifts.applyTo(MarketDataBox.ofSingleValue(@base), REF_DATA);
            SabrParametersSwaptionVolatilities computed0 = (SabrParametersSwaptionVolatilities)resBox.getValue(0);
            SabrParametersSwaptionVolatilities computed1 = (SabrParametersSwaptionVolatilities)resBox.getValue(1);

            for (int i = 0; i < @base.ParameterCount; ++i)
            {
                assertEquals(computed0.getParameter(i), @base.getParameter(i) + 0.1d * (i + 1d));
                assertEquals(computed1.getParameter(i), @base.getParameter(i) + 10d * (i + 1d));
            }
        }
예제 #10
0
        //-------------------------------------------------------------------------
        public virtual void test_singleCurve()
        {
            Curve              curve      = ConstantCurve.of(CURVE_NAME1, (double)1);
            CurveId            curveId1   = CurveId.of(GROUP_NAME, CURVE_NAME1, OBS_SOURCE);
            CurveId            curveId2   = CurveId.of(GROUP_NAME, CURVE_NAME2, OBS_SOURCE);
            CurveId            curveId3   = CurveId.of(GROUP_NAME2, CURVE_NAME1, OBS_SOURCE);
            RatesCurveGroupId  groupId    = RatesCurveGroupId.of(GROUP_NAME, OBS_SOURCE);
            RatesCurveGroup    curveGroup = RatesCurveGroup.of(GROUP_NAME, ImmutableMap.of(Currency.AUD, curve), ImmutableMap.of());
            ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValue(groupId, curveGroup).build();
            MarketDataConfig   config     = MarketDataConfig.builder().add(GROUP_NAME, RatesCurveGroupDefinition.builder().name(GROUP_NAME).build()).build();

            CurveMarketDataFunction test = new CurveMarketDataFunction();
            MarketDataRequirements  reqs = test.requirements(curveId1, config);

            assertEquals(reqs.NonObservables, ImmutableSet.of(groupId));
            MarketDataBox <Curve> result = test.build(curveId1, config, marketData, REF_DATA);

            assertEquals(result, MarketDataBox.ofSingleValue(curve));
            assertThrowsIllegalArg(() => test.build(curveId2, config, marketData, REF_DATA));
            assertThrowsIllegalArg(() => test.build(curveId3, config, marketData, REF_DATA));
        }
예제 #11
0
        public virtual void test_applyTo()
        {
            MarketDataBox <FxRate> marketData     = MarketDataBox.ofSingleValue(FX_RATE);
            FxRateShifts           testScaled     = FxRateShifts.of(ShiftType.SCALED, SHIFT_AMOUNT_2, EURUSD);
            MarketDataBox <FxRate> computedScaled = testScaled.applyTo(marketData, REF_DATA);
            MarketDataBox <FxRate> expectedScaled = MarketDataBox.ofScenarioValues(ImmutableList.of(FxRate.of(EURUSD, BASE_RATE * SHIFT_AMOUNT_2.get(0)), FxRate.of(EURUSD, BASE_RATE * SHIFT_AMOUNT_2.get(1)), FxRate.of(EURUSD, BASE_RATE * SHIFT_AMOUNT_2.get(2))));

            assertEquals(computedScaled, expectedScaled);
            FxRateShifts           testScaledInv     = FxRateShifts.of(ShiftType.SCALED, SHIFT_AMOUNT_2, USDEUR);
            MarketDataBox <FxRate> computedScaledInv = testScaledInv.applyTo(marketData, REF_DATA);
            MarketDataBox <FxRate> expectedScaledInv = MarketDataBox.ofScenarioValues(ImmutableList.of(FxRate.of(USDEUR, 1d / BASE_RATE * SHIFT_AMOUNT_2.get(0)), FxRate.of(USDEUR, 1d / BASE_RATE * SHIFT_AMOUNT_2.get(1)), FxRate.of(USDEUR, 1d / BASE_RATE * SHIFT_AMOUNT_2.get(2))));

            assertEquals(computedScaledInv, expectedScaledInv);
            FxRateShifts           testAbsolute     = FxRateShifts.of(ShiftType.ABSOLUTE, SHIFT_AMOUNT_1, EURUSD);
            MarketDataBox <FxRate> computedAbsolute = testAbsolute.applyTo(marketData, REF_DATA);
            MarketDataBox <FxRate> expectedAbsolute = MarketDataBox.ofScenarioValues(ImmutableList.of(FxRate.of(EURUSD, BASE_RATE + SHIFT_AMOUNT_1.get(0)), FxRate.of(EURUSD, BASE_RATE + SHIFT_AMOUNT_1.get(1)), FxRate.of(EURUSD, BASE_RATE + SHIFT_AMOUNT_1.get(2))));

            assertEquals(computedAbsolute, expectedAbsolute);
            FxRateShifts           testRelative     = FxRateShifts.of(ShiftType.RELATIVE, SHIFT_AMOUNT_1, EURUSD);
            MarketDataBox <FxRate> computedRelative = testRelative.applyTo(marketData, REF_DATA);
            MarketDataBox <FxRate> expectedRelative = MarketDataBox.ofScenarioValues(ImmutableList.of(FxRate.of(EURUSD, BASE_RATE * (1d + SHIFT_AMOUNT_1.get(0))), FxRate.of(EURUSD, BASE_RATE * (1d + SHIFT_AMOUNT_1.get(1))), FxRate.of(EURUSD, BASE_RATE * (1d + SHIFT_AMOUNT_1.get(2)))));

            assertEquals(computedRelative, expectedRelative);
        }