Exemple #1
0
        internal static void AddOtherPartyPayments(ValuationReport valuationReport, List <OtherPartyPaymentRangeItem> otherPartyPaymentList)
        {
            var otherPartyPayments = new List <Payment>();

            //  other party payments
            //
            if (null != otherPartyPaymentList)
            {
                foreach (OtherPartyPaymentRangeItem item in otherPartyPaymentList)
                {
                    var otherPartyPayment = new Payment
                    {
                        payerPartyReference =
                            PartyReferenceFactory.Create(item.Payer),
                        receiverPartyReference =
                            PartyReferenceFactory.Create(item.Receiver),
                        paymentAmount = MoneyHelper.GetNonNegativeAmount(item.Amount),
                        paymentDate   = AdjustableOrAdjustedDateHelper.CreateAdjustedDate(item.PaymentDate),
                        paymentType   = PaymentTypeHelper.Create(item.PaymentType)
                    };
                    otherPartyPayments.Add(otherPartyPayment);
                }
            }
            TradeValuationItem valuationItem = valuationReport.tradeValuationItem[0];

            Trade[] tradeArray = XsdClassesFieldResolver.TradeValuationItemGetTradeArray(valuationItem);
            Trade   trade      = tradeArray[0];

            trade.otherPartyPayment = otherPartyPayments.ToArray();
        }
        public static InterestRateStream GenerateStreamDefinition(SwapLegParametersRange legParametersRange)
        {
            InterestRateStream result;

            if (legParametersRange.LegType == LegType.Fixed)
            {
                result = GenerateFixedStreamDefinition(legParametersRange);
            }
            else if (legParametersRange.LegType == LegType.Floating)
            {
                result = GenerateFloatingStreamDefinition(legParametersRange);
            }
            else
            {
                throw new NotImplementedException(String.Format("'{0}' leg type is not suported!", legParametersRange.LegType));
            }
            //  Payer/Receiver references
            //
            result.payerPartyReference    = PartyReferenceFactory.Create(legParametersRange.Payer);
            result.receiverPartyReference = PartyReferenceFactory.Create(legParametersRange.Receiver);
            //  Principal exchanges
            //
            result.principalExchanges = new PrincipalExchanges();
            result.principalExchanges.initialExchange              =
                result.principalExchanges.finalExchange            =
                    result.principalExchanges.intermediateExchange = legParametersRange.GeneratePrincipalExchanges;
            return(result);
        }
        public static ValuationReport Generate(string valuationId, string party1Name, string party2Name,
                                               bool isParty1Base, Trade trade, Market market,
                                               AssetValuation assetValuation)
        {
            var valuationReport = new ValuationReport
            {
                header = new NotificationMessageHeader
                {
                    messageId = new MessageId
                    {
                        Value = valuationId
                    }
                },
                market = market
            };
            //  Associate id with the valuation
            //
            var tradeValuationItem = new TradeValuationItem();

            valuationReport.tradeValuationItem = new[] { tradeValuationItem };
            string baseParty = isParty1Base ? party1Name : party2Name;
            Party  party1    = PartyFactory.Create("Party1", party1Name);
            Party  party2    = PartyFactory.Create("Party2", party2Name);

            valuationReport.party           = new[] { party1, party2 };
            tradeValuationItem.Items        = new object[] { trade };
            tradeValuationItem.valuationSet = new ValuationSet
            {
                baseParty      = PartyReferenceFactory.Create(baseParty),
                assetValuation = new[] { assetValuation }
            };
            return(valuationReport);
        }
        public static ValuationReport Generate(string valuationId, string baseParty, Fra fra, Market market, AssetValuation assetValuation)
        {
            var valuationReport = new ValuationReport
            {
                header = new NotificationMessageHeader
                {
                    messageId = new MessageId
                    {
                        Value
                            =
                                valuationId
                    }
                },
                market = market
            };
            //  Associate id with the valuation
            //
            var tradeValuationItem = new TradeValuationItem();

            valuationReport.tradeValuationItem = new[] { tradeValuationItem };
            var trade = new Trade();

            XsdClassesFieldResolver.TradeSetFra(trade, fra);
            tradeValuationItem.Items        = new object[] { trade };
            tradeValuationItem.valuationSet = new ValuationSet
            {
                baseParty      = PartyReferenceFactory.Create(baseParty),
                assetValuation = new[] { assetValuation }
            };
            return(valuationReport);
        }
        public static ValuationReport Generate(string valuationId, string baseParty,
                                               string tradeId, DateTime tradeDate,
                                               Swap swap, Market market,
                                               AssetValuation assetValuation)
        {
            var valuationReport = new ValuationReport
            {
                header = new NotificationMessageHeader
                {
                    messageId = new MessageId
                    {
                        Value
                            =
                                valuationId
                    }
                },
                market = market
            };
            //  Associate id with the valuation
            //
            var tradeValuationItem = new TradeValuationItem();

            valuationReport.tradeValuationItem = new[] { tradeValuationItem };

            //Party nabParty = PartyFactory.Create("Party1");
            //Party counterParty = PartyFactory.Create(_counterpartyName);
//
//            valuationReport.party = new Party[] { nabParty, counterParty };

//            PartyOrAccountReference nabPartyReference = PartyOrAccountReferenceFactory.Create(nabParty.id);
//            PartyOrAccountReference counterPartyReference = PartyOrAccountReferenceFactory.Create(counterParty.id);

//            // NAB is the payer of pay paystream and receiver of receive stream
//            //
//            SwapHelper.GetPayerStream(swap).payerPartyReference = nabPartyReference;
//            SwapHelper.GetReceiverStream(swap).receiverPartyReference = nabPartyReference;
//
//            // CounterParty is the receiver of paystream and payer of receivestream
//            //
//            SwapHelper.GetPayStream(swap).receiverPartyReference = counterPartyReference;
//            SwapHelper.GetReceiveStream(swap).payerPartyReference = counterPartyReference;

            var trade = new Trade();
            //  Generate trade header
            //
            TradeHeader tradeHeader = CreateTradeHeader(tradeDate, tradeId);

            trade.tradeHeader = tradeHeader;
            XsdClassesFieldResolver.TradeSetSwap(trade, swap);
            tradeValuationItem.Items        = new object[] { trade };
            tradeValuationItem.valuationSet = new ValuationSet
            {
                baseParty      = PartyReferenceFactory.Create(baseParty),
                assetValuation = new[] { assetValuation }
            };
            return(valuationReport);
        }
Exemple #6
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);
        }
Exemple #7
0
        public static Trade CreateFraTrade(FraInputRange2 fraInputRange)
        {
            var trade = new Trade();
            var fra   = new Fra
            {
                adjustedEffectiveDate =
                    DateTypesHelper.ToRequiredIdentifierDate(fraInputRange.AdjustedEffectiveDate),
                adjustedTerminationDate          = fraInputRange.AdjustedTerminationDate,
                adjustedTerminationDateSpecified = true,
                paymentDate =
                    DateTypesHelper.ToAdjustableDate(fraInputRange.UnadjustedPaymentDate,
                                                     fraInputRange.PaymentDateBusinessDayConvention,
                                                     fraInputRange.PaymentDateBusinessCenters),
                Items = new object[] { new ProductType {
                                           Value = ProductTypeSimpleEnum.FRA.ToString()
                                       } },
                ItemsElementName = new[] { ItemsChoiceType2.productType }
            };

            if ("resetDate" != fraInputRange.FixingDayOffsetDateRelativeTo)
            {
                throw new ArgumentException("The fixing date must be specified as 'resetDate'-relative!", nameof(fraInputRange));
            }
            var fixingDayType = EnumHelper.Parse <DayTypeEnum>(fraInputRange.FixingDayOffsetDayType);

            fra.fixingDateOffset = RelativeDateOffsetHelper.Create(fraInputRange.FixingDayOffsetPeriod, fixingDayType,
                                                                   fraInputRange.FixingDayOffsetBusinessDayConvention,
                                                                   fraInputRange.FixingDayOffsetBusinessCenters,
                                                                   fraInputRange.FixingDayOffsetDateRelativeTo);
            fra.dayCountFraction = DayCountFractionHelper.Parse(fraInputRange.DayCountFraction);
            IDayCounter dayCounter = DayCounterHelper.Parse(fra.dayCountFraction.Value);

            fra.calculationPeriodNumberOfDays = dayCounter.DayCount(fra.adjustedEffectiveDate.Value, fra.adjustedTerminationDate).ToString(CultureInfo.InvariantCulture);
            fra.notional                = MoneyHelper.GetAmount(fraInputRange.NotionalAmount, fraInputRange.NotionalCurrency);
            fra.fixedRate               = (decimal)fraInputRange.FixedRate;
            fra.fixedRateSpecified      = true;
            fra.floatingRateIndex       = FloatingRateIndexHelper.Parse(fraInputRange.FloatingRateIndex);
            fra.indexTenor              = new[] { PeriodHelper.Parse(fraInputRange.IndexTenor) };
            fra.fraDiscounting          = fraInputRange.FraDiscounting;
            fra.fraDiscountingSpecified = true;
            PartyReference party1 = PartyReferenceFactory.Create("party1");
            PartyReference party2 = PartyReferenceFactory.Create("party2");

            fra.sellerPartyReference = party1;
            fra.buyerPartyReference  = party2;
            if (bool.Parse(fraInputRange.IsParty1Buyer))
            {
                fra.sellerPartyReference = party2;
                fra.buyerPartyReference  = party1;
            }
            XsdClassesFieldResolver.TradeSetFra(trade, fra);
            trade.id = fraInputRange.TradeId;
            return(trade);
        }
        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 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);
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fraInputRange"></param>
        /// <returns></returns>
        public static Fra GetFpMLFra(FraInputRange fraInputRange)
        {
            var fra = new Fra
            {
                adjustedEffectiveDate =
                    DateTypesHelper.ToRequiredIdentifierDate(fraInputRange.AdjustedEffectiveDate),
                adjustedTerminationDate = fraInputRange.AdjustedTerminationDate,
                paymentDate             =
                    DateTypesHelper.ToAdjustableDate(fraInputRange.UnadjustedPaymentDate,
                                                     fraInputRange.PaymentDateBusinessDayConvention,
                                                     fraInputRange.PaymentDateBusinessCenters)
            };

            if ("resetDate" != fraInputRange.FixingDayOffsetDateRelativeTo)
            {
                throw new ArgumentException("The fixing date must be specified as 'resetDate'-relative!", nameof(fraInputRange));
            }
            var fixingDayType = EnumHelper.Parse <DayTypeEnum>(fraInputRange.FixingDayOffsetDayType);

            fra.fixingDateOffset = RelativeDateOffsetHelper.Create(fraInputRange.FixingDayOffsetPeriod, fixingDayType,
                                                                   fraInputRange.FixingDayOffsetBusinessDayConvention,
                                                                   fraInputRange.FixingDayOffsetBusinessCenters,
                                                                   fraInputRange.FixingDayOffsetDateRelativeTo);
            fra.dayCountFraction = DayCountFractionHelper.Parse(fraInputRange.DayCountFraction);
            IDayCounter dayCounter = DayCounterHelper.Parse(fra.dayCountFraction.Value);

            fra.calculationPeriodNumberOfDays = dayCounter.DayCount(fra.adjustedEffectiveDate.Value, fra.adjustedTerminationDate).ToString();
            fra.notional          = MoneyHelper.GetAmount(fraInputRange.NotionalAmount, fraInputRange.NotionalCurrency);
            fra.fixedRate         = (decimal)fraInputRange.FixedRate;
            fra.floatingRateIndex = FloatingRateIndexHelper.Parse(fraInputRange.FloatingRateIndex);
            fra.indexTenor        = new[] { PeriodHelper.Parse(fraInputRange.IndexTenor) };
            fra.fraDiscounting    = fraInputRange.FraDiscounting;
            PartyReference nabParty     = PartyReferenceFactory.Create("NAB");
            PartyReference counterParty = PartyReferenceFactory.Create("COUNTERPARTY");

            if (bool.Parse(fraInputRange.Sell))
            {
                fra.sellerPartyReference = nabParty;
                fra.buyerPartyReference  = counterParty;
            }
            else
            {
                fra.sellerPartyReference = counterParty;
                fra.buyerPartyReference  = nabParty;
            }
            return(fra);
        }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceablePayment"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="payerPartyReference">The payer.</param>
 /// <param name="receiverPartyReference">The receiver.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="amount">The amount.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="paymentCalendar">Type paymentCalendar.</param>
 public PriceablePayment
 (
     string id
     , string payerPartyReference
     , string receiverPartyReference
     , bool payerIsBase
     , Money amount
     , AdjustableOrAdjustedDate paymentDate
     , IBusinessCalendar paymentCalendar) :
     base(id, "DiscountedCashflow", payerIsBase, amount, paymentDate, PaymentTypeHelper.Create("Certain"),
          CashflowTypeHelper.Create(CashflowTypeEnum.PrincipalExchange.ToString()), false, paymentCalendar)
 {
     PayerPartyReference    = PartyReferenceFactory.Create(payerPartyReference);
     ReceiverPartyReference = PartyReferenceFactory.Create(receiverPartyReference);
     OrderedPartyNames.Add(PayerPartyReference.href);
     OrderedPartyNames.Add(ReceiverPartyReference.href);
 }
        /// <summary>
        /// Builds this instance.
        /// </summary>
        /// <returns></returns>
        public InterestRateStream Build()
        {
            var irstream = new InterestRateStream
            {
                cashflows               = BuildCashflows(),
                payerPartyReference     = PartyReferenceFactory.Create(Payer),
                receiverPartyReference  = PartyReferenceFactory.Create(Receiver),
                calculationPeriodDates  = CalculationPeriodDates,
                calculationPeriodAmount = CalculationPeriodAmount,
                id                          = Id,
                paymentDates                = PaymentDates,
                principalExchanges          = PrincipalExchanges,
                resetDates                  = ResetDates,
                settlementProvision         = SettlementProvision,
                stubCalculationPeriodAmount = StubCalculationPeriodAmount
            };

            return(irstream);
        }
Exemple #13
0
        public static Trade CreateFraTrade(string tradeId, RequiredIdentifierDate adjustedEffectiveDate, DateTime adjustedTerminationDate,
                                           AdjustableDate paymentDate, RelativeDateOffset fixingDayOffset, DayCountFraction dayCountFraction, decimal notionalAmount,
                                           string notionalCurrency, decimal fixedRate, string floatingRateIndex, string indexTenor, FraDiscountingEnum fraDiscounting)
        {
            var trade = new Trade();
            var fra   = new Fra
            {
                adjustedEffectiveDate            = adjustedEffectiveDate,
                adjustedTerminationDate          = adjustedTerminationDate,
                adjustedTerminationDateSpecified = true,
                paymentDate = paymentDate,
                Items       = new object[] { new ProductType {
                                                 Value = ProductTypeSimpleEnum.FRA.ToString()
                                             } },
                ItemsElementName = new[] { ItemsChoiceType2.productType }
            };

            if ("resetDate" != fixingDayOffset.dateRelativeTo.href)
            {
                throw new ArgumentException("The fixing date must be specified as 'resetDate'-relative!", nameof(fixingDayOffset));
            }
            fra.fixingDateOffset = fixingDayOffset;
            fra.dayCountFraction = dayCountFraction;
            IDayCounter dayCounter = DayCounterHelper.Parse(fra.dayCountFraction.Value);

            fra.calculationPeriodNumberOfDays = dayCounter.DayCount(fra.adjustedEffectiveDate.Value, fra.adjustedTerminationDate).ToString(CultureInfo.InvariantCulture);
            fra.notional                = MoneyHelper.GetAmount(notionalAmount, notionalCurrency);
            fra.fixedRate               = fixedRate;
            fra.fixedRateSpecified      = true;
            fra.floatingRateIndex       = FloatingRateIndexHelper.Parse(floatingRateIndex);
            fra.indexTenor              = new[] { PeriodHelper.Parse(indexTenor) };
            fra.fraDiscounting          = fraDiscounting;
            fra.fraDiscountingSpecified = true;
            PartyReference party1 = PartyReferenceFactory.Create("party1");
            PartyReference party2 = PartyReferenceFactory.Create("party2");

            fra.sellerPartyReference = party2;
            fra.buyerPartyReference  = party1;
            XsdClassesFieldResolver.TradeSetFra(trade, fra);
            trade.id = tradeId;
            return(trade);
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableFxOptionPremium"/> class.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="receiverPartyReference">The receiver.</param>
        /// <param name="payerIsBase">The flag determining if the payer is the base party.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="settlementDate">The adjusted payment date.</param>
        /// <param name="payerPartyReference">The payer.</param>
        /// <param name="premiumQuote">The premium quote </param>
        /// <param name="settlementInformation">The settlement information. </param>
        /// <param name="paymentCalendar">Type paymentCalendar.</param>
        public PriceableFxOptionPremium
        (
            string id
            , string payerPartyReference
            , string receiverPartyReference
            , bool payerIsBase
            , Money amount
            , DateTime settlementDate
            , PremiumQuote premiumQuote
            , SettlementInformation settlementInformation
            , IBusinessCalendar paymentCalendar) :
            base(id, "DiscountedCashflow", payerIsBase, amount,
                 AdjustableOrAdjustedDateHelper.CreateAdjustedDate(settlementDate),
                 PaymentTypeHelper.Create("Certain"), CashflowTypeHelper.Create(CashflowTypeEnum.Premium.ToString()), false, paymentCalendar)
        {
            PayerPartyReference    = PartyReferenceFactory.Create(payerPartyReference);
            ReceiverPartyReference = PartyReferenceFactory.Create(receiverPartyReference);
            OrderedPartyNames.Add(PayerPartyReference.href);
            OrderedPartyNames.Add(ReceiverPartyReference.href);
            if (premiumQuote != null)
            {
                PremiumQuote = new PremiumQuote
                {
                    quoteBasis          = premiumQuote.quoteBasis,
                    quoteBasisSpecified = true,
                    value          = premiumQuote.value,
                    valueSpecified = true
                };
            }
            if (settlementInformation == null)
            {
                return;
            }
            SettlementInformation = new SettlementInformation();
            var item = BinarySerializerHelper.Clone(settlementInformation.Item);

            SettlementInformation.Item = item;
        }
        public static ValuationReport Generate(string valuationId, string baseParty,
                                               string tradeId, DateTime tradeDate,
                                               Swaption swaption, Market market, AssetValuation assetValuation)
        {
            var valuationReport = new ValuationReport
            {
                header = new NotificationMessageHeader
                {
                    messageId = new MessageId
                    {
                        Value
                            =
                                valuationId
                    }
                },
                market = market
            };
            //  Associate id with the valuation
            //
            var tradeValuationItem = new TradeValuationItem();

            valuationReport.tradeValuationItem = new[] { tradeValuationItem };
            //  Generate trade header
            //
            var         trade       = new Trade();
            TradeHeader tradeHeader = CreateTradeHeader(tradeDate, tradeId);

            trade.tradeHeader = tradeHeader;
            XsdClassesFieldResolver.TradeSetSwaption(trade, swaption);
            tradeValuationItem.Items        = new object[] { trade };
            tradeValuationItem.valuationSet = new ValuationSet
            {
                baseParty      = PartyReferenceFactory.Create(baseParty),
                assetValuation = new[] { assetValuation }
            };
            return(valuationReport);
        }
Exemple #16
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));
        }
Exemple #17
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);
        }
 public static void SetPayerAndReceiver(InterestRateStream stream, string payer, string receiver)
 {
     stream.payerPartyReference    = PartyReferenceFactory.Create(payer);
     stream.receiverPartyReference = PartyReferenceFactory.Create(receiver);
 }
Exemple #19
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);
        }