예제 #1
0
        public string CreateValuation(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwaptionParametersRange swaptionParametersRange,
            List <StringObjectRangeItem> valuationSet,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange leg1ParametersRange,
            SwapLegParametersRange leg2ParametersRange,
            List <InputCashflowRangeItem> leg1DetailedCashflowsListArray,
            List <InputCashflowRangeItem> leg2DetailedCashflowsListArray,
            List <InputPrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowListArray,
            List <InputPrincipalExchangeCashflowRangeItem> leg2PrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentListArray,
            List <AdditionalPaymentRangeItem> leg2AdditionalPaymentListArray,
            List <PartyIdRangeItem> partyIdList,                     //optional
            List <OtherPartyPaymentRangeItem> otherPartyPaymentList, //opt
            List <FeePaymentRangeItem> feePaymentList                //opt
            )
        {
            var swap = GetPriceAndGeneratedFpMLSwap(logger, cache, nameSpace,
                                                    fixingCalendar, paymentCalendar, valuationRange,
                                                    tradeRange, leg1ParametersRange, leg2ParametersRange,
                                                    leg1DetailedCashflowsListArray, leg2DetailedCashflowsListArray,
                                                    leg1PrincipalExchangeCashflowListArray, leg2PrincipalExchangeCashflowListArray,
                                                    leg1AdditionalPaymentListArray, leg2AdditionalPaymentListArray).Second;
            string            baseParty    = valuationRange.BaseParty;
            List <IRateCurve> uniqueCurves = GetUniqueCurves(logger, cache, nameSpace, leg1ParametersRange, leg2ParametersRange);
            Market            fpMLMarket   = InterestRateProduct.CreateFpMLMarketFromCurves(uniqueCurves);
            //  TODO: add Trade Id & Trade data into valuation. (Trade.Id & Trade.TradeHeader.TradeDate)
            //
            //  create ValuationReport and add it to in-memory collection.
            //  Add methods!
            AssetValuation           assetValuation = InterestRateProduct.CreateAssetValuationFromValuationSet(valuationSet);
            NonNegativeMoney         premium        = MoneyHelper.GetNonNegativeAmount(swaptionParametersRange.Premium, swaptionParametersRange.PremiumCurrency);
            AdjustableDate           expirationDate = DateTypesHelper.ToAdjustableDate(swaptionParametersRange.ExpirationDate, swaptionParametersRange.ExpirationDateBusinessDayAdjustments, swaptionParametersRange.ExpirationDateCalendar);
            AdjustableOrAdjustedDate paymentDate    = DateTypesHelper.ToAdjustableOrAdjustedDate(swaptionParametersRange.PaymentDate, swaptionParametersRange.PaymentDateBusinessDayAdjustments, swaptionParametersRange.PaymentDateCalendar);
            TimeSpan earliestExerciseTimeAsTimeSpan = TimeSpan.FromDays(swaptionParametersRange.EarliestExerciseTime);
            DateTime earliestExerciseTime           = DateTime.MinValue.Add(earliestExerciseTimeAsTimeSpan);
            TimeSpan expirationTimeAsTimeSpan       = TimeSpan.FromDays(swaptionParametersRange.ExpirationTime);
            DateTime expirationTime = DateTime.MinValue.Add(expirationTimeAsTimeSpan);
            var      swaption       = SwaptionFactory.Create(swap, premium, swaptionParametersRange.PremiumPayer, swaptionParametersRange.PremiumReceiver,
                                                             paymentDate, expirationDate,
                                                             earliestExerciseTime, expirationTime, swaptionParametersRange.AutomaticExcercise);
            // overrides the premium created by SwaptionFactort.Create
            //
            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),
                    payerPartyReference    = PartyReferenceFactory.Create(feePaymentRangeItem.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver)
                }));
            }
            swaption.premium = feeList.ToArray();
            string valuationReportAndProductId = tradeRange.Id ?? Guid.NewGuid().ToString();

            swaption.id = valuationReportAndProductId;
            ValuationReport valuationReport = ValuationReportGenerator.Generate(valuationReportAndProductId, baseParty, valuationReportAndProductId, tradeRange.TradeDate, swaption, fpMLMarket, assetValuation);

            cache.SaveObject(valuationReport, valuationReportAndProductId, null);
            InterestRateProduct.ReplacePartiesInValuationReport(valuationReport, partyIdList);
            InterestRateProduct.AddOtherPartyPayments(valuationReport, otherPartyPaymentList);
            return(valuationReportAndProductId);
        }
예제 #2
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));
        }
예제 #3
0
        /// <summary>
        /// Creates a vanilla fx option.
        /// </summary>
        /// <param name="buyerPartyReference"></param>
        /// <param name="sellerPartyReference"></param>
        /// <param name="soldAs"></param>
        /// <param name="period"> </param>
        /// <param name="expiryDate"></param>
        /// <param name="expiryBusinessCenter"> </param>
        /// <param name="cutName"> </param>
        /// <param name="isCashSettled"></param>
        /// <param name="settlementCurrency"></param>
        /// <param name="fixingDate"></param>
        /// <param name="quotedCurrencyPair"></param>
        /// <param name="putCurrencyAmount"></param>
        /// <param name="putCurrency"></param>
        /// <param name="callCurrencyAmount"></param>
        /// <param name="spotRate"></param>
        /// <param name="callCurrency"></param>
        /// <param name="strikeQuoteBasis"></param>
        /// <param name="valueDate"></param>
        /// <param name="strikePrice"></param>
        /// <param name="premia"></param>
        /// <param name="time"> </param>
        /// <returns></returns>
        public static FxOption CreateVanillaOption(string buyerPartyReference, string sellerPartyReference, PutCallEnum?soldAs, string period,
                                                   DateTime expiryDate, DateTime time, string expiryBusinessCenter, CutName cutName, decimal putCurrencyAmount, string putCurrency,
                                                   decimal callCurrencyAmount, string callCurrency, StrikeQuoteBasisEnum strikeQuoteBasis, DateTime valueDate, Decimal strikePrice, decimal?spotRate,
                                                   bool isCashSettled, Currency settlementCurrency, DateTime?fixingDate, QuotedCurrencyPair quotedCurrencyPair, List <FxOptionPremium> premia)
        {
            CutName cut = null;

            if (cutName != null)
            {
                cut = new CutName {
                    Value = cutName.Value
                };
            }
            var expiryDateTime = new FxEuropeanExercise
            {
                expiryDate = expiryDate,
                expiryTime =
                    new BusinessCenterTime
                {
                    hourMinuteTime = time,
                    businessCenter = new BusinessCenter {
                        Value = expiryBusinessCenter
                    }
                },
                cutName            = cut,
                valueDate          = valueDate,
                valueDateSpecified = true
            };

            FxOptionPremium[] premiumValues = null;
            if (premia != null)
            {
                premiumValues = premia.ToArray();
            }
            var fxOption = new FxOption
            {
                Items = new object[] { new ProductType {
                                           Value = ProductTypeSimpleEnum.FxOption.ToString()
                                       } },
                ItemsElementName   = new[] { ItemsChoiceType2.productType },
                putCurrencyAmount  = MoneyHelper.GetNonNegativeAmount(putCurrencyAmount, putCurrency),
                callCurrencyAmount = MoneyHelper.GetNonNegativeAmount(callCurrencyAmount, callCurrency),
                strike             =
                    new FxStrikePrice {
                    rate = strikePrice, rateSpecified = true, strikeQuoteBasis = strikeQuoteBasis, strikeQuoteBasisSpecified = true
                },
                buyerPartyReference  = PartyReferenceFactory.Create(buyerPartyReference),
                sellerPartyReference =
                    PartyReferenceFactory.Create(sellerPartyReference),
                premium = premiumValues,
                Item    = expiryDateTime,
            };

            if (spotRate != null)
            {
                fxOption.spotRate          = (decimal)spotRate;
                fxOption.spotRateSpecified = true;
            }
            if (period != null)
            {
                var tenorPeriod = PeriodHelper.Parse(period);
                fxOption.tenorPeriod = tenorPeriod;
            }
            if (soldAs != null)
            {
                fxOption.soldAs          = (PutCallEnum)soldAs;
                fxOption.soldAsSpecified = true;
            }
            if (isCashSettled)
            {
                fxOption.cashSettlement = new FxCashSettlement {
                    settlementCurrency = settlementCurrency
                };
                var fxFixing = new FxFixing();
                if (fixingDate != null)
                {
                    fxFixing.fixingDate          = (DateTime)fixingDate;
                    fxFixing.fixingDateSpecified = true;
                }
                fxFixing.quotedCurrencyPair    = quotedCurrencyPair;
                fxOption.cashSettlement.fixing = new [] { fxFixing };
            }
            return(fxOption);
        }
예제 #4
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 definition + cashflows schedule
            InterestRateStream stream2 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg2ParametersRange); //parametric definition + 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));
        }