Exemplo n.º 1
0
        private static InterestRateStream GetCashflowsSchedule(IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                                                               CapFloorLegParametersRange legParametersRange)
        {
            InterestRateStream stream    = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange);
            Cashflows          cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar);

            stream.cashflows = cashflows;
            return(stream);
        }
Exemplo n.º 2
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.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="capFloorLeg"></param>
        /// <param name="spreadSchedule"></param>
        /// <param name="capOrFloorSchedule"></param>
        /// <param name="notionalSchedule"></param>
        /// <returns></returns>
        public static CapFloor GenerateDefinitionCashflowsAmounts(ILogger logger,
                                                                  ICoreCache cache, String nameSpace,
                                                                  IBusinessCalendar fixingCalendar,
                                                                  IBusinessCalendar paymentCalendar,
                                                                  CapFloorLegParametersRange capFloorLeg,
                                                                  Schedule spreadSchedule,
                                                                  Schedule capOrFloorSchedule,
                                                                  NonNegativeAmountSchedule notionalSchedule)
        {
            var capFloor = GenerateDefinitionCashflows(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloorLeg, spreadSchedule, capOrFloorSchedule, notionalSchedule);

            return(capFloor);
        }
Exemplo n.º 4
0
        public static CapFloor GenerateDefiniton(CapFloorLegParametersRange capFloorLeg,
                                                 Schedule spreadSchedule,
                                                 Schedule capOrFloorSchedule,
                                                 NonNegativeSchedule notionalSchedule)
        {
            InterestRateStream capFloorStream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(capFloorLeg);

            InterestRateStreamHelper.SetPayerAndReceiver(capFloorStream, capFloorLeg.Payer, capFloorLeg.Receiver);
            var capFloor = new CapFloor {
                capFloorStream = capFloorStream
            };

            return(capFloor);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="capFloorLeg"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="spreadSchedule"></param>
        /// <param name="capOrFloorSchedule"></param>
        /// <param name="notionalSchedule"></param>
        /// <returns></returns>
        public static CapFloor GenerateDefinitionCashflows(ILogger logger, ICoreCache cache,
                                                           string nameSpace,
                                                           IBusinessCalendar fixingCalendar,
                                                           IBusinessCalendar paymentCalendar,
                                                           CapFloorLegParametersRange capFloorLeg,
                                                           Schedule spreadSchedule,
                                                           Schedule capOrFloorSchedule,
                                                           NonNegativeAmountSchedule notionalSchedule)
        {
            if (paymentCalendar == null)
            {
                if (!string.IsNullOrEmpty(capFloorLeg.PaymentCalendar))
                {
                    var payCalendar = BusinessCentersHelper.Parse(capFloorLeg.PaymentCalendar);
                    paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, payCalendar, nameSpace);
                }
            }
            if (fixingCalendar == null)
            {
                if (!string.IsNullOrEmpty(capFloorLeg.FixingCalendar))
                {
                    var fixCalendar = BusinessCentersHelper.Parse(capFloorLeg.FixingCalendar);
                    fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixCalendar, nameSpace);
                }
            }
            CapFloor capFloor = GenerateDefiniton(capFloorLeg, spreadSchedule, capOrFloorSchedule, notionalSchedule);

            if (null != spreadSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetSpreadSchedule(capFloor.capFloorStream, spreadSchedule);
            }
            if (null != notionalSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(capFloor.capFloorStream, notionalSchedule);
            }
            if (null != capOrFloorSchedule)
            {
                if (capFloorLeg.CapOrFloor == CapFloorType.Cap)
                {
                    InterestRateStreamParametricDefinitionGenerator.SetCapRateSchedule(capFloor.capFloorStream, capOrFloorSchedule, true);
                }
                else
                {
                    InterestRateStreamParametricDefinitionGenerator.SetFloorRateSchedule(capFloor.capFloorStream, capOrFloorSchedule, true);
                }
            }
            capFloor.capFloorStream.cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(capFloor.capFloorStream, fixingCalendar, paymentCalendar);
            return(capFloor);
        }
        public static InterestRateStream GenerateStreamDefinition(CapFloorLegParametersRange legParametersRange)
        {
            InterestRateStream stream = GenerateCapFloorStreamDefinition(legParametersRange);

            //  Payer/Receiver references
            //
            stream.payerPartyReference    = PartyReferenceFactory.Create(legParametersRange.Payer);
            stream.receiverPartyReference = PartyReferenceFactory.Create(legParametersRange.Receiver);
            //  Principal exchanges
            //
            stream.principalExchanges = new PrincipalExchanges();
            stream.principalExchanges.initialExchange              =
                stream.principalExchanges.finalExchange            =
                    stream.principalExchanges.intermediateExchange = legParametersRange.GeneratePrincipalExchanges;
            return(stream);
        }
Exemplo n.º 7
0
 public static void UpdatePaymentsAmounts(IBusinessCalendar paymentCalendar,
                                          CapFloor capFloor,
                                          CapFloorLegParametersRange capFloorLeg,
                                          IRateCurve discountCurve,
                                          DateTime valuationDate)
 {
     foreach (Payment payment in capFloor.additionalPayment)
     {
         var date = AdjustedDateHelper.GetAdjustedDate(paymentCalendar, payment.paymentDate);
         if (date != null)
         {
             payment.discountFactor          = (decimal)discountCurve.GetDiscountFactor(valuationDate, (DateTime)date);
             payment.discountFactorSpecified = true;
             payment.presentValueAmount      = MoneyHelper.Mul(payment.paymentAmount, payment.discountFactor);
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="capFloorLeg"></param>
        /// <param name="spreadSchedule"></param>
        /// <param name="capOrFloorSchedule"></param>
        /// <param name="notionalSchedule"></param>
        /// <param name="marketEnvironment"></param>
        /// <param name="valuationDate"></param>
        /// <returns></returns>
        public static CapFloor GenerateDefinitionCashflowsAmounts(ILogger logger,
                                                                  ICoreCache cache, String nameSpace,
                                                                  IBusinessCalendar fixingCalendar,
                                                                  IBusinessCalendar paymentCalendar,
                                                                  CapFloorLegParametersRange capFloorLeg,
                                                                  Schedule spreadSchedule,
                                                                  Schedule capOrFloorSchedule,
                                                                  NonNegativeAmountSchedule notionalSchedule,
                                                                  ISwapLegEnvironment marketEnvironment,
                                                                  DateTime valuationDate)
        {
            CapFloor   capFloor = GenerateDefinitionCashflows(logger, cache, nameSpace, fixingCalendar, paymentCalendar, capFloorLeg, spreadSchedule, capOrFloorSchedule, notionalSchedule);
            IRateCurve payStreamDiscountingCurve = marketEnvironment.GetDiscountRateCurve();
            IRateCurve payStreamForecastCurve    = marketEnvironment.GetForecastRateCurve();

            FixedAndFloatingRateStreamCashflowGenerator.UpdateCashflowsAmounts(capFloor.capFloorStream, payStreamForecastCurve, payStreamDiscountingCurve, valuationDate);
            return(capFloor);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="leg1Parameters"></param>
        /// <param name="leg1PaymentCalendar"> </param>
        /// <param name="capStrikeSchedule"></param>
        /// <param name="floorStrikeSchedule"> </param>
        /// <param name="spreadSchedule"></param>
        /// <param name="notionalSchedule"></param>
        /// <param name="leg1FixingCalendar"> </param>
        /// <returns></returns>
        public static Trade CreateTrade(CapFloorLegParametersRange leg1Parameters,
                                        IBusinessCalendar leg1FixingCalendar,
                                        IBusinessCalendar leg1PaymentCalendar,
                                        Schedule capStrikeSchedule,
                                        Schedule floorStrikeSchedule,
                                        Schedule spreadSchedule,
                                        NonNegativeAmountSchedule notionalSchedule)
        {
            var stream1 = GetCashflowsSchedule(leg1FixingCalendar, leg1PaymentCalendar, leg1Parameters);

            if (null != capStrikeSchedule && null != floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetCapRateSchedule(stream1, capStrikeSchedule, true);
                InterestRateStreamParametricDefinitionGenerator.SetFloorRateSchedule(stream1, floorStrikeSchedule, false);
            }
            if (null != capStrikeSchedule && null == floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetCapRateSchedule(stream1, capStrikeSchedule, true);
            }
            if (null == capStrikeSchedule && null != floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetFloorRateSchedule(stream1, floorStrikeSchedule, true);
            }
            if (null != spreadSchedule) //for float legs only
            {
                InterestRateStreamParametricDefinitionGenerator.SetSpreadSchedule(stream1, spreadSchedule);
            }
            if (null != notionalSchedule)
            {
                //  Set notional schedule
                //
                InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(stream1, notionalSchedule);
            }
            var capFloor = CapFloorFactory.Create(stream1);
            var trade    = new Trade();

            XsdClassesFieldResolver.TradeSetCapFloor(trade, capFloor);
            return(trade);
        }
        private static InterestRateStream GenerateCapFloorStreamDefinition(CapFloorLegParametersRange legParametersRange)
        {
            Discounting        discounting = null;
            InterestRateStream stream;

            if (legParametersRange.DiscountingType != null && legParametersRange.DiscountingType.ToUpper() != "NONE")
            {
                discounting = new Discounting
                {
                    discountingType =
                        EnumHelper.Parse <DiscountingTypeEnum>(legParametersRange.DiscountingType)
                };
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(discounting.discountingType));
            }
            // Create the stream object
            //
            else
            {
                stream = InterestRateStreamFactory.CreateFloatingRateStream(DiscountingTypeToPayRelativeTo(null));
            }
            // Set effective and termination dates of the stream.
            //
            SetEffectiveAndTerminationDates(stream, legParametersRange.EffectiveDate, legParametersRange.MaturityDate, legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            // Adjusted or unadjusted swap
            //
            stream.calculationPeriodDates.calculationPeriodDatesAdjustments = AdjustedType.Adjusted != legParametersRange.AdjustedType ? BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, legParametersRange.PaymentCalendar) : BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            stream.calculationPeriodDates.calculationPeriodFrequency        = CalculationPeriodFrequencyHelper.Parse(legParametersRange.PaymentFrequency, legParametersRange.RollConvention);
            stream.paymentDates.paymentFrequency        = PeriodHelper.Parse(legParametersRange.PaymentFrequency).ToFrequency();
            stream.paymentDates.paymentDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.PaymentBusinessDayAdjustments, legParametersRange.PaymentCalendar);
            stream.resetDates.fixingDates           = RelativeDateOffsetHelper.Create(legParametersRange.PaymentFrequency, DayTypeEnum.Business, BusinessDayConventionEnum.NONE.ToString(), legParametersRange.FixingCalendar, "resetDates");//"NONE" & "resedDates" - hardcoded
            stream.resetDates.resetFrequency        = ResetFrequencyHelper.Parse(legParametersRange.PaymentFrequency);
            stream.resetDates.resetDatesAdjustments = BusinessDayAdjustmentsHelper.Create(legParametersRange.FixingBusinessDayAdjustments, legParametersRange.FixingCalendar);
            Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(stream.calculationPeriodAmount);

            //  Set discounting type
            //
            calculation.discounting = discounting;
            // Set notional amount (as the initial value in notional schedule)
            //
            SetNotional(calculation, legParametersRange.NotionalAmount, legParametersRange.Currency);
            // Set floating rate index name
            //
            string indexTenor = legParametersRange.PaymentFrequency;
            string indexName  = legParametersRange.ForecastIndexName;
            FloatingRateCalculation floatingRateCalculation = FloatingRateCalculationFactory.Create(indexName, indexTenor, legParametersRange.FloatingRateSpread);

            XsdClassesFieldResolver.CalculationSetFloatingRateCalculation(calculation, floatingRateCalculation);
            if (legParametersRange.CapOrFloor == CapFloorType.Cap)
            {
                floatingRateCalculation.capRateSchedule = new[] { new StrikeSchedule() };
                floatingRateCalculation.capRateSchedule[0].initialValue = legParametersRange.StrikeRate;
                floatingRateCalculation.capRateSchedule[0].buyer        = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
                floatingRateCalculation.capRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
            }
            else
            {
                floatingRateCalculation.floorRateSchedule = new[] { new StrikeSchedule() };
                floatingRateCalculation.floorRateSchedule[0].initialValue = legParametersRange.StrikeRate;
                floatingRateCalculation.floorRateSchedule[0].buyer        = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Receiver
                };
                floatingRateCalculation.floorRateSchedule[0].seller = new IdentifiedPayerReceiver {
                    Value = PayerReceiverEnum.Payer
                };
            }
            // Set day count convention
            //
            calculation.dayCountFraction = DayCountFractionHelper.Parse(legParametersRange.DayCount);
            return(stream);
        }