Exemplo n.º 1
0
        private static void UpdateCashflowsWithDetailedCashflows(Cashflows cashflows, IEnumerable <DetailedCashflowRangeItem> listDetailedCashflows /*, bool fixedLeg*/)
        {
            var paymentCalculationPeriods = new List <PaymentCalculationPeriod>();

            foreach (DetailedCashflowRangeItem detailedCashflowRangeItem in listDetailedCashflows)
            {
                var paymentCalculationPeriod = new PaymentCalculationPeriod();
                var calculationPeriod        = new CalculationPeriod();
                paymentCalculationPeriod.Items = new object[] { calculationPeriod };
                paymentCalculationPeriod.adjustedPaymentDate          = detailedCashflowRangeItem.PaymentDate;
                paymentCalculationPeriod.adjustedPaymentDateSpecified = true;
                PaymentCalculationPeriodHelper.SetCalculationPeriodStartDate(paymentCalculationPeriod, detailedCashflowRangeItem.StartDate);
                PaymentCalculationPeriodHelper.SetCalculationPeriodEndDate(paymentCalculationPeriod, detailedCashflowRangeItem.EndDate);
                // Update notional amount
                //
                PaymentCalculationPeriodHelper.SetNotionalAmount(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.NotionalAmount);
                if (detailedCashflowRangeItem.CouponType == "Fixed")
                {
                    //CalculationPeriod calculationPeriod = PaymentCalculationPeriodHelper.GetCalculationPeriods(paymentCalculationPeriod)[0];

                    //if (XsdClassesFieldResolver.CalculationPeriod_HasFixedRate(calculationPeriod))
                    //{
                    //  Fixed->Fixed
                    //
                    //PaymentCalculationPeriodHelper.SetRate(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Rate);

                    XsdClassesFieldResolver.SetCalculationPeriodFixedRate(calculationPeriod, (decimal)detailedCashflowRangeItem.Rate);
                    //}
                    //else if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod))
//                    {
//                        //  Float->Fixed
//                        //
//                        PaymentCalculationPeriodHelper.ReplaceFloatingRateWithFixedRate(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Rate);
//                    }
//                    else
//                    {
//                        throw new NotImplementedException();
//                    }
                }
                else if (detailedCashflowRangeItem.CouponType == "Float")
                {
                    //  Create floating rate definiton...
                    //
                    var floatingRateDefinition = new FloatingRateDefinition();
                    //XsdClassesFieldResolver.CalculationPeriod_SetFloatingRateDefinition(calculationPeriod, floatingRateDefinition);
                    calculationPeriod.Item1 = floatingRateDefinition;
                    // After the spread is reset - we need to update calculated rate.
                    //
                    PaymentCalculationPeriodHelper.SetSpread(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Spread);
                }
                else
                {
                    string message = $"Unsupported coupon type '{detailedCashflowRangeItem.CouponType}";
                    throw new System.Exception(message);
                }
                paymentCalculationPeriods.Add(paymentCalculationPeriod);
            }
            cashflows.cashflowsMatchParameters = false;
            cashflows.paymentCalculationPeriod = paymentCalculationPeriods.ToArray();
        }
Exemplo n.º 2
0
        private static Cashflows UpdateCashflowsWithDetailedCashflows(IEnumerable <InputCashflowRangeItem> listDetailedCashflows /*, bool fixedLeg*/)
        {
            var cashflows = new Cashflows();
            var paymentCalculationPeriods = new List <PaymentCalculationPeriod>();

            foreach (var detailedCashflowRangeItem in listDetailedCashflows)
            {
                var paymentCalculationPeriod = new PaymentCalculationPeriod();
                var calculationPeriod        = new CalculationPeriod();
                paymentCalculationPeriod.Items = new object[] { calculationPeriod };
                paymentCalculationPeriod.adjustedPaymentDate          = detailedCashflowRangeItem.PaymentDate;
                paymentCalculationPeriod.adjustedPaymentDateSpecified = true;
                PaymentCalculationPeriodHelper.SetCalculationPeriodStartDate(paymentCalculationPeriod, detailedCashflowRangeItem.StartDate);
                PaymentCalculationPeriodHelper.SetCalculationPeriodEndDate(paymentCalculationPeriod, detailedCashflowRangeItem.EndDate);
                // Update notional amount
                //
                PaymentCalculationPeriodHelper.SetNotionalAmount(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.NotionalAmount);
                switch (detailedCashflowRangeItem.CouponType.ToLower())
                {
                case "cap":
                {
                    var floatingRateDefinition = new FloatingRateDefinition();
                    calculationPeriod.Item1 = floatingRateDefinition;
                    // After the spread is reset - we need to update calculated rate.
                    //
                    PaymentCalculationPeriodHelper.SetSpread(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Spread);
                    floatingRateDefinition.capRate = new[] { new Strike() };
                    floatingRateDefinition.capRate[0].strikeRate = (decimal)detailedCashflowRangeItem.StrikeRate;        //tODO There is no fixing date.
                    {
                        var rateObservation = new RateObservation
                        {
                            adjustedFixingDate =
                                detailedCashflowRangeItem.FixingDate,
                            adjustedFixingDateSpecified = true
                        };
                        floatingRateDefinition.rateObservation = new[] { rateObservation };
                    }
                    break;
                }

                case "floor":
                {
                    var floatingRateDefinition = new FloatingRateDefinition();
                    //XsdClassesFieldResolver.CalculationPeriod_SetFloatingRateDefinition(calculationPeriod, floatingRateDefinition);
                    calculationPeriod.Item1 = floatingRateDefinition;
                    // After the spread is reset - we need to update calculated rate.
                    //
                    PaymentCalculationPeriodHelper.SetSpread(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Spread);
                    floatingRateDefinition.capRate = new[] { new Strike() };
                    floatingRateDefinition.capRate[0].strikeRate = (decimal)detailedCashflowRangeItem.StrikeRate;

                    {
                        var rateObservation = new RateObservation
                        {
                            adjustedFixingDate =
                                detailedCashflowRangeItem.FixingDate,
                            adjustedFixingDateSpecified = true
                        };
                        floatingRateDefinition.rateObservation = new[] { rateObservation };
                    }
                    break;
                }

                default:
                {
                    string message = String.Format("Specified coupon type : '{0}' is not supported. Please use one of these: 'cap, floor'", detailedCashflowRangeItem.CouponType.ToLower());
                    throw new NotSupportedException(message);
                }
                }
                paymentCalculationPeriods.Add(paymentCalculationPeriod);
            }
            cashflows.cashflowsMatchParameters = true;
            cashflows.paymentCalculationPeriod = paymentCalculationPeriods.ToArray();
            return(cashflows);
        }