Exemplo n.º 1
0
        public static CapFloor GeneratedFpMLCapFloor(
            ILogger logger, ICoreCache cache,
            CapFloorLegParametersRange capFloorParametersRange,
            List <InputCashflowRangeItem> capFloorDetailedCashflowsList,
            List <InputPrincipalExchangeCashflowRangeItem> capFloorPrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> capFloorAdditionalPaymentList,
            List <FeePaymentRangeItem> feePaymentList
            )
        {
            //Check if the calendars are null. If not build them!
            InterestRateStream stream1 = GetCashflowsSchedule(null, null, capFloorParametersRange);//parametric definiton + cashflows schedule

            // Update FpML cashflows
            //
            stream1.cashflows = UpdateCashflowsWithDetailedCashflows(capFloorDetailedCashflowsList);
            if (null != capFloorPrincipalExchangeCashflowListArray)
            {
                // create principal exchanges
                //
                InterestRateSwapPricer.CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, capFloorPrincipalExchangeCashflowListArray);
            }
            //  Add bullet payments...
            //
            var bulletPaymentList = new List <Payment>();

            if (null != capFloorAdditionalPaymentList)
            {
                bulletPaymentList.AddRange(capFloorAdditionalPaymentList.Select(bulletPaymentRangeItem =>
                                                                                new Payment {
                    payerPartyReference = PartyReferenceFactory.Create(capFloorParametersRange.Payer), receiverPartyReference =
                        PartyReferenceFactory.Create(capFloorParametersRange.Receiver),
                    paymentAmount = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount, bulletPaymentRangeItem.Currency),
                    paymentDate   = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }));
            }
            CapFloor capFloor = CapFloorFactory.Create(stream1);

            capFloor.additionalPayment = bulletPaymentList.ToArray();
            var feeList = new List <Payment>();

            if (null != feePaymentList)
            {
                feeList.AddRange(feePaymentList.Select(feePaymentRangeItem =>
                                                       new Payment
                {
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(feePaymentRangeItem.PaymentDate),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(feePaymentRangeItem.Amount, feePaymentRangeItem.Currency),    //TODO The currency needs to be added!
                    payerPartyReference    = PartyReferenceFactory.Create(feePaymentRangeItem.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver)
                }));
            }
            capFloor.premium = feeList.ToArray();
            return(capFloor);
        }
Exemplo n.º 2
0
        public double Value(double parRate)
        {
            var pricer = new InterestRateSwapPricer();

            //  We can safely assign FIXED rate it to both (fixed and floating sides) legs as a floating side ignores this value
            //
            _payLegParametersRange.CouponOrLastResetRate = _receiveLegParametersRange.CouponOrLastResetRate = (decimal)parRate;
            //            ValuationResultRange valuationResult = pricer.GetPrice(_payLegParametersRange, _receiveLegParametersRange, _valuationRange);
            //
            //            return (double)valuationResult.PresentValue;

            throw new NotImplementedException();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="swaptionFpML"> </param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        public InterestRateSwaptionPricer(ILogger logger, ICoreCache cache, String nameSpace,
                                          Swaption swaptionFpML, string basePartyReference, Boolean forecastRateInterpolation)
            : base(logger, cache, nameSpace, swaptionFpML, basePartyReference, forecastRateInterpolation)
        {
            ProductType = ProductTypeSimpleEnum.InterestRateSwaption;
            var underlyingSwap = new InterestRateSwapPricer(logger, cache, nameSpace, null, swaptionFpML.swap, basePartyReference, forecastRateInterpolation);

            Swap = underlyingSwap;
            //Add the currencies for the trade pricer.
            foreach (var ccy in Swap.PaymentCurrencies)
            {
                if (!PaymentCurrencies.Contains(ccy))
                {
                    PaymentCurrencies.Add(ccy);
                }
            }
            if (underlyingSwap.SwapType == SwapType.FixedFloat && underlyingSwap.ProductType == ProductTypeSimpleEnum.InterestRateSwap)
            {
                if (Swap.BasePartyPayingFixed && underlyingSwap.PayLeg.Strike != null)
                {
                    StrikeRate = (decimal)underlyingSwap.PayLeg.Strike;
                    if (!IsBasePartyBuyer)
                    {
                        IsCall = true;
                    }
                }
                if (!Swap.BasePartyPayingFixed && underlyingSwap.ReceiveLeg.Strike != null)//
                {
                    StrikeRate = (decimal)underlyingSwap.ReceiveLeg.Strike;
                    if (IsBasePartyBuyer)
                    {
                        IsCall = true;
                    }
                }
                VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(swaptionFpML.swap);
            }
            BucketedDates    = new DateTime[] { };
            RiskMaturityDate = Swap.RiskMaturityDate;
        }
 public static object[,] DoXLReport(InterestRateSwapPricer interestRateSwap, bool receiveLeg)
 {
     if (interestRateSwap != null)
     {
         var result = new object[interestRateSwap.ReceiveLeg.Coupons.Count, 6];
         if (receiveLeg)
         {
             var index = 0;
             foreach (var receiveRateCoupon in interestRateSwap.ReceiveLeg.Coupons)
             {
                 result[index, 0] = "ReceiveLeg_Coupon_" + index;
                 result[index, 1] = receiveRateCoupon.PriceableCouponType.ToString();
                 result[index, 2] = receiveRateCoupon.PaymentDate;
                 result[index, 3] = receiveRateCoupon.NotionalAmount.amount;
                 result[index, 4] = receiveRateCoupon.Rate;
                 result[index, 5] = receiveRateCoupon.PaymentAmount.amount;
                 index++;
             }
         }
         else
         {
             var index       = 0;
             var secondIndex = 0;
             foreach (var payRateCoupon in interestRateSwap.PayLeg.Coupons)
             {
                 result[index, 0] = "PayLeg_Coupon_" + secondIndex;
                 result[index, 1] = payRateCoupon.PriceableCouponType.ToString();
                 result[index, 2] = payRateCoupon.PaymentDate;
                 result[index, 3] = payRateCoupon.NotionalAmount.amount;
                 result[index, 4] = payRateCoupon.Rate;
                 result[index, 5] = payRateCoupon.PaymentAmount.amount;
                 index++;
                 secondIndex++;
             }
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        public double Value(double spread)
        {
            var pricer = new InterestRateSwapPricer();

            //  We can safely assign SPREAD to both (fixed and floating sides) legs as a FIXED side ignores this value
            //
            _payLegParametersRange.FloatingRateSpread = _receiveLegParametersRange.FloatingRateSpread = (decimal)spread;

//                    public ValuationResultRange GetPrice(
//                                    ValuationRange valuationRange,
//                                    TradeRange tradeRange,
//                                    SwapLegParametersRange leg1ParametersRange,
//                                    SwapLegParametersRange leg2ParametersRange,
//                                    List<DetailedCashflowRangeItem> leg1DetailedCashflowsListArray,
//                                    List<DetailedCashflowRangeItem> leg2DetailedCashflowsListArray,
//                                    List<PrincipleExchangeCashflowRangeItem> leg1PrincipleExchangeCashflowListArray,
//                                    List<PrincipleExchangeCashflowRangeItem> leg2PrincipleExchangeCashflowListArray,
//                                    List<AdditionalPaymentRangeItem> leg1AdditionalPaymentListArray,
//                                    List<AdditionalPaymentRangeItem> leg2AdditionalPaymentListArray)

            throw new NotImplementedException();

//            ValuationResultRange valuationResult = pricer.GetPrice(_valuationRange, null,
//                                                                    _payLegParametersRange, _receiveLegParametersRange,
//                                                                    new List<DetailedCashflowRangeItem>(),
//                                                                    new List<DetailedCashflowRangeItem>(),
//                                                                    new List<PrincipleExchangeCashflowRangeItem>(),
//                                                                    new List<PrincipleExchangeCashflowRangeItem>(),
//                                                                    new List<AdditionalPaymentRangeItem>(),
//                                                                    new List<AdditionalPaymentRangeItem>()
//                                                                    );
//
//
//
//            return (double)valuationResult.PresentValue;
        }
Exemplo n.º 6
0
        /// <summary>
        /// <remarks>
        /// Always:
        /// pay floating
        /// receive fixed
        /// </remarks>
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="valueDate"></param>
        /// <param name="effectiveDate"></param>
        /// <param name="terminationDate"></param>
        /// <param name="interpolationMethod"></param>
        /// <param name="margineAboveFloatingRate"></param>
        /// <param name="resetRate"></param>
        /// <param name="directionDateGenerationPayLeg"></param>
        /// <param name="cashFlowFrequencyPayLeg"></param>
        /// <param name="accrualMethodPayLeg"></param>
        /// <param name="holidaysPayLeg"></param>
        /// <param name="discountFactorCurvePayLeg"></param>
        /// <param name="directionDateGenerationRecLeg"></param>
        /// <param name="cashFlowFrequencyRecLeg"></param>
        /// <param name="accrualMethodRecLeg"></param>
        /// <param name="holidaysRecLeg"></param>
        /// <param name="discountFactorCurveRecLeg"></param>
        /// <returns></returns>
        public double GetSwapParRateWithoutCurves
        (
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            DateTime valueDate,
            DateTime effectiveDate,
            DateTime terminationDate,
            string interpolationMethod,      //1 is linear on forward rates => make sure that the right curve is provided ...
            double margineAboveFloatingRate, // use 0 initially
            double resetRate,
            int directionDateGenerationPayLeg,
            string cashFlowFrequencyPayLeg,
            string accrualMethodPayLeg,
            string holidaysPayLeg,
            IRateCurve discountFactorCurvePayLeg,
            int directionDateGenerationRecLeg,
            string cashFlowFrequencyRecLeg,
            string accrualMethodRecLeg,
            string holidaysRecLeg,
            IRateCurve discountFactorCurveRecLeg
        )
        {
            const decimal dummyNotional = 1000000.0m;
            //  received fixed leg
            //
            var recFixedCashflows = InterestRateSwapPricer.GenerateCashflows(logger, cache, nameSpace, null, valueDate, effectiveDate, terminationDate,
                                                                             interpolationMethod, margineAboveFloatingRate, resetRate,
                                                                             dummyNotional,
                                                                             directionDateGenerationRecLeg,
                                                                             cashFlowFrequencyRecLeg,
                                                                             accrualMethodRecLeg,
                                                                             holidaysRecLeg,
                                                                             discountFactorCurveRecLeg,
                                                                             true);

            recFixedCashflows.PayingFixedRate = false;
            //  pay floating leg
            //
            var payFloatingCashflows = InterestRateSwapPricer.GenerateCashflows(logger, cache, nameSpace, null, valueDate, effectiveDate, terminationDate,
                                                                                interpolationMethod, margineAboveFloatingRate, resetRate,
                                                                                dummyNotional,
                                                                                directionDateGenerationPayLeg,
                                                                                cashFlowFrequencyPayLeg,
                                                                                accrualMethodPayLeg,
                                                                                holidaysPayLeg,
                                                                                discountFactorCurvePayLeg,
                                                                                false);

            payFloatingCashflows.PayingFixedRate = false;
            var objectiveFunction = new InterestRateSwapPricer
            {
                ReceiveLeg = recFixedCashflows,
                PayLeg     = payFloatingCashflows
            };
            var solver = new Brent
            {
                LowerBound = -100.0,
                UpperBound = 100.0
            };

            return(solver.Solve(objectiveFunction, Accuracy, Guess, Step));
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="valueDate"></param>
        /// <param name="effectiveDate"></param>
        /// <param name="terminationDate"></param>
        /// <param name="interpolationMethod"></param>
        /// <param name="margineAboveFloatingRate"></param>
        /// <param name="resetRate"></param>
        /// <param name="notional"></param>
        /// <param name="directionDateGenerationPayLeg"></param>
        /// <param name="cashFlowFrequencyPayLeg"></param>
        /// <param name="accrualMethodPayLeg"></param>
        /// <param name="holidaysPayLeg"></param>
        /// <param name="rateCurvePayLeg"></param>
        /// <param name="directionDateGenerationRecLeg"></param>
        /// <param name="cashFlowFrequencyRecLeg"></param>
        /// <param name="accrualMethodRecLeg"></param>
        /// <param name="holidaysRecLeg"></param>
        /// <param name="rateCurveRecLeg"></param>
        /// <param name="layout">
        /// if 0 - cashflows displayed one under another,
        /// if 1 - cashflows displayed side by side.
        /// </param>
        /// <returns>
        ///  Pay cashflows:
        ///
        ///
        ///
        ///  Rec cashflows:
        ///
        ///
        /// </returns>
        public object[,] GetSwapCashflowsWithoutCurves
        (
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            DateTime valueDate,
            DateTime effectiveDate,
            DateTime terminationDate,
            string interpolationMethod,      //1 is linear on forward rates => make sure that the right curve is provided ...
            double margineAboveFloatingRate, // use 0 initially
            double resetRate,
            decimal notional,
            int directionDateGenerationPayLeg,
            string cashFlowFrequencyPayLeg,
            string accrualMethodPayLeg,
            string holidaysPayLeg,
            IRateCurve rateCurvePayLeg,
            int directionDateGenerationRecLeg,
            string cashFlowFrequencyRecLeg,
            string accrualMethodRecLeg,
            string holidaysRecLeg,
            IRateCurve rateCurveRecLeg,
            int layout
        )
        {
            //  received fixed leg
            //
            var recFixedCashflows = InterestRateSwapPricer.GenerateCashflows(logger, cache, nameSpace, null, valueDate, effectiveDate, terminationDate,
                                                                             interpolationMethod, margineAboveFloatingRate, resetRate,
                                                                             notional,
                                                                             directionDateGenerationRecLeg,
                                                                             cashFlowFrequencyRecLeg,
                                                                             accrualMethodRecLeg,
                                                                             holidaysRecLeg,
                                                                             rateCurvePayLeg,
                                                                             true);
            //  pay floating leg
            //
            var payFloatingCashflows = InterestRateSwapPricer.GenerateCashflows(logger, cache, nameSpace, null, valueDate, effectiveDate, terminationDate,
                                                                                interpolationMethod, margineAboveFloatingRate, resetRate,
                                                                                notional,
                                                                                directionDateGenerationPayLeg,
                                                                                cashFlowFrequencyPayLeg,
                                                                                accrualMethodPayLeg,
                                                                                holidaysPayLeg,
                                                                                rateCurveRecLeg,
                                                                                false);
            var objectiveFunction = new InterestRateSwapPricer
            {
                ReceiveLeg = recFixedCashflows,
                PayLeg     = payFloatingCashflows
            };
            var solver = new Brent
            {
                LowerBound = -100.0,
                UpperBound = 100.0
            };

            solver.Solve(objectiveFunction, Accuracy, Guess, Step);
            //            bool bothLegsHaveTheSameStructure =
            //                directionDateGenerationPayLeg == directionDateGenerationRecLeg &&
            //                cashFlowFrequencyPayLeg == cashFlowFrequencyRecLeg &&
            //                holidaysPayLeg == holidaysRecLeg;

            // if 0 - cashflows displayed one under another,
            // if 1 - cashflows displayed side by side.

            var result = 1 == layout?Utilities.GetCashflowsSideBySideExcelRange(payFloatingCashflows.Coupons, recFixedCashflows.Coupons) : Utilities.GetCashflowsOneUnderAnotherExcelRange(payFloatingCashflows.Coupons, recFixedCashflows.Coupons);

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="legCalendars"></param>
        /// <param name="trade"></param>
        /// <param name="tradeProps"></param>
        /// <param name="forecastRateInterpolation"></param>
        public TradePricer(ILogger logger, ICoreCache cache, String nameSpace,
                           List <Pair <IBusinessCalendar, IBusinessCalendar> > legCalendars,
                           Trade trade, NamedValueSet tradeProps, bool forecastRateInterpolation)
        {
            if (tradeProps == null)
            {
                tradeProps = new NamedValueSet();//TODO Need to generate properties for the FpML examples.
            }
            var tradeIdentifier = new TradeIdentifier(tradeProps);

            TradeIdentifier = tradeIdentifier;
            TradeHeader     = trade.tradeHeader;
            //Get the baseParty, which in GWML is the originating party.
            BaseParty = tradeProps.GetValue <string>(TradeProp.BaseParty, false) ?? TradeProp.Party1;
            var party1 = tradeProps.GetValue <string>(TradeProp.Party1, true);
            var party2 = tradeProps.GetValue <string>(TradeProp.Party2, true);

            Parties = new List <Party> {
                new Party {
                    partyName = new PartyName {
                        Value = party1
                    }
                }, new Party {
                    partyName = new PartyName {
                        Value = party2
                    }
                }
            };
            TradeType = trade.ItemElementName;
            //Determine the product type, so that the appropriate productPricer can be instantiated.
            //Set the product type
            var productType = tradeIdentifier.ProductType;
            //Check whether the business calendars list is null.
            Pair <IBusinessCalendar, IBusinessCalendar> firstCalendarPair = null;

            if (legCalendars?.Count > 0)
            {
                firstCalendarPair = legCalendars[0];
            }
            //Instantiate the productPricer.
            if (productType != null && productType != ProductTypeSimpleEnum.Undefined)
            {
                ProductType = (ProductTypeSimpleEnum)productType;
                switch (ProductType)
                {
                case ProductTypeSimpleEnum.PropertyTransaction:
                {
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var property          = (PropertyTransaction)trade.Item;
                    var tradeDate         = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false);
                    var referenceProperty = tradeProps.GetValue <String>(PropertyProp.ReferenceProperty, false);
                    //Get the instrument configuration data.
                    //Modify the pricer to include this data.
                    PriceableProduct = new PropertyTransactionPricer(logger, cache, nameSpace, tradeDate, referenceProperty, settlementCalendar, property, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new PropertyTransactionReporter();
                }
                break;

                case ProductTypeSimpleEnum.EquityTransaction:
                {
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var equity          = (EquityTransaction)trade.Item;
                    var tradeDate       = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true);
                    var effectiveDate   = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true);
                    var referenceEquity = tradeProps.GetValue <String>(EquityProp.ReferenceEquity, false);
                    //Get the instrument configuration data.
                    //Modify the pricer to include this data.
                    PriceableProduct = new EquityTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, referenceEquity, settlementCalendar, equity, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new EquityTransactionReporter();
                }
                break;

                case ProductTypeSimpleEnum.BondTransaction:
                {
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var bond          = (BondTransaction)trade.Item;
                    var tradeDate     = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true);
                    var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true);
                    var bondType      = tradeProps.GetValue <string>(BondProp.BondType, false);
                    //Get the instrument configuration data.
                    //Modify the pricer to include this data.
                    PriceableProduct = new BondTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, settlementCalendar, settlementCalendar, bond, BaseParty, bondType, forecastRateInterpolation);
                    ProductReporter  = new BondTransactionReporter();
                }
                break;

                case ProductTypeSimpleEnum.FutureTransaction:
                {
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var future     = (FutureTransaction)trade.Item;
                    var tradeDate  = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false);
                    var type       = tradeProps.GetValue <String>(FuturesProp.FuturesType, true);
                    var futureType = EnumHelper.Parse <ExchangeContractTypeEnum>(type);
                    //Get the instrument configuration data.
                    //Modify the pricer to include this data.
                    PriceableProduct = new FutureTransactionPricer(logger, cache, nameSpace, tradeDate, futureType, settlementCalendar, future, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new FutureTransactionReporter();
                }
                break;

                case ProductTypeSimpleEnum.InterestRateSwap:
                {
                    var swap = (Swap)trade.Item;
                    PriceableProduct = new InterestRateSwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwapReporter();
                }
                break;

                case ProductTypeSimpleEnum.AssetSwap:
                {
                    var swap = (Swap)trade.Item;
                    //TODO set for the payer. This needs to be modified for the base counterparty.
                    PriceableProduct = new AssetSwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, new Bond(), forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwapReporter();
                }
                break;

                case ProductTypeSimpleEnum.CrossCurrencySwap:
                {
                    var swap = (Swap)trade.Item;
                    //TODO set for the payer. This needs to be modified for the base counterparty.
                    PriceableProduct = new CrossCurrencySwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwapReporter();
                }
                break;

                case ProductTypeSimpleEnum.FRA:     // todo
                {
                    var fra = (Fra)trade.Item;
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    PriceableProduct = new FraPricer(logger, cache, fixingCalendar, paymentCalendar, fra, BaseParty, nameSpace)
                    {
                        ForecastRateInterpolation = forecastRateInterpolation
                    };
                    ProductReporter = new ForwardRateAgreementReporter();
                }
                break;

                //case ProductTypeSimpleEnum.InflationSwap:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultSwap:
                //    break;
                //case ProductTypeSimpleEnum.TotalReturnSwap:
                //    break;
                //case ProductTypeSimpleEnum.VarianceSwap:
                //    break;
                case ProductTypeSimpleEnum.CapFloor:
                {
                    var capFloor = (CapFloor)trade.Item;
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    PriceableProduct = new CapFloorPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloor, BaseParty);
                    ProductReporter  = new CapFloorReporter();
                }
                break;

                case ProductTypeSimpleEnum.FxSpot:
                {
                    var fxForward = (FxSingleLeg)trade.Item;
                    PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductTypeSimpleEnum.FxSpot);
                    ProductReporter  = new FxSingleLegReporter();
                }
                break;

                case ProductTypeSimpleEnum.FxForward:
                {
                    var fxForward = (FxSingleLeg)trade.Item;
                    PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductTypeSimpleEnum.FxForward);
                    ProductReporter  = new FxSingleLegReporter();
                }
                break;

                case ProductTypeSimpleEnum.BulletPayment:
                {
                    if (trade.Item is BulletPayment bullet)
                    {
                        IBusinessCalendar paymentCalendar = null;
                        if (firstCalendarPair != null)
                        {
                            paymentCalendar = firstCalendarPair.Second;
                        }
                        //The calendars
                        if (paymentCalendar == null)
                        {
                            if (bullet.payment.paymentDate != null)
                            {
                                var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(bullet.payment.paymentDate, ItemsChoiceType.dateAdjustments, out object dateAdjustments);
                                if (containsPaymentDateAdjustments && dateAdjustments != null)
                                {
                                    paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments).
                                                                                              businessCenters, nameSpace);
                                }
                            }
                        }
                        PriceableProduct = new BulletPaymentPricer(bullet, BaseParty, paymentCalendar);
                        ProductReporter  = new BulletPaymentReporter();
                    }
                }
                break;

                case ProductTypeSimpleEnum.FxSwap:
                {
                    var fxSwap = (FxSwap)trade.Item;
                    PriceableProduct = new FxSwapPricer(fxSwap, BaseParty);
                    ProductReporter  = new FxSwapReporter();
                }
                break;

                //case ProductTypeSimpleEnum.EquityOption:
                //    break;
                //case ProductTypeSimpleEnum.BondOption:
                //    break;
                case ProductTypeSimpleEnum.FxOption:
                {
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    var fxOption = (FxOption)trade.Item;
                    PriceableProduct = new VanillaEuropeanFxOptionPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, fxOption, BaseParty);
                    ProductReporter  = new FxOptionLegReporter();
                }
                break;

                //case ProductTypeSimpleEnum.FxOptionStrategy:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultIndex:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultIndexTranche:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultBasket:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultBasketTranche:
                //    break;
                //case ProductTypeSimpleEnum.CreditDefaultOption:
                //    break;
                //case ProductTypeSimpleEnum.EquityForward:
                //    break;
                case ProductTypeSimpleEnum.InterestRateSwaption:
                {
                    var interestRateSwaption = (Swaption)trade.Item;
                    PriceableProduct = new InterestRateSwaptionPricer(logger, cache, nameSpace, interestRateSwaption, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwaptionReporter();
                }
                break;

                case ProductTypeSimpleEnum.TermDeposit:
                {
                    //var party1 = tradeProps.GetValue<string>(TradeProp.Party1, true);
                    //var party2 = tradeProps.GetValue<string>(TradeProp.Party2, true);
                    //var reportingParty = baseParty == party1 ? "Party1" : "Party2"; // TODO this is for backward compatability.
                    var deposit = (TermDeposit)trade.Item;
                    PriceableProduct = new TermDepositPricer(logger, cache, deposit, TradeProp.Party1);        //The payment date must be correct before calling this!
                    ProductReporter  = new TermDepositReporter();
                }
                break;

                //case ProductTypeSimpleEnum.DividendSwap:
                //    break;
                //case ProductTypeSimpleEnum.ConvertibleBondOption:
                //    break;
                //case ProductTypeSimpleEnum.Loan:
                //    break;
                //case ProductTypeSimpleEnum.Repo:
                //    break;
                default:
                    throw new NotSupportedException("Unsupported ProductType: " + ProductType);
                }
            }
            else
            {
                switch (TradeType)
                {
                case ItemChoiceType15.propertyTransaction:
                {
                    var equity = (PropertyTransaction)trade.Item;
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var tradeDate         = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false);
                    var referenceProperty = tradeProps.GetValue <String>(PropertyProp.ReferenceProperty, false);
                    PriceableProduct = new PropertyTransactionPricer(logger, cache, nameSpace, tradeDate, referenceProperty, settlementCalendar, equity, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new PropertyTransactionReporter();
                }
                break;

                case ItemChoiceType15.equityTransaction:
                {
                    var equity = (EquityTransaction)trade.Item;
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var tradeDate       = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false);
                    var effectiveDate   = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true);
                    var referenceEquity = tradeProps.GetValue <String>(EquityProp.ReferenceEquity, false);
                    PriceableProduct = new EquityTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, referenceEquity, settlementCalendar, equity, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new EquityTransactionReporter();
                }
                break;

                case ItemChoiceType15.bondTransaction:
                {
                    var bond = (BondTransaction)trade.Item;
                    IBusinessCalendar settlementCalendar = null;
                    IBusinessCalendar paymentCalendar    = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                        paymentCalendar    = firstCalendarPair.Second;
                    }
                    var tradeDate     = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, true);
                    var effectiveDate = tradeProps.GetValue <DateTime>(TradeProp.EffectiveDate, true);
                    var bondType      = tradeProps.GetValue <string>(BondProp.BondType, false);
                    PriceableProduct = new BondTransactionPricer(logger, cache, nameSpace, tradeDate, effectiveDate, settlementCalendar, paymentCalendar, bond, BaseParty, bondType, forecastRateInterpolation);
                    ProductReporter  = new BondTransactionReporter();
                }
                break;

                case ItemChoiceType15.futureTransaction:
                {
                    IBusinessCalendar settlementCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        settlementCalendar = firstCalendarPair.First;
                    }
                    var future     = (FutureTransaction)trade.Item;
                    var tradeDate  = tradeProps.GetValue <DateTime>(TradeProp.TradeDate, false);
                    var type       = tradeProps.GetValue <String>(FuturesProp.FuturesType, true);
                    var futureType = EnumHelper.Parse <ExchangeContractTypeEnum>(type);
                    //Get the instrument configuration data.
                    //Modify the pricer to include this data.
                    PriceableProduct = new FutureTransactionPricer(logger, cache, nameSpace, tradeDate, futureType, settlementCalendar, future, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new FutureTransactionReporter();
                }
                break;

                case ItemChoiceType15.swap:
                {
                    var swap = (Swap)trade.Item;
                    //TODO this needs to be emnhanced
                    ProductType      = ProductTypeSimpleEnum.InterestRateSwap;
                    PriceableProduct = new CrossCurrencySwapPricer(logger, cache, nameSpace, legCalendars, swap, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwapReporter();
                    //var report =
                }
                break;

                case ItemChoiceType15.fra:     // todo
                {
                    var fra = (Fra)trade.Item;
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    ProductType      = ProductTypeSimpleEnum.FRA;
                    PriceableProduct = new FraPricer(logger, cache, fixingCalendar, paymentCalendar, fra, BaseParty)
                    {
                        ForecastRateInterpolation = forecastRateInterpolation
                    };
                    ProductReporter = new ForwardRateAgreementReporter();
                }
                break;

                case ItemChoiceType15.capFloor:
                {
                    var capFloor = (CapFloor)trade.Item;
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    ProductType      = ProductTypeSimpleEnum.CapFloor;
                    PriceableProduct = new CapFloorPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloor, BaseParty);
                    ProductReporter  = new CapFloorReporter();
                }
                break;

                case ItemChoiceType15.fxSingleLeg:
                {
                    var fxForward = (FxSingleLeg)trade.Item;
                    ProductType      = ProductTypeSimpleEnum.FxSpot;
                    PriceableProduct = new FxSingleLegPricer(fxForward, BaseParty, ProductType);
                    ProductReporter  = new FxSingleLegReporter();
                }
                break;

                case ItemChoiceType15.fxSwap:
                {
                    var fxSwap = (FxSwap)trade.Item;
                    ProductType      = ProductTypeSimpleEnum.FxSwap;
                    PriceableProduct = new FxSwapPricer(fxSwap, BaseParty);
                    ProductReporter  = new FxSwapReporter();
                }
                break;

                case ItemChoiceType15.bulletPayment:
                {
                    if (trade.Item is BulletPayment bullet)
                    {
                        IBusinessCalendar paymentCalendar = null;
                        if (firstCalendarPair != null)
                        {
                            paymentCalendar = firstCalendarPair.Second;
                        }
                        //The calendars
                        if (paymentCalendar == null)
                        {
                            if (bullet.payment.paymentDate != null)
                            {
                                var containsPaymentDateAdjustments = AdjustableOrAdjustedDateHelper.Contains(bullet.payment.paymentDate, ItemsChoiceType.dateAdjustments, out object dateAdjustments);
                                if (containsPaymentDateAdjustments && dateAdjustments != null)
                                {
                                    paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ((BusinessDayAdjustments)dateAdjustments).
                                                                                              businessCenters, nameSpace);
                                }
                            }
                        }
                        ProductType      = ProductTypeSimpleEnum.BulletPayment;
                        PriceableProduct = new BulletPaymentPricer(bullet, BaseParty, paymentCalendar);
                        ProductReporter  = new BulletPaymentReporter();
                    }
                }
                break;

                case ItemChoiceType15.termDeposit:
                {
                    var deposit = (TermDeposit)trade.Item;
                    ProductType      = ProductTypeSimpleEnum.TermDeposit;
                    PriceableProduct = new TermDepositPricer(logger, cache, deposit, TradeProp.Party1);        //The payment date must be correct before calling this!
                    ProductReporter  = new TermDepositReporter();
                }
                break;

                case ItemChoiceType15.swaption:
                {
                    var interestRateSwaption = (Swaption)trade.Item;
                    ProductType      = ProductTypeSimpleEnum.InterestRateSwaption;
                    PriceableProduct = new InterestRateSwaptionPricer(logger, cache, nameSpace, interestRateSwaption, BaseParty, forecastRateInterpolation);
                    ProductReporter  = new InterestRateSwaptionReporter();
                }
                break;

                case ItemChoiceType15.fxOption:
                {
                    IBusinessCalendar fixingCalendar  = null;
                    IBusinessCalendar paymentCalendar = null;
                    if (firstCalendarPair != null)
                    {
                        fixingCalendar  = firstCalendarPair.First;
                        paymentCalendar = firstCalendarPair.Second;
                    }
                    var fxOption = (FxOption)trade.Item;
                    ProductType      = ProductTypeSimpleEnum.FxOption;
                    PriceableProduct = new VanillaEuropeanFxOptionPricer(logger, cache, nameSpace, fixingCalendar, paymentCalendar, fxOption, BaseParty);
                    ProductReporter  = new FxOptionLegReporter();
                }
                break;

                default:
                    throw new NotSupportedException("Unsupported TradeType: " + TradeType);
                }
                //Adds the extra party info now required.
                PriceableProduct.OrderedPartyNames.Add(party1);
                PriceableProduct.OrderedPartyNames.Add(party2);
                //Check if collateralised
                if (trade.collateral != null)
                {
                    PriceableProduct.IsCollateralised = true;
                }
            }
        }
Exemplo n.º 9
0
        internal static Pair <ValuationResultRange, Swap> GetPriceAndGeneratedFpMLSwap(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange leg1ParametersRange,
            SwapLegParametersRange leg2ParametersRange,
            List <InputCashflowRangeItem> leg1DetailedCashflowsList,
            List <InputCashflowRangeItem> leg2DetailedCashflowsList,
            List <InputPrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowList,
            List <InputPrincipalExchangeCashflowRangeItem> leg2PrincipalExchangeCashflowList,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList,
            List <AdditionalPaymentRangeItem> leg2AdditionalPaymentList
            )
        {
            //Check if the calendars are null. If not build them!
            //
            //
            //
            //
            //
            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange); //parametric definiton + cashflows schedule
            InterestRateStream stream2 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg2ParametersRange); //parametric definiton + cashflows schedule
            var swap = SwapFactory.Create(stream1, stream2);

            // Update FpML cashflows
            //
            InterestRateSwapPricer.UpdateCashflowsWithDetailedCashflows(stream1.cashflows, leg1DetailedCashflowsList);
            InterestRateSwapPricer.UpdateCashflowsWithDetailedCashflows(stream2.cashflows, leg2DetailedCashflowsList);
            //  Update PE
            //
            CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, leg1PrincipalExchangeCashflowList);
            CreatePrincipalExchangesFromListOfRanges(stream2.cashflows, leg2PrincipalExchangeCashflowList);
            //  Add bullet payments...
            //
            var bulletPaymentList = new List <Payment>();

            if (null != leg1AdditionalPaymentList)
            {
                bulletPaymentList.AddRange(leg1AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment
                {
                    payerPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Payer), receiverPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Receiver), paymentAmount = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount), paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }));
            }
            if (null != leg2AdditionalPaymentList)
            {
                bulletPaymentList.AddRange(leg2AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment
                {
                    payerPartyReference = PartyReferenceFactory.Create(leg2ParametersRange.Payer), receiverPartyReference = PartyReferenceFactory.Create(leg2ParametersRange.Receiver), paymentAmount = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount), paymentDate = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }));
            }
            swap.additionalPayment = bulletPaymentList.ToArray();
            // Update FpML cashflows with DF,FV,PV, etc (LegParametersRange needed to access curve functionality)
            //
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange);
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream2, leg2ParametersRange, valuationRange);
            //  Update additional payments
            //
            var leg1DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg1ParametersRange.DiscountCurve);
            var leg2DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg2ParametersRange.DiscountCurve);

            SwapGenerator.UpdatePaymentsAmounts(logger, cache, nameSpace, swap, leg1ParametersRange, leg2ParametersRange, leg1DiscountCurve, leg2DiscountCurve, valuationRange.ValuationDate, paymentCalendar);
            //~  Update additional payments
            string baseParty = valuationRange.BaseParty;

            return(new Pair <ValuationResultRange, Swap>(CreateValuationRange(swap, baseParty), swap));
        }
        public void CreateSwaptionValuation()
        {
            DateTime valuationDate = DateTime.Today;

            SwaptionPricer irSwaptionPricer = new InterestRateSwaptionPricer();

            string discountCurveID   = BuildAndCacheRateCurve(valuationDate); //RateCurveExcelInterfaceTests.ExcelInterface_CreateAUDCurveFromDepostSwapsFuturesFras_WithDates(valuationDate, valuationDate);
            string projectionCurveID = discountCurveID;

            SwapLegParametersRange_Old payFixed       = CreateFixedAUD_6MSwapLegParametersRange(_NAB, CounterParty, valuationDate, 0.065m, "ACT/365.FIXED", "AUSY", "FOLLOWING", "AUSY", "NONE", discountCurveID);
            SwapLegParametersRange_Old receiveFloat   = CreateFloatingAUD_6MSwapLegParametersRange(CounterParty, _NAB, valuationDate, 0, "ACT/365.FIXED", "AUSY", "FOLLOWING", "AUSY", "NONE", discountCurveID, projectionCurveID);
            ValuationRange             valuationRange = CreateValuationRangeForNAB(valuationDate);
            var payCFRangeItemList = InterestRateSwapPricer.GetDetailedCashflowsTestOnly(Engine.Logger, Engine.Cache, Engine.NameSpace, payFixed, valuationRange);

            payCFRangeItemList[0].CouponType = "fixed"; // that should test case insensitive nature of coupons
            payCFRangeItemList[1].CouponType = "Fixed"; //
            var receiveCFRangeItemList = InterestRateSwapPricer.GetDetailedCashflowsTestOnly(Engine.Logger, Engine.Cache, Engine.NameSpace, receiveFloat, valuationRange);

            receiveCFRangeItemList[0].CouponType = "float"; // that should test case insensitive nature of coupons
            receiveCFRangeItemList[1].CouponType = "Float"; //
            var tradeRange = new TradeRange {
                Id = "TradeId_12345", TradeDate = valuationDate
            };
            var leg1PrincipalExchangeCashflowList = new List <InputPrincipalExchangeCashflowRangeItem>();
            var leg2PrincipalExchangeCashflowList = new List <InputPrincipalExchangeCashflowRangeItem>();
            var leg1BulletPaymentList             = new List <AdditionalPaymentRangeItem>();
            var leg2BulletPaymentList             = new List <AdditionalPaymentRangeItem>();
            var swaptionParametersRange           = new SwaptionParametersRange
            {
                Premium                = 456789.12m,
                PremiumCurrency        = "AUD",
                PremiumPayer           = CounterParty,
                PremiumReceiver        = _NAB,
                ExpirationDate         = valuationDate.AddDays(10),
                ExpirationDateCalendar = "AUSY-GBLO",
                ExpirationDateBusinessDayAdjustments = "FOLLOWING",
                PaymentDate         = valuationDate.AddDays(20),
                PaymentDateCalendar = "USNY-GBLO",
                PaymentDateBusinessDayAdjustments = "MODFOLLOWING",
                EarliestExerciseTime = new TimeSpan(10, 0, 0).TotalDays,
                ExpirationTime       = new TimeSpan(11, 0, 0).TotalDays,
                AutomaticExcercise   = false
            };
            List <PartyIdRangeItem>           partyList = GetPartyList("NAB", "book", "MCHammer", "counterparty");
            List <OtherPartyPaymentRangeItem> otherPartyPaymentRangeItems = GetOtherPartyPaymentList("counterparty", "cost center");
            List <FeePaymentRangeItem>        feePaymentRangeItems        = GetFeeList("counterparty", "book");
            //  Get price and swap representation using non-vanilla PRICE function.
            //
            string valuatonId = irSwaptionPricer.CreateValuation(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null,
                                                                 swaptionParametersRange,
                                                                 CreateValuationSetList2(12345.67, -0.321), valuationRange, tradeRange,
                                                                 payFixed, receiveFloat,
                                                                 payCFRangeItemList, receiveCFRangeItemList,
                                                                 leg1PrincipalExchangeCashflowList, leg2PrincipalExchangeCashflowList,
                                                                 leg1BulletPaymentList, leg2BulletPaymentList,
                                                                 partyList, otherPartyPaymentRangeItems,
                                                                 feePaymentRangeItems);
            var valuationReport = Engine.Cache.LoadObject <ValuationReport>(Engine.NameSpace + "." + valuatonId);

            Debug.Print(XmlSerializerHelper.SerializeToString(valuationReport));
        }
Exemplo n.º 11
0
        public static Pair <ValuationResultRange, CapFloor> GetPriceAndGeneratedFpML(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            ValuationRange valuationRange, TradeRange tradeRange,
            CapFloorLegParametersRange_Old leg1ParametersRange,
            List <InputCashflowRangeItem> leg1DetailedCashflowsList,
            List <InputPrincipalExchangeCashflowRangeItem> legPrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList,
            List <FeePaymentRangeItem> feePaymentList
            )
        {
            //Check if the calendars are null. If not build them!
            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange);//parametric definiton + cashflows schedule

            // Update FpML cashflows
            //
            stream1.cashflows = UpdateCashflowsWithDetailedCashflows(leg1DetailedCashflowsList);
            if (null != legPrincipalExchangeCashflowListArray)
            {
                // create principal exchanges
                //
                InterestRateSwapPricer.CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, legPrincipalExchangeCashflowListArray);
            }
            //  Add bullet payments...
            //
            var bulletPaymentList = new List <Payment>();

            if (null != leg1AdditionalPaymentList)
            {
                bulletPaymentList.AddRange(leg1AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment
                {
                    payerPartyReference    = PartyReferenceFactory.Create(leg1ParametersRange.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Receiver),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount, bulletPaymentRangeItem.Currency),
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }));
            }
            CapFloor capFloor = CapFloorFactory.Create(stream1);

            capFloor.additionalPayment = bulletPaymentList.ToArray();
            var feeList = new List <Payment>();

            if (null != feePaymentList)
            {
                feeList.AddRange(feePaymentList.Select(feePaymentRangeItem => new Payment
                {
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(feePaymentRangeItem.PaymentDate),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(feePaymentRangeItem.Amount, feePaymentRangeItem.Currency),
                    payerPartyReference    = PartyReferenceFactory.Create(feePaymentRangeItem.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver)
                }));
            }
            capFloor.premium = feeList.ToArray();
            // Update FpML cashflows with DF,FV,PV, etc (LegParametersRange needed to access curve functionality)
            //
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange);
            //  Update additional payments
            //
            var leg1DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg1ParametersRange.DiscountCurve);

            CapFloorGenerator.UpdatePaymentsAmounts(paymentCalendar, capFloor, leg1ParametersRange, leg1DiscountCurve, valuationRange.ValuationDate);
            //~  Update additional payments
            string baseParty = valuationRange.BaseParty;

            return(new Pair <ValuationResultRange, CapFloor>(CreateValuationRange(capFloor, baseParty), capFloor));
        }