/// <summary>
        /// Calculates the currency exposure of the bond future trade with z-spread.
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates
        /// of the issuer discounting curve.
        /// </para>
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodPerYear">  the number of periods per year </param>
        /// <returns> the currency exposure of the bond future trade </returns>
        public MultiCurrencyAmount currencyExposureWithZSpread(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear)
        {
            double price          = priceWithZSpread(trade, discountingProvider, zSpread, compoundedRateType, periodPerYear);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(MultiCurrencyAmount.of(presentValue(trade, price, referencePrice)));
        }
        public virtual void test_currencyExposureWithZSpread()
        {
            MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposureWithZSpread(FUTURE_TRADE, PROVIDER, SETTLE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
            CurrencyAmount      pv         = TRADE_PRICER.presentValueWithZSpread(FUTURE_TRADE, PROVIDER, SETTLE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);

            assertEquals(ceComputed, MultiCurrencyAmount.of(pv));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure of the bond future trade.
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <returns> the currency exposure of the bond future trade </returns>
        public MultiCurrencyAmount currencyExposure(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice)
        {
            double price          = this.price(trade, discountingProvider);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(MultiCurrencyAmount.of(presentValue(trade, price, referencePrice)));
        }
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure()
        {
            MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposure(FUTURE_TRADE, PROVIDER, SETTLE_PRICE);
            CurrencyAmount      pv         = TRADE_PRICER.presentValue(FUTURE_TRADE, PROVIDER, SETTLE_PRICE);

            assertEquals(ceComputed, MultiCurrencyAmount.of(pv));
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = PRICER.currentCash(CAP_ONE_LEG, RATES, VOLS);
            MultiCurrencyAmount cc2 = PRICER.currentCash(CAP_TWO_LEGS, RATES, VOLS);

            assertEquals(cc1, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
예제 #6
0
 /// <summary>
 /// Calculates the current cash.
 /// </summary>
 /// <param name="fx">  the product </param>
 /// <param name="valuationDate">  the valuation date </param>
 /// <returns> the current cash </returns>
 public virtual MultiCurrencyAmount currentCash(ResolvedFxSingle fx, LocalDate valuationDate)
 {
     if (valuationDate.isEqual(fx.PaymentDate))
     {
         return(MultiCurrencyAmount.of(fx.BaseCurrencyPayment.Value, fx.CounterCurrencyPayment.Value));
     }
     return(MultiCurrencyAmount.empty());
 }
예제 #7
0
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount computedWithPayLeg  = PRICER.currentCash(TRADE_PAYLEG, RATES, VOLS);
            MultiCurrencyAmount computedWithPremium = PRICER.currentCash(TRADE_PREMIUM, RATES, VOLS);

            assertEquals(computedWithPayLeg, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(computedWithPremium, MultiCurrencyAmount.of(PREMIUM.Value));
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = TRADE_PRICER.currentCash(CMS_TRADE_PREMIUM, RATES_PROVIDER, VOLATILITIES);
            MultiCurrencyAmount cc2 = TRADE_PRICER.currentCash(CMS_TRADE, RATES_PROVIDER, VOLATILITIES);

            assertEquals(cc1, MultiCurrencyAmount.of(PREMIUM.Value));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
예제 #9
0
        public virtual void test_presentValue()
        {
            MultiCurrencyAmount pvSensiTrade   = PRICER_TRADE.presentValue(OPTION_TRADE, RATES_PROVIDER, VOLS);
            CurrencyAmount      pvSensiProduct = PRICER_PRODUCT.presentValue(OPTION_PRODUCT, RATES_PROVIDER, VOLS);
            CurrencyAmount      pvSensiPremium = PRICER_PAYMENT.presentValue(PREMIUM, RATES_PROVIDER);

            assertEquals(pvSensiTrade, MultiCurrencyAmount.of(pvSensiProduct, pvSensiPremium));
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = PRODUCT_PRICER.currentCash(CMS_ONE_LEG, RATES_PROVIDER, VOLATILITIES);
            MultiCurrencyAmount cc2 = PRODUCT_PRICER.currentCash(CMS_TWO_LEGS, RATES_PROVIDER, VOLATILITIES);

            assertEquals(cc1, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
        public virtual void test_presentValueGamma()
        {
            MultiCurrencyAmount computed1 = PRICER.presentValueGamma(CAP_ONE_LEG, RATES, VOLS);
            MultiCurrencyAmount computed2 = PRICER.presentValueGamma(CAP_TWO_LEGS, RATES, VOLS);
            CurrencyAmount      cap       = PRICER_CAP_LEG.presentValueGamma(CAP_LEG, RATES, VOLS);

            assertEquals(computed1, MultiCurrencyAmount.of(cap));
            assertEquals(computed2, MultiCurrencyAmount.of(cap));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the FX barrier option trade.
        /// <para>
        /// The present value of the trade is the value on the valuation date.
        /// </para>
        /// <para>
        /// The trinomial tree is first calibrated to Black volatilities,
        /// then the price is computed based on the calibrated tree.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the option trade </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="volatilities">  the Black volatility provider </param>
        /// <returns> the present value of the trade </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedFxSingleBarrierOptionTrade trade, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities)
        {
            ResolvedFxSingleBarrierOption product = trade.Product;
            CurrencyAmount pvProduct = productPricer.presentValue(product, ratesProvider, volatilities);
            Payment        premium   = trade.Premium;
            CurrencyAmount pvPremium = paymentPricer.presentValue(premium, ratesProvider);

            return(MultiCurrencyAmount.of(pvProduct, pvPremium));
        }
        public virtual void test_presentValue()
        {
            MultiCurrencyAmount pv1   = PRODUCT_PRICER.presentValue(CMS_ONE_LEG, RATES_PROVIDER, VOLATILITIES);
            MultiCurrencyAmount pv2   = PRODUCT_PRICER.presentValue(CMS_TWO_LEGS, RATES_PROVIDER, VOLATILITIES);
            CurrencyAmount      pvCms = CMS_LEG_PRICER.presentValue(CMS_LEG, RATES_PROVIDER, VOLATILITIES);
            CurrencyAmount      pvPay = SWAP_LEG_PRICER.presentValue(PAY_LEG, RATES_PROVIDER);

            assertEquals(pv1, MultiCurrencyAmount.of(pvCms));
            assertEquals(pv2, MultiCurrencyAmount.of(pvCms).plus(pvPay));
        }
        public virtual void test_currentCash_onPay()
        {
            MultiCurrencyAmount cc1   = PRODUCT_PRICER.currentCash(CMS_ONE_LEG, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY);
            MultiCurrencyAmount cc2   = PRODUCT_PRICER.currentCash(CMS_TWO_LEGS, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY);
            CurrencyAmount      ccCms = CMS_LEG_PRICER.currentCash(CMS_LEG, RATES_PROVIDER_ON_PAY, VOLATILITIES_ON_PAY);
            CurrencyAmount      ccPay = SWAP_LEG_PRICER.currentCash(PAY_LEG, RATES_PROVIDER_ON_PAY);

            assertEquals(cc1, MultiCurrencyAmount.of(ccCms));
            assertEquals(cc2, MultiCurrencyAmount.of(ccCms).plus(ccPay));
        }
예제 #15
0
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure_RatePaymentPeriod()
        {
            MultiCurrencyAmount expected = MultiCurrencyAmount.of(GBP, 0.0123d);
            SwapPaymentPeriodPricer <RatePaymentPeriod> mockNotionalExchangeFn = mock(typeof(SwapPaymentPeriodPricer));

            when(mockNotionalExchangeFn.currencyExposure(SwapDummyData.FIXED_RATE_PAYMENT_PERIOD_REC_GBP, MOCK_PROV)).thenReturn(expected);
            DispatchingSwapPaymentPeriodPricer test = new DispatchingSwapPaymentPeriodPricer(mockNotionalExchangeFn, MOCK_KNOWN);

            assertEquals(test.currencyExposure(SwapDummyData.FIXED_RATE_PAYMENT_PERIOD_REC_GBP, MOCK_PROV), expected);
        }
        public virtual void test_currentCash_onPay()
        {
            MultiCurrencyAmount cc1   = PRICER.currentCash(CAP_ONE_LEG, RATES_PAY, VOLS_PAY);
            MultiCurrencyAmount cc2   = PRICER.currentCash(CAP_TWO_LEGS, RATES_PAY, VOLS_PAY);
            CurrencyAmount      ccCap = PRICER_CAP_LEG.currentCash(CAP_LEG, RATES_PAY, VOLS_PAY);
            CurrencyAmount      ccPay = PRICER_PAY_LEG.currentCash(PAY_LEG, RATES_PAY);

            assertEquals(cc1, MultiCurrencyAmount.of(ccCap));
            assertEquals(cc2, MultiCurrencyAmount.of(ccCap).plus(ccPay));
        }
예제 #17
0
        public virtual void test_currencyExposure_FxResetNotionalExchange()
        {
            MultiCurrencyAmount expected = MultiCurrencyAmount.of(Currency.GBP, 0.0123d);
            SwapPaymentEventPricer <FxResetNotionalExchange> mockCalledFn = mock(typeof(SwapPaymentEventPricer));

            when(mockCalledFn.currencyExposure(SwapDummyData.FX_RESET_NOTIONAL_EXCHANGE_REC_USD, MOCK_PROV)).thenReturn(expected);
            DispatchingSwapPaymentEventPricer test = new DispatchingSwapPaymentEventPricer(MOCK_NOTIONAL_EXG, mockCalledFn);

            assertEquals(test.currencyExposure(SwapDummyData.FX_RESET_NOTIONAL_EXCHANGE_REC_USD, MOCK_PROV), expected);
        }
예제 #18
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the FX product by discounting each payment in its own currency.
        /// </summary>
        /// <param name="fx">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value in the two natural currencies </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedFxSingle fx, RatesProvider provider)
        {
            if (provider.ValuationDate.isAfter(fx.PaymentDate))
            {
                return(MultiCurrencyAmount.empty());
            }
            CurrencyAmount pv1 = paymentPricer.presentValue(fx.BaseCurrencyPayment, provider);
            CurrencyAmount pv2 = paymentPricer.presentValue(fx.CounterCurrencyPayment, provider);

            return(MultiCurrencyAmount.of(pv1, pv2));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the Ibor cap/floor product.
        /// <para>
        /// The present value of the product is the value on the valuation date.
        /// </para>
        /// <para>
        /// The cap/floor leg and pay leg are typically in the same currency, thus the
        /// present value gamma is expressed as a single currency amount in most cases.
        ///
        /// </para>
        /// </summary>
        /// <param name="capFloor">  the Ibor cap/floor product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="volatilities">  the volatilities </param>
        /// <returns> the present value </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedIborCapFloor capFloor, RatesProvider ratesProvider, IborCapletFloorletVolatilities volatilities)
        {
            CurrencyAmount pvCapFloorLeg = capFloorLegPricer.presentValue(capFloor.CapFloorLeg, ratesProvider, volatilities);

            if (!capFloor.PayLeg.Present)
            {
                return(MultiCurrencyAmount.of(pvCapFloorLeg));
            }
            CurrencyAmount pvPayLeg = payLegPricer.presentValue(capFloor.PayLeg.get(), ratesProvider);

            return(MultiCurrencyAmount.of(pvCapFloorLeg).plus(pvPayLeg));
        }
        /// <summary>
        /// Calculates the current cash of the product.
        /// </summary>
        /// <param name="cms">  the CMS product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the current cash </returns>
        public virtual MultiCurrencyAmount currentCash(ResolvedCms cms, RatesProvider ratesProvider)
        {
            CurrencyAmount ccCmsLeg = cmsLegPricer.currentCash(cms.CmsLeg, ratesProvider);

            if (!cms.PayLeg.Present)
            {
                return(MultiCurrencyAmount.of(ccCmsLeg));
            }
            CurrencyAmount ccPayLeg = swapPricer.LegPricer.currentCash(cms.PayLeg.get(), ratesProvider);

            return(MultiCurrencyAmount.of(ccPayLeg).plus(ccCmsLeg));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the CMS product by simple forward estimation.
        /// </summary>
        /// <param name="cms">  the CMS product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the present value </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedCms cms, RatesProvider ratesProvider)
        {
            CurrencyAmount pvCmsLeg = cmsLegPricer.presentValue(cms.CmsLeg, ratesProvider);

            if (!cms.PayLeg.Present)
            {
                return(MultiCurrencyAmount.of(pvCmsLeg));
            }
            CurrencyAmount pvPayLeg = swapPricer.LegPricer.presentValue(cms.PayLeg.get(), ratesProvider);

            return(MultiCurrencyAmount.of(pvCmsLeg).plus(pvPayLeg));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure by discounting each payment in its own currency.
        /// </summary>
        /// <param name="ndf">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the currency exposure </returns>
        public virtual MultiCurrencyAmount currencyExposure(ResolvedFxNdf ndf, RatesProvider provider)
        {
            if (provider.ValuationDate.isAfter(ndf.PaymentDate))
            {
                return(MultiCurrencyAmount.empty());
            }
            Currency       ccySettle      = ndf.SettlementCurrency;
            CurrencyAmount notionalSettle = ndf.SettlementCurrencyNotional;
            double         dfSettle       = provider.discountFactor(ccySettle, ndf.PaymentDate);
            Currency       ccyOther       = ndf.NonDeliverableCurrency;
            double         agreedRate     = ndf.AgreedFxRate.fxRate(ccySettle, ccyOther);
            double         dfOther        = provider.discountFactor(ccyOther, ndf.PaymentDate);

            return(MultiCurrencyAmount.of(notionalSettle.multipliedBy(dfSettle)).plus(CurrencyAmount.of(ccyOther, -notionalSettle.Amount * agreedRate * dfOther)));
        }
        //-------------------------------------------------------------------------
        public virtual MultiCurrencyAmount currencyExposure(FxResetNotionalExchange @event, RatesProvider provider)
        {
            LocalDate    fixingDate = @event.Observation.FixingDate;
            FxIndexRates rates      = provider.fxIndexRates(@event.Observation.Index);
            double       df         = provider.discountFactor(@event.Currency, @event.PaymentDate);

            if (!fixingDate.isAfter(provider.ValuationDate) && rates.Fixings.get(fixingDate).HasValue)
            {
                double fxRate = rates.rate(@event.Observation, @event.ReferenceCurrency);
                return(MultiCurrencyAmount.of(CurrencyAmount.of(@event.Currency, @event.Notional * df * fxRate)));
            }
            LocalDate maturityDate          = @event.Observation.MaturityDate;
            double    fxRateSpotSensitivity = rates.FxForwardRates.rateFxSpotSensitivity(@event.ReferenceCurrency, maturityDate);

            return(MultiCurrencyAmount.of(CurrencyAmount.of(@event.ReferenceCurrency, @event.Notional * df * fxRateSpotSensitivity)));
        }
예제 #24
0
        //-------------------------------------------------------------------------
        public virtual MultiCurrencyAmount currencyExposure(RatePaymentPeriod period, RatesProvider provider)
        {
            double df = provider.discountFactor(period.Currency, period.PaymentDate);

            if (period.FxReset.Present)
            {
                FxReset      fxReset    = period.FxReset.get();
                LocalDate    fixingDate = fxReset.Observation.FixingDate;
                FxIndexRates rates      = provider.fxIndexRates(fxReset.Observation.Index);
                if (!fixingDate.isAfter(provider.ValuationDate) && rates.Fixings.get(fixingDate).HasValue)
                {
                    double fxRate = rates.rate(fxReset.Observation, fxReset.ReferenceCurrency);
                    return(MultiCurrencyAmount.of(period.Currency, accrualWithNotional(period, period.Notional * fxRate * df, provider)));
                }
                double fxRateSpotSensitivity = rates.FxForwardRates.rateFxSpotSensitivity(fxReset.ReferenceCurrency, fxReset.Observation.MaturityDate);
                return(MultiCurrencyAmount.of(fxReset.ReferenceCurrency, accrualWithNotional(period, period.Notional * fxRateSpotSensitivity * df, provider)));
            }
            return(MultiCurrencyAmount.of(period.Currency, accrualWithNotional(period, period.Notional * df, provider)));
        }
 /// <summary>
 /// Calculates the currency exposure of the FRA trade.
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the currency exposure </returns>
 public virtual MultiCurrencyAmount currencyExposure(ResolvedFraTrade trade, RatesProvider provider)
 {
     return(MultiCurrencyAmount.of(presentValue(trade, provider)));
 }
 //-------------------------------------------------------------------------
 public virtual void test_currencyExposure()
 {
     assertEquals(PRICER_TRADE.currencyExposure(RFRA_TRADE, RATES_PROVIDER), MultiCurrencyAmount.of(PRICER_TRADE.presentValue(RFRA_TRADE, RATES_PROVIDER)));
 }
예제 #27
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Computes the currency exposure of the swaption trade.
 /// </summary>
 /// <param name="trade">  the swaption trade </param>
 /// <param name="ratesProvider">  the rates provider </param>
 /// <param name="swaptionVolatilities">  the volatilities </param>
 /// <returns> the currency exposure </returns>
 public virtual MultiCurrencyAmount currencyExposure(ResolvedSwaptionTrade trade, RatesProvider ratesProvider, SabrSwaptionVolatilities swaptionVolatilities)
 {
     return(MultiCurrencyAmount.of(presentValue(trade, ratesProvider, swaptionVolatilities)));
 }
예제 #28
0
        /// <summary>
        /// Calculates the currency exposure of the bond trade with z-spread.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodsPerYear">  the number of periods per year </param>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposureWithZSpread(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            CurrencyAmount pv = presentValueWithZSpread(trade, ratesProvider, discountingProvider, zSpread, compoundedRateType, periodsPerYear);

            return(MultiCurrencyAmount.of(pv));
        }
예제 #29
0
        /// <summary>
        /// Calculates the currency exposure of the bond trade.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposure(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            CurrencyAmount pv = presentValue(trade, ratesProvider, discountingProvider);

            return(MultiCurrencyAmount.of(pv));
        }
예제 #30
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure of the bond trade.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <param name="refData">  the reference data used to calculate the settlement date </param>
        /// <param name="cleanRealPrice">  the clean real price </param>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposureFromCleanPrice(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice)
        {
            CurrencyAmount pv = presentValueFromCleanPrice(trade, ratesProvider, discountingProvider, refData, cleanRealPrice);

            return(MultiCurrencyAmount.of(pv));
        }