Beispiel #1
0
        public virtual void test_rate()
        {
            SimpleRatesProvider       prov       = new SimpleRatesProvider();
            LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(FIXING_DATE, RATE);
            IborIndexRates            mockIbor   = new TestingIborIndexRates(GBP_LIBOR_3M, FIXING_DATE, LocalDateDoubleTimeSeries.empty(), timeSeries);

            prov.IborRates = mockIbor;

            ForwardIborRateComputationFn obsFn = ForwardIborRateComputationFn.DEFAULT;

            assertEquals(obsFn.rate(GBP_LIBOR_3M_COMP, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov), RATE);

            // explain
            ExplainMapBuilder builder = ExplainMap.builder();

            assertEquals(obsFn.explainRate(GBP_LIBOR_3M_COMP, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov, builder), RATE);

            ExplainMap built = builder.build();

            assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 1);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FIXING_DATE), FIXING_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX), GBP_LIBOR_3M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX_VALUE), RATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FROM_FIXING_SERIES), true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FORWARD_RATE_START_DATE), FORWARD_START_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FORWARD_RATE_END_DATE), FORWARD_END_DATE);
            assertEquals(built.get(ExplainKey.COMBINED_RATE), RATE);
        }
Beispiel #2
0
        public virtual void test_presentValue_ended()
        {
            SimpleRatesProvider prov     = provider(date(2014, 9, 22), 1.2d, 1.1d);
            CurrencyAmount      computed = PRICER.presentValue(RTERM_DEPOSIT, prov);

            assertEquals(computed.Currency, EUR);
            assertEquals(computed.Amount, 0.0d, TOLERANCE * NOTIONAL);
        }
Beispiel #3
0
        public virtual void test_presentValue_inPast()
        {
            SimpleRatesProvider prov = createProvider(VAL_DATE);

            double pvComputed = PRICER.presentValue(PERIOD_PAST, prov);

            assertEquals(pvComputed, 0, TOLERANCE_PV);
        }
Beispiel #4
0
        public virtual void test_accruedInterest_valDateAfterPeriod()
        {
            SimpleRatesProvider prov = createProvider(PERIOD.EndDate.plusDays(1));

            double computed = PRICER.accruedInterest(PERIOD, prov);

            assertEquals(computed, 0, TOLERANCE_PV);
        }
Beispiel #5
0
        public virtual void test_accruedInterest_valDateBeforePeriod()
        {
            SimpleRatesProvider prov = createProvider(PERIOD.StartDate);

            double computed = PRICER.accruedInterest(PERIOD, prov);

            assertEquals(computed, 0, TOLERANCE_PV);
        }
Beispiel #6
0
        public virtual void test_presentValueSensitivity_inPast()
        {
            SimpleRatesProvider prov = createProvider(VAL_DATE);

            PointSensitivities computed = PRICER.presentValueSensitivity(PERIOD_PAST, prov).build();

            assertEquals(computed, PointSensitivities.empty());
        }
Beispiel #7
0
        public virtual void test_parSpread()
        {
            SimpleRatesProvider prov = provider(VAL_DATE, DF_START, DF_END);
            double      parSpread    = PRICER.parSpread(RTERM_DEPOSIT, prov);
            TermDeposit depositPar   = TermDeposit.builder().buySell(BuySell.BUY).startDate(START_DATE).endDate(END_DATE).businessDayAdjustment(BD_ADJ).dayCount(ACT_360).notional(NOTIONAL).currency(EUR).rate(RATE + parSpread).build();
            double      pvPar        = PRICER.presentValue(depositPar.resolve(REF_DATA), prov).Amount;

            assertEquals(pvPar, 0.0, NOTIONAL * TOLERANCE);
        }
Beispiel #8
0
        public virtual void test_presentValue_onStart()
        {
            SimpleRatesProvider prov     = provider(START_DATE, 1.0d, DF_END);
            CurrencyAmount      computed = PRICER.presentValue(RTERM_DEPOSIT, prov);
            double expected = ((1d + RATE * RTERM_DEPOSIT.YearFraction) * DF_END - 1.0d) * NOTIONAL;

            assertEquals(computed.Currency, EUR);
            assertEquals(computed.Amount, expected, TOLERANCE * NOTIONAL);
        }
Beispiel #9
0
        //-------------------------------------------------------------------------
        public virtual void test_forecastValue()
        {
            SimpleRatesProvider prov = createProvider(VAL_DATE);

            double fvExpected = AMOUNT_1000;
            double fvComputed = PRICER.forecastValue(PERIOD, prov);

            assertEquals(fvComputed, fvExpected, TOLERANCE_PV);
        }
Beispiel #10
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            SimpleRatesProvider prov = createProvider(VAL_DATE);

            double pvExpected = AMOUNT_1000 * DISCOUNT_FACTOR;
            double pvComputed = PRICER.presentValue(PERIOD, prov);

            assertEquals(pvComputed, pvExpected, TOLERANCE_PV);
        }
Beispiel #11
0
        public virtual void test_presentValue_started()
        {
            SimpleRatesProvider prov     = provider(date(2014, 2, 22), 1.2d, DF_END);
            CurrencyAmount      computed = PRICER.presentValue(RTERM_DEPOSIT, prov);
            double expected = (1d + RATE * RTERM_DEPOSIT.YearFraction) * DF_END * NOTIONAL;

            assertEquals(computed.Currency, EUR);
            assertEquals(computed.Amount, expected, TOLERANCE * NOTIONAL);
        }
Beispiel #12
0
        //-------------------------------------------------------------------------
        public virtual void test_price()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(FUTURE.IborRate.Observation)).thenReturn(RATE);

            assertEquals(PRICER_TRADE.price(FUTURE_TRADE, prov), 1.0 - RATE, TOLERANCE_PRICE);
        }
Beispiel #13
0
        //-------------------------------------------------------------------------
        // creates a simple provider
        private SimpleRatesProvider createProvider(LocalDate valDate)
        {
            Curve               curve = ConstantCurve.of(Curves.discountFactors("Test", DAY_COUNT), DISCOUNT_FACTOR);
            DiscountFactors     df    = SimpleDiscountFactors.of(GBP, valDate, curve);
            SimpleRatesProvider prov  = new SimpleRatesProvider(valDate);

            prov.DayCount        = DAY_COUNT;
            prov.DiscountFactors = df;
            return(prov);
        }
Beispiel #14
0
        //-------------------------------------------------------------------------
        public virtual void test_accruedInterest()
        {
            LocalDate           valDate = PERIOD.StartDate.plusDays(7);
            SimpleRatesProvider prov    = createProvider(valDate);

            double expected = AMOUNT_1000 * (7d / (7 + 28 + 31 + 25));
            double computed = PRICER.accruedInterest(PERIOD, prov);

            assertEquals(computed, expected, TOLERANCE_PV);
        }
Beispiel #15
0
        private SimpleRatesProvider provider(LocalDate valuationDate, double dfStart, double dfEnd)
        {
            DiscountFactors mockDf = mock(typeof(DiscountFactors));

            when(mockDf.discountFactor(START_DATE)).thenReturn(dfStart);
            when(mockDf.discountFactor(END_DATE)).thenReturn(dfEnd);
            SimpleRatesProvider prov = new SimpleRatesProvider(valuationDate, mockDf);

            return(prov);
        }
Beispiel #16
0
        //-------------------------------------------------------------------------
        public virtual void test_priceSensitivity()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;

            PointSensitivities sensiExpected = PointSensitivities.of(IborRateSensitivity.of(FUTURE.IborRate.Observation, -1d));
            PointSensitivities sensiComputed = PRICER.priceSensitivity(FUTURE, prov);

            assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PRICE_DELTA));
        }
Beispiel #17
0
        //-------------------------------------------------------------------------
        public virtual void test_parSpreadSensitivity()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;

            PointSensitivities sensiExpected = PRICER_PRODUCT.priceSensitivity(FUTURE, prov);
            PointSensitivities sensiComputed = PRICER_TRADE.parSpreadSensitivity(FUTURE_TRADE, prov);

            assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PRICE_DELTA));
        }
Beispiel #18
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivity()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;

            PointSensitivities sensiPrice = PRICER_PRODUCT.priceSensitivity(FUTURE, prov);
            PointSensitivities sensiPresentValueExpected = sensiPrice.multipliedBy(FUTURE.Notional * FUTURE.AccrualFactor * FUTURE_TRADE.Quantity);
            PointSensitivities sensiPresentValueComputed = PRICER_TRADE.presentValueSensitivity(FUTURE_TRADE, prov);

            assertTrue(sensiPresentValueComputed.equalWithTolerance(sensiPresentValueExpected, TOLERANCE_PV_DELTA));
        }
Beispiel #19
0
        public virtual void test_rateSensitivity()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;

            when(mockIbor.ratePointSensitivity(GBP_LIBOR_3M_COMP.Observation)).thenReturn(SENSITIVITY);

            ForwardIborRateComputationFn obsFn = ForwardIborRateComputationFn.DEFAULT;

            assertEquals(obsFn.rateSensitivity(GBP_LIBOR_3M_COMP, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov), SENSITIVITY);
        }
        // ----------     present value sensitivity     ----------

        public virtual void presentValueSensitivity_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            PointSensitivities psProduct  = OPTION_PRODUCT_PRICER.priceSensitivityRatesStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);
            PointSensitivities psExpected = psProduct.multipliedBy(OPTION_PRODUCT_PRICER.marginIndex(OPTION, 1) * OPTION_QUANTITY);
            PointSensitivities psComputed = OPTION_TRADE_PRICER.presentValueSensitivityRates(FUTURE_OPTION_TRADE, prov, VOL_SIMPLE_MONEY_PRICE);

            assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_PV_DELTA));
        }
        public virtual void price_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            double futurePrice         = 1.0 - RATE;
            double optionPriceExpected = OPTION_PRICER.price(OPTION, prov, VOL_SIMPLE_MONEY_PRICE, futurePrice);
            double optionPriceComputed = OPTION_PRICER.price(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);

            assertEquals(optionPriceComputed, optionPriceExpected, TOLERANCE_PRICE);
        }
Beispiel #22
0
        //-------------------------------------------------------------------------
        public virtual void test_parSpread_after_trade_date()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates     = mockIbor;
            prov.ValuationDate = FUTURE_TRADE.TradedPrice.get().TradeDate.plusDays(1);
            when(mockIbor.rate(FUTURE.IborRate.Observation)).thenReturn(RATE);
            double lastClosingPrice  = 0.99;
            double parSpreadExpected = PRICER_TRADE.price(FUTURE_TRADE, prov) - lastClosingPrice;
            double parSpreadComputed = PRICER_TRADE.parSpread(FUTURE_TRADE, prov, lastClosingPrice);

            assertEquals(parSpreadComputed, parSpreadExpected, TOLERANCE_PRICE);
        }
        static DiscountingFraTradePricerTest()
        {
            DiscountFactors mockDf   = mock(typeof(DiscountFactors));
            IborIndexRates  mockIbor = mock(typeof(IborIndexRates));

            RATES_PROVIDER           = new SimpleRatesProvider(VAL_DATE, mockDf);
            RATES_PROVIDER.IborRates = mockIbor;
            IborIndexObservation obs  = ((IborRateComputation)RFRA.FloatingRate).Observation;
            IborRateSensitivity  sens = IborRateSensitivity.of(obs, 1d);

            when(mockIbor.ratePointSensitivity(obs)).thenReturn(sens);
            when(mockIbor.rate(obs)).thenReturn(FORWARD_RATE);
            when(mockDf.discountFactor(RFRA.PaymentDate)).thenReturn(DISCOUNT_FACTOR);
        }
Beispiel #24
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivity()
        {
            SimpleRatesProvider prov = createProvider(VAL_DATE);

            PointSensitivities  point = PRICER.presentValueSensitivity(PERIOD, prov).build();
            double              relativeYearFraction = DAY_COUNT.relativeYearFraction(VAL_DATE, PAYMENT_DATE);
            double              expected             = -DISCOUNT_FACTOR * relativeYearFraction * AMOUNT_1000;
            ZeroRateSensitivity actual = (ZeroRateSensitivity)point.Sensitivities.get(0);

            assertEquals(actual.Currency, GBP);
            assertEquals(actual.CurveCurrency, GBP);
            assertEquals(actual.YearFraction, relativeYearFraction);
            assertEquals(actual.Sensitivity, expected, AMOUNT_1000 * TOLERANCE_PV);
        }
        public virtual void presentValue_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider(VAL_DATE);

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            double         lastClosingPrice = 0.0150;
            CurrencyAmount pvComputed       = OPTION_TRADE_PRICER.presentValue(FUTURE_OPTION_TRADE, prov, VOL_SIMPLE_MONEY_PRICE, lastClosingPrice);
            double         optionPrice      = OPTION_PRODUCT_PRICER.price(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);
            double         pvExpected       = (OPTION_PRODUCT_PRICER.marginIndex(OPTION, optionPrice) - OPTION_PRODUCT_PRICER.marginIndex(OPTION, lastClosingPrice)) * OPTION_QUANTITY;

            assertEquals(pvComputed.Amount, pvExpected, TOLERANCE_PV);
        }
        // ----------     present value normal vol sensitivity     ----------

        public virtual void presentvalue_normalVolSensitivity_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            IborFutureOptionSensitivity psProduct  = OPTION_PRODUCT_PRICER.priceSensitivityModelParamsVolatility(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);
            IborFutureOptionSensitivity psExpected = psProduct.withSensitivity(psProduct.Sensitivity * OPTION_PRODUCT_PRICER.marginIndex(OPTION, 1) * OPTION_QUANTITY);
            IborFutureOptionSensitivity psComputed = OPTION_TRADE_PRICER.presentValueSensitivityModelParamsVolatility(FUTURE_OPTION_TRADE, prov, VOL_SIMPLE_MONEY_PRICE);

            assertTrue(psExpected.compareKey(psComputed) == 0);
            assertEquals(psComputed.Sensitivity, psExpected.Sensitivity, TOLERANCE_PV_DELTA);
        }
        public virtual void priceSensitivityStickyStrike_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            PointSensitivities futurePriceSensitivity = OPTION_PRICER.FuturePricer.priceSensitivity(OPTION.UnderlyingFuture, prov);
            double             delta = OPTION_PRICER.deltaStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);
            PointSensitivities optionPriceSensitivityExpected = futurePriceSensitivity.multipliedBy(delta);
            PointSensitivities optionPriceSensitivityComputed = OPTION_PRICER.priceSensitivityRatesStickyStrike(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);

            assertTrue(optionPriceSensitivityExpected.equalWithTolerance(optionPriceSensitivityComputed, TOLERANCE_PRICE_DELTA));
        }
        public virtual void priceSensitivityNormalVolatility_from_env()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            double futurePrice = 1.0 - RATE;
            IborFutureOptionSensitivity optionVegaExpected = OPTION_PRICER.priceSensitivityModelParamsVolatility(OPTION, prov, VOL_SIMPLE_MONEY_PRICE, futurePrice);
            IborFutureOptionSensitivity optionVegaComputed = OPTION_PRICER.priceSensitivityModelParamsVolatility(OPTION, prov, VOL_SIMPLE_MONEY_PRICE);

            assertTrue(optionVegaExpected.compareKey(optionVegaComputed) == 0);
            assertEquals(optionVegaComputed.Sensitivity, optionVegaExpected.Sensitivity, TOLERANCE_PRICE_DELTA);
        }
Beispiel #29
0
        public virtual void test_presentValue_on_trade_date()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates     = mockIbor;
            prov.ValuationDate = FUTURE_TRADE.TradedPrice.get().TradeDate;
            when(mockIbor.rate(FUTURE.IborRate.Observation)).thenReturn(RATE);

            double lastClosingPrice = 1.025;
            DiscountingIborFutureTradePricer pricerFn = DiscountingIborFutureTradePricer.DEFAULT;
            double         expected = ((1.0 - RATE) - FUTURE_TRADE.TradedPrice.get().Price) * FUTURE.AccrualFactor * FUTURE.Notional * FUTURE_TRADE.Quantity;
            CurrencyAmount computed = pricerFn.presentValue(FUTURE_TRADE, prov, lastClosingPrice);

            assertEquals(computed.Amount, expected, TOLERANCE_PV);
            assertEquals(computed.Currency, FUTURE.Currency);
        }
        // ----------     price     ----------
        public virtual void price_from_future_price()
        {
            IborIndexRates      mockIbor = mock(typeof(IborIndexRates));
            SimpleRatesProvider prov     = new SimpleRatesProvider();

            prov.IborRates = mockIbor;
            when(mockIbor.rate(OPTION.UnderlyingFuture.IborRate.Observation)).thenReturn(RATE);

            double futurePrice                = 0.9875;
            double strike                     = OPTION.StrikePrice;
            double timeToExpiry               = ACT_365F.relativeYearFraction(VAL_DATE, OPTION.ExpiryDate);
            double priceSimpleMoneyness       = strike - futurePrice;
            double normalVol                  = PARAMETERS_PRICE.zValue(timeToExpiry, priceSimpleMoneyness);
            EuropeanVanillaOption option      = EuropeanVanillaOption.of(strike, timeToExpiry, OPTION.PutCall);
            NormalFunctionData    normalPoint = NormalFunctionData.of(futurePrice, 1.0, normalVol);
            double optionPriceExpected        = NORMAL_FUNCTION.getPriceFunction(option).apply(normalPoint);
            double optionPriceComputed        = OPTION_PRICER.price(OPTION, prov, VOL_SIMPLE_MONEY_PRICE, futurePrice);

            assertEquals(optionPriceComputed, optionPriceExpected, TOLERANCE_PRICE);
        }