//-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price of the Ibor future product.
        /// <para>
        /// The price of the product is the price on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the price of the product, in decimal form </returns>
        public virtual double price(ResolvedIborFuture future, RatesProvider ratesProvider)
        {
            IborIndexRates rates   = ratesProvider.iborIndexRates(future.Index);
            double         forward = rates.rate(future.IborRate.Observation);

            return(1.0 - forward);
        }
        public virtual void test_rateSensitivity_finiteDifference()
        {
            double         eps         = 1.0e-7;
            RatesProvider  mockProv    = mock(typeof(RatesProvider));
            IborIndexRates mockRates3M = mock(typeof(IborIndexRates));
            IborIndexRates mockRates6M = mock(typeof(IborIndexRates));

            when(mockProv.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M);
            when(mockProv.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M);
            when(mockRates3M.rate(GBP_LIBOR_3M_OBS)).thenReturn(RATE3);
            when(mockRates6M.rate(GBP_LIBOR_6M_OBS)).thenReturn(RATE6);
            when(mockRates3M.ratePointSensitivity(GBP_LIBOR_3M_OBS)).thenReturn(SENSITIVITY3);
            when(mockRates6M.ratePointSensitivity(GBP_LIBOR_6M_OBS)).thenReturn(SENSITIVITY6);

            IborInterpolatedRateComputation          ro  = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA);
            ForwardIborInterpolatedRateComputationFn obs = ForwardIborInterpolatedRateComputationFn.DEFAULT;
            PointSensitivityBuilder test = obs.rateSensitivity(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProv);

            IborIndexRates mockRatesUp3M = mock(typeof(IborIndexRates));

            when(mockRatesUp3M.rate(GBP_LIBOR_3M_OBS)).thenReturn(RATE3 + eps);
            IborIndexRates mockRatesDw3M = mock(typeof(IborIndexRates));

            when(mockRatesDw3M.rate(GBP_LIBOR_3M_OBS)).thenReturn(RATE3 - eps);
            IborIndexRates mockRatesUp6M = mock(typeof(IborIndexRates));

            when(mockRatesUp6M.rate(GBP_LIBOR_6M_OBS)).thenReturn(RATE6 + eps);
            IborIndexRates mockRatesDw6M = mock(typeof(IborIndexRates));

            when(mockRatesDw6M.rate(GBP_LIBOR_6M_OBS)).thenReturn(RATE6 - eps);

            RatesProvider mockProvUp3M = mock(typeof(RatesProvider));

            when(mockProvUp3M.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRatesUp3M);
            when(mockProvUp3M.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M);
            RatesProvider mockProvDw3M = mock(typeof(RatesProvider));

            when(mockProvDw3M.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRatesDw3M);
            when(mockProvDw3M.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M);
            RatesProvider mockProvUp6M = mock(typeof(RatesProvider));

            when(mockProvUp6M.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M);
            when(mockProvUp6M.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRatesUp6M);
            RatesProvider mockProvDw6M = mock(typeof(RatesProvider));

            when(mockProvDw6M.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M);
            when(mockProvDw6M.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRatesDw6M);

            double rateUp3M        = obs.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProvUp3M);
            double rateDw3M        = obs.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProvDw3M);
            double senseExpected3M = 0.5 * (rateUp3M - rateDw3M) / eps;

            double rateUp6M        = obs.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProvUp6M);
            double rateDw6M        = obs.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProvDw6M);
            double senseExpected6M = 0.5 * (rateUp6M - rateDw6M) / eps;

            assertEquals(test.build().Sensitivities.get(0).Sensitivity, senseExpected3M, eps);
            assertEquals(test.build().Sensitivities.get(1).Sensitivity, senseExpected6M, eps);
        }
Exemplo n.º 3
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);
        }
        //-------------------------------------------------------------------------
        public virtual double rate(IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            IborIndexObservation obs1   = computation.ShortObservation;
            IborIndexObservation obs2   = computation.LongObservation;
            IborIndexRates       rates1 = provider.iborIndexRates(obs1.Index);
            IborIndexRates       rates2 = provider.iborIndexRates(obs2.Index);

            double      rate1   = rates1.rate(obs1);
            double      rate2   = rates2.rate(obs2);
            DoublesPair weights = this.weights(obs1, obs2, endDate);

            return(((rate1 * weights.First) + (rate2 * weights.Second)) / (weights.First + weights.Second));
        }
        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);
        }
Exemplo n.º 6
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);
        }
        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);
        }
        // ----------     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 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);
        }
        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));
        }
        // ----------     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 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);
        }
Exemplo n.º 13
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);
        }
        //-------------------------------------------------------------------------
        public virtual double rate(IborRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            IborIndexRates rates = provider.iborIndexRates(computation.Index);

            return(rates.rate(computation.Observation));
        }
Exemplo n.º 16
0
        // Compute the rate adjusted by the weight for one IborAverageFixing.
        private double weightedRate(IborAveragedFixing fixing, IborIndexRates rates)
        {
            double rate = fixing.FixedRate.GetValueOrDefault(rates.rate(fixing.Observation));

            return(rate * fixing.Weight);
        }