示例#1
0
 // current cash for one scenario
 internal MultiCurrencyAmount accruedInterest(ResolvedSwapTrade trade, RatesProvider ratesProvider)
 {
     return(tradePricer.accruedInterest(trade, ratesProvider));
 }
示例#2
0
        // calculates the present value curve sensitivity of the periods composing the leg in the currency of the swap leg
        internal virtual PointSensitivityBuilder presentValueSensitivityPeriodsInternal(ResolvedSwapLeg leg, RatesProvider provider)
        {
            PointSensitivityBuilder builder = PointSensitivityBuilder.none();

            foreach (SwapPaymentPeriod period in leg.PaymentPeriods)
            {
                if (!period.PaymentDate.isBefore(provider.ValuationDate))
                {
                    builder = builder.combinedWith(paymentPeriodPricer.presentValueSensitivity(period, provider));
                }
            }
            return(builder);
        }
示例#3
0
        private MultiCurrencyAmount currencyExposureEventsInternal(ResolvedSwapLeg leg, RatesProvider provider)
        {
            MultiCurrencyAmount total = MultiCurrencyAmount.empty();

            foreach (SwapPaymentEvent @event in leg.PaymentEvents)
            {
                if ([email protected](provider.ValuationDate))
                {
                    total = total.plus(paymentEventPricer.currencyExposure(@event, provider));
                }
            }
            return(total);
        }
示例#4
0
 // calculates the present value in the currency of the swap leg
 internal virtual double forecastValueInternal(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(forecastValuePeriodsInternal(leg, provider) + forecastValueEventsInternal(leg, provider));
 }
示例#5
0
 /// <summary>
 /// Calculates the forecast value sensitivity of the swap leg.
 /// <para>
 /// The forecast value sensitivity of the leg is the sensitivity of the forecast value to
 /// the underlying curves.
 ///
 /// </para>
 /// </summary>
 /// <param name="leg">  the leg </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the forecast value curve sensitivity of the swap leg </returns>
 public virtual PointSensitivityBuilder forecastValueSensitivity(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(legValueSensitivity(leg, provider, paymentPeriodPricer.forecastValueSensitivity, paymentEventPricer.forecastValueSensitivity));
 }
        public virtual void calibration_present_value_twoGroups()
        {
            RatesProvider result = CALIBRATOR.calibrate(ImmutableList.of(GROUP_1, GROUP_2), KNOWN_DATA, ALL_QUOTES_BD, REF_DATA);

            assertResult(result, ALL_QUOTES_BD);
        }
示例#7
0
 // calculates the present value in the currency of the swap leg
 internal virtual double presentValueInternal(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(presentValuePeriodsInternal(leg, provider) + presentValueEventsInternal(leg, provider));
 }
示例#8
0
 /// <summary>
 /// Calculates the forecast value sensitivity of the swap product.
 /// <para>
 /// The forecast value sensitivity of the product is the sensitivity of the forecast value to
 /// the underlying curves.
 ///
 /// </para>
 /// </summary>
 /// <param name="swap">  the product </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the forecast value curve sensitivity of the swap product </returns>
 public virtual PointSensitivityBuilder forecastValueSensitivity(ResolvedSwap swap, RatesProvider provider)
 {
     return(swapValueSensitivity(swap, provider, legPricer.forecastValueSensitivity));
 }
示例#9
0
        // calculate present or forecast value sensitivity for the swap
        private static PointSensitivityBuilder swapValueSensitivity(ResolvedSwap swap, RatesProvider provider, System.Func <ResolvedSwapLeg, RatesProvider, PointSensitivityBuilder> legFn)
        {
            PointSensitivityBuilder builder = PointSensitivityBuilder.none();

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                builder = builder.combinedWith(legFn(leg, provider));
            }
            return(builder);
        }
示例#10
0
 /// <summary>
 /// Calculates the forecast value of the swap product.
 /// <para>
 /// The forecast value of the product is the value on the valuation date without present value discounting.
 /// The result is expressed using the payment currency of each leg.
 ///
 /// </para>
 /// </summary>
 /// <param name="swap">  the product </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the forecast value of the swap product </returns>
 public virtual MultiCurrencyAmount forecastValue(ResolvedSwap swap, RatesProvider provider)
 {
     return(swapValue(provider, swap, legPricer.forecastValueInternal));
 }
示例#11
0
        /// <summary>
        /// Calculates the present value sensitivity of the swap product converted in a given currency.
        /// <para>
        /// The present value sensitivity of the product is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="currency">  the currency to convert to </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value curve sensitivity of the swap product converted in the given currency </returns>
        public virtual PointSensitivityBuilder presentValueSensitivity(ResolvedSwap swap, Currency currency, RatesProvider provider)
        {
            PointSensitivityBuilder builder = PointSensitivityBuilder.none();

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                PointSensitivityBuilder ls          = legPricer.presentValueSensitivity(leg, provider);
                PointSensitivityBuilder lsConverted = ls.withCurrency(currency).multipliedBy(provider.fxRate(leg.Currency, currency));
                builder = builder.combinedWith(lsConverted);
            }
            return(builder);
        }
示例#12
0
 // current cash for one scenario
 internal MultiCurrencyAmount currentCash(ResolvedSwapTrade trade, RatesProvider ratesProvider)
 {
     return(tradePricer.currentCash(trade, ratesProvider));
 }
示例#13
0
        // present value for a leg
        private SwapLegAmount legAmount(ResolvedSwapLeg leg, RatesProvider provider)
        {
            CurrencyAmount amount = tradePricer.ProductPricer.LegPricer.presentValue(leg, provider);

            return(SwapLegAmount.of(leg, amount));
        }
示例#14
0
        // leg present value for one scenario
        internal LegAmounts legPresentValue(ResolvedSwapTrade trade, RatesProvider ratesProvider)
        {
            IList <LegAmount> legAmounts = trade.Product.Legs.Select(leg => legAmount(leg, ratesProvider)).ToList();

            return(LegAmounts.of(legAmounts));
        }
        //-------------------------------------------------------------------------
        public virtual void calibration_present_value_oneGroup_no_fixing()
        {
            RatesProvider result = CALIBRATOR.calibrate(CURVE_GROUP_CONFIG, ALL_QUOTES_BD, REF_DATA);

            assertResult(result, ALL_QUOTES_BD);
        }
示例#16
0
        /// <summary>
        /// Calculates the par spread curve sensitivity for a swap.
        /// <para>
        /// The par spread is the common spread on all payments of the first leg for which the total swap present value is 0.
        /// </para>
        /// <para>
        /// The par spread is computed with respect to the first leg. For that leg, all the payments have a unique
        /// accrual period (no compounding) and no FX reset.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the par spread curve sensitivity of the swap product </returns>
        public virtual PointSensitivityBuilder parSpreadSensitivity(ResolvedSwap swap, RatesProvider provider)
        {
            ResolvedSwapLeg         referenceLeg    = swap.Legs.get(0);
            Currency                ccyReferenceLeg = referenceLeg.Currency;
            double                  convertedPv     = presentValue(swap, ccyReferenceLeg, provider).Amount;
            PointSensitivityBuilder convertedPvDr   = presentValueSensitivity(swap, ccyReferenceLeg, provider);
            // try one payment compounding, typically for inflation swaps
            Triple <bool, int, double> fixedCompounded = checkFixedCompounded(referenceLeg);

            if (fixedCompounded.First)
            {
                double df = provider.discountFactor(ccyReferenceLeg, referenceLeg.PaymentPeriods.get(0).PaymentDate);
                PointSensitivityBuilder dfDr = provider.discountFactors(ccyReferenceLeg).zeroRatePointSensitivity(referenceLeg.PaymentPeriods.get(0).PaymentDate);
                double referenceConvertedPv  = legPricer.presentValue(referenceLeg, provider).Amount;
                PointSensitivityBuilder referenceConvertedPvDr = legPricer.presentValueSensitivity(referenceLeg, provider);
                double notional = ((RatePaymentPeriod)referenceLeg.PaymentPeriods.get(0)).Notional;
                PointSensitivityBuilder dParSpreadDr = convertedPvDr.combinedWith(referenceConvertedPvDr.multipliedBy(-1)).multipliedBy(-1.0d / (df * notional)).combinedWith(dfDr.multipliedBy((convertedPv - referenceConvertedPv) / (df * df * notional))).multipliedBy(1.0d / fixedCompounded.Second * Math.Pow(-(convertedPv - referenceConvertedPv) / (df * notional) + 1.0d, 1.0d / fixedCompounded.Second - 1.0d));
                return(dParSpreadDr);
            }
            double pvbp = legPricer.pvbp(referenceLeg, provider);
            // Backward sweep
            double convertedPvBar          = -1d / pvbp;
            double pvbpBar                 = convertedPv / (pvbp * pvbp);
            PointSensitivityBuilder pvbpDr = legPricer.pvbpSensitivity(referenceLeg, provider);

            return(convertedPvDr.multipliedBy(convertedPvBar).combinedWith(pvbpDr.multipliedBy(pvbpBar)));
        }
        public virtual void calibration_present_value_oneGroup_holiday()
        {
            RatesProvider result = CALIBRATOR.calibrate(CURVE_GROUP_CONFIG, ALL_QUOTES_HO.combinedWith(TS_HO_LIBOR3M), REF_DATA);

            assertResult(result, ALL_QUOTES_HO);
        }
示例#18
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the future cash flows of the swap product.
        /// <para>
        /// Each expected cash flow is added to the result.
        /// This is based on <seealso cref="#forecastValue(ResolvedSwap, RatesProvider)"/>.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the cash flow </returns>
        public virtual CashFlows cashFlows(ResolvedSwap swap, RatesProvider provider)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            return(swap.Legs.Select(leg => legPricer.cashFlows(leg, provider)).Aggregate(CashFlows.NONE, CashFlows::combinedWith));
        }
示例#19
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the swap leg, converted to the specified currency.
        /// <para>
        /// The present value of the leg is the value on the valuation date.
        /// This is the discounted forecast value.
        /// The result is converted to the specified currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="leg">  the leg </param>
        /// <param name="currency">  the currency to convert to </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value of the swap leg in the specified currency </returns>
        public virtual CurrencyAmount presentValue(ResolvedSwapLeg leg, Currency currency, RatesProvider provider)
        {
            double pv = presentValueInternal(leg, provider);

            return(CurrencyAmount.of(currency, (pv * provider.fxRate(leg.Currency, currency))));
        }
示例#20
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the swap product, converted to the specified currency.
        /// <para>
        /// The present value of the product is the value on the valuation date.
        /// This is the discounted forecast value.
        /// The result is converted to the specified currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="currency">  the currency to convert to </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value of the swap product in the specified currency </returns>
        public virtual CurrencyAmount presentValue(ResolvedSwap swap, Currency currency, RatesProvider provider)
        {
            double totalPv = 0;

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                double pv = legPricer.presentValueInternal(leg, provider);
                totalPv += (pv * provider.fxRate(leg.Currency, currency));
            }
            return(CurrencyAmount.of(currency, totalPv));
        }
示例#21
0
 /// <summary>
 /// Calculates the forecast value of the swap leg.
 /// <para>
 /// The forecast value of the leg is the value on the valuation date without present value discounting.
 /// The result is returned using the payment currency of the leg.
 ///
 /// </para>
 /// </summary>
 /// <param name="leg">  the leg </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the forecast value of the swap leg </returns>
 public virtual CurrencyAmount forecastValue(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(CurrencyAmount.of(leg.Currency, forecastValueInternal(leg, provider)));
 }
示例#22
0
        //-------------------------------------------------------------------------
        public virtual void calibration_present_value_oneGroup()
        {
            RatesProvider result = CALIBRATOR.calibrate(CURVE_GROUP_CONFIG, ALL_QUOTES, REF_DATA);

            assertPresentValue(result);
        }
示例#23
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the coupon equivalent of a swap leg.
 /// <para>
 /// The coupon equivalent is the common fixed coupon for all the periods which would
 /// result in the same present value of the leg.
 /// </para>
 /// <para>
 /// This is used in particular for swaption pricing with a model on the swap rate.
 ///
 /// </para>
 /// </summary>
 /// <param name="leg">  the swap leg </param>
 /// <param name="provider">  the rates provider </param>
 /// <param name="pvbp">  the present value of a basis point </param>
 /// <returns> the fixed coupon equivalent </returns>
 public virtual double couponEquivalent(ResolvedSwapLeg leg, RatesProvider provider, double pvbp)
 {
     return(presentValuePeriodsInternal(leg, provider) / pvbp);
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private DefaultRatesMarketData(RatesMarketDataLookup lookup, com.opengamma.strata.data.MarketData marketData)
        private DefaultRatesMarketData(RatesMarketDataLookup lookup, MarketData marketData)
        {
            this.lookup                = ArgChecker.notNull(lookup, "lookup");
            this.marketData            = ArgChecker.notNull(marketData, "marketData");
            this.ratesProvider_Renamed = lookup.ratesProvider(marketData);
        }
示例#25
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the Present Value of a Basis Point curve sensitivity for a fixed swap leg.
        /// <para>
        /// The Present Value of a Basis Point is the value of the leg when the rate is equal to 1.
        /// A better name would be "Present Value of 1".
        /// The quantity is also known as "physical annuity" or "level".
        /// </para>
        /// <para>
        /// Each period must not have FX reset or compounding.
        /// They must not be of type <seealso cref="KnownAmountSwapPaymentPeriod"/>.
        ///
        /// </para>
        /// </summary>
        /// <param name="fixedLeg">  the swap fixed leg </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the Present Value of a Basis Point sensitivity to the curves </returns>
        public virtual PointSensitivityBuilder pvbpSensitivity(ResolvedSwapLeg fixedLeg, RatesProvider provider)
        {
            PointSensitivityBuilder builder = PointSensitivityBuilder.none();

            foreach (SwapPaymentPeriod period in fixedLeg.PaymentPeriods)
            {
                builder = builder.combinedWith(paymentPeriodPricer.pvbpSensitivity(period, provider));
            }
            return(builder);
        }
 /// <summary>
 /// Calibrates caplet volatilities to cap volatilities.
 /// </summary>
 /// <param name="definition">  the caplet volatility definition </param>
 /// <param name="calibrationDateTime">  the calibration time </param>
 /// <param name="capFloorData">  the cap data </param>
 /// <param name="ratesProvider">  the rates provider </param>
 /// <returns> the calibration result </returns>
 public abstract IborCapletFloorletVolatilityCalibrationResult calibrate(IborCapletFloorletVolatilityDefinition definition, ZonedDateTime calibrationDateTime, RawOptionData capFloorData, RatesProvider ratesProvider);
示例#27
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the currency exposure of the swap leg.
 /// </summary>
 /// <param name="leg">  the leg </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the currency exposure of the swap leg </returns>
 public virtual MultiCurrencyAmount currencyExposure(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(currencyExposurePeriodsInternal(leg, provider).plus(currencyExposureEventsInternal(leg, provider)));
 }
        //-------------------------------------------------------------------------
        // create complete lists of caps, volatilities, strikes, expiries
        protected internal virtual void reduceRawData(IborCapletFloorletVolatilityDefinition definition, RatesProvider ratesProvider, DoubleArray strikes, DoubleArray volatilityData, DoubleArray errors, LocalDate startDate, LocalDate endDate, SurfaceMetadata metadata, System.Func <Surface, IborCapletFloorletVolatilities> volatilityFunction, IList <double> timeList, IList <double> strikeList, IList <double> volList, IList <ResolvedIborCapFloorLeg> capList, IList <double> priceList, IList <double> errorList)
        {
            int nStrikes = strikes.size();

            for (int i = 0; i < nStrikes; ++i)
            {
                if (Double.isFinite(volatilityData.get(i)))
                {
                    ResolvedIborCapFloorLeg capFloor = definition.createCap(startDate, endDate, strikes.get(i)).resolve(referenceData);
                    capList.Add(capFloor);
                    strikeList.Add(strikes.get(i));
                    volList.Add(volatilityData.get(i));
                    ConstantSurface constVolSurface     = ConstantSurface.of(metadata, volatilityData.get(i));
                    IborCapletFloorletVolatilities vols = volatilityFunction(constVolSurface);
                    timeList.Add(vols.relativeTime(capFloor.FinalFixingDateTime));
                    priceList.Add(pricer.presentValue(capFloor, ratesProvider, vols).Amount);
                    errorList.Add(errors.get(i));
                }
            }
        }
示例#29
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the current cash of the swap leg.
 /// </summary>
 /// <param name="leg">  the leg </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the current cash of the swap leg </returns>
 public virtual CurrencyAmount currentCash(ResolvedSwapLeg leg, RatesProvider provider)
 {
     return(CurrencyAmount.of(leg.Currency, currentCashPeriodsInternal(leg, provider) + (currentCashEventsInternal(leg, provider))));
 }
示例#30
0
 // cash flows for one scenario
 internal CashFlows cashFlows(ResolvedSwapTrade trade, RatesProvider ratesProvider)
 {
     return(tradePricer.cashFlows(trade, ratesProvider));
 }