Ejemplo n.º 1
0
        internal static Pair <ValuationResultRange, Swap> GetPriceAndGeneratedFpMLSwap(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange_Old leg1ParametersRange,
            List <DetailedCashflowRangeItem> leg1DetailedCashflowsList,
            List <PrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowList,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList)
        {
            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange);//parametric definiton + cashflows schedule
            var swap = SwapFactory.Create(stream1);

            // Update FpML cashflows
            //
            UpdateCashflowsWithDetailedCashflows(stream1.cashflows, leg1DetailedCashflowsList);
            //  Update PE
            //
            if (null != leg1PrincipalExchangeCashflowList)
            {
                CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, leg1PrincipalExchangeCashflowList);
            }
            //  Add bullet payments...
            //
            if (null != leg1AdditionalPaymentList)
            {
                swap.additionalPayment = 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)
                }).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);

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

            return(new Pair <ValuationResultRange, Swap>(CreateValuationRange(swap, baseParty), swap));
        }
        public Swaption GenerateSwaptionParametricWithCashflows()
        {
            var payLeg = new SwapLegParametersRange_Old
            {
                AdjustedType  = AdjustedType.Unadjusted,
                EffectiveDate = new DateTime(1994, 12, 14),
                MaturityDate  = new DateTime(1999, 12, 14),
                FirstRegularPeriodStartDate = new DateTime(1995, 6, 14),
                RollConvention                = "14",
                InitialStubType               = StubPeriodTypeEnum.ShortInitial.ToString(),
                FinalStubType                 = StubPeriodTypeEnum.ShortFinal.ToString(),
                NotionalAmount                = 1000000,
                LegType                       = LegType.Fixed,
                Currency                      = "AUD",
                CouponOrLastResetRate         = 0.08m,
                PaymentFrequency              = "6M",
                DayCount                      = "Actual360",
                PaymentCalendar               = "AUSY",
                PaymentBusinessDayAdjustments = "FOLLOWING",
                FixingCalendar                = "AUSY-GBLO",
                FixingBusinessDayAdjustments  = "MODFOLLOWING",
                DiscountCurve                 = "AUD-LIBOR",
                DiscountingType               = "Standard"
            };

            var receiveLeg = new SwapLegParametersRange_Old
            {
                AdjustedType  = AdjustedType.Unadjusted,
                EffectiveDate = new DateTime(1994, 12, 14),
                MaturityDate  = new DateTime(1999, 12, 14),
                FirstRegularPeriodStartDate = new DateTime(1995, 6, 14),
                RollConvention                = "14",
                InitialStubType               = StubPeriodTypeEnum.ShortInitial.ToString(),
                FinalStubType                 = StubPeriodTypeEnum.ShortFinal.ToString(),
                NotionalAmount                = 1000000,
                LegType                       = LegType.Floating,
                Currency                      = "AUD",
                FloatingRateSpread            = 0,
                PaymentFrequency              = "6M",
                DayCount                      = "Actual360",
                PaymentCalendar               = "AUSY",
                PaymentBusinessDayAdjustments = "FOLLOWING",
                FixingCalendar                = "AUSY-GBLO",
                FixingBusinessDayAdjustments  = "MODFOLLOWING",
                DiscountCurve                 = "AUD-LIBOR",
                ForecastCurve                 = "AUD-LIBOR",
                DiscountingType               = "Standard"
            };
            var  marketEnvironment = CreateInterestRateStreamTestEnvironment(new DateTime(1994, 12, 14));
            var  valuationDT       = new DateTime(1994, 12, 20);
            Swap swap = SwapGenerator.GenerateDefinitionCashflowsAmounts(Engine.Logger, Engine.Cache, Engine.NameSpace, payLeg, null, receiveLeg, null, null, null, null, marketEnvironment, valuationDT);

            Assert.AreEqual(swap.swapStream.Length, 2);
            Assert.IsNotNull(swap.swapStream[0].cashflows);
            Assert.IsNotNull(swap.swapStream[1].cashflows);
            var swaption = new Swaption {
                swap = swap
            };

            return(swaption);
        }