예제 #1
0
        public static NonNegativeSchedule Create(Decimal initialValue)
        {
            var result = new NonNegativeSchedule {
                initialValue = initialValue, initialValueSpecified = true
            };

            return(result);
        }
예제 #2
0
        public static NonNegativeAmountSchedule Create(NonNegativeSchedule schedule, Currency currency)
        {
            var result = new NonNegativeAmountSchedule
            {
                currency     = currency,
                initialValue = schedule.initialValue,
                step         = schedule.step
            };

            return(result);
        }
예제 #3
0
        public static CapFloor GenerateDefiniton(CapFloorLegParametersRange_Old 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);
        }
예제 #4
0
        public List <DetailedCashflowRangeItem> GetDetailedCashflowsWithNotionalSchedule(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            var tempList = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
            NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(tempList);
            Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
            NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
            InterestRateStream        interestRateStream   = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);

            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            //int periodNumber = 1;
            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                list.Add(detailedCashflowRangeItem);
                detailedCashflowRangeItem.PaymentDate = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate   = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate     = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                //detailedCashflowRangeItem.NumberOfDays = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                //detailedCashflowRangeItem.FutureValue = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                //detailedCashflowRangeItem.PresentValue = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                //detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                //  If  floating rate - retrieve the spread.
                //
                if (legParametersRange.IsFloatingLegType())
                {
                    detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                }
            }

            return(list);
        }
예제 #5
0
        public static NonNegativeSchedule Create(IList <Pair <DateTime, decimal> > scheduleDatesAndValues)
        {
            var result      = new NonNegativeSchedule();
            var listOfSteps = new List <NonNegativeStep>();

            for (int i = 0; i < scheduleDatesAndValues.Count; ++i)
            {
                Pair <DateTime, decimal> pair = scheduleDatesAndValues[i];
                if (i == 0) //create a Schedule from the initial value
                {
                    result = Create(pair.Second);
                }
                else
                {
                    listOfSteps.Add(new NonNegativeStep {
                        stepDate = pair.First, stepValue = pair.Second, stepDateSpecified = true, stepValueSpecified = true
                    });
                }
            }
            result.step = listOfSteps.ToArray();
            return(result);
        }
예제 #6
0
        public List <PrincipalExchangeCashflowRangeItem> GetPrincipalExchanges(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            InterestRateStream interestRateStream;

            if (notionalValueItems.Count > 0)
            {
                var tempList = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
                NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(tempList);
                Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
                NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
                interestRateStream = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);
            }
            else
            {
                interestRateStream = GetCashflowsSchedule(fixingCalendar, paymentCalendar, legParametersRange);
            }
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <PrincipalExchangeCashflowRangeItem>();

            //int periodNumber = 0;
            foreach (PrincipalExchange principleExchange in interestRateStream.cashflows.principalExchange)
            {
                var principalExchangeCashflowRangeItem = new PrincipalExchangeCashflowRangeItem();
                list.Add(principalExchangeCashflowRangeItem);
                principalExchangeCashflowRangeItem.PaymentDate = principleExchange.adjustedPrincipalExchangeDate;
                principalExchangeCashflowRangeItem.Amount      = (double)principleExchange.principalExchangeAmount;
                //principalExchangeCashflowRangeItem.PresentValueAmount = MoneyHelper.ToDouble(principleExchange.presentValuePrincipalExchangeAmount);
                //principalExchangeCashflowRangeItem.DiscountFactor = (double)principleExchange.discountFactor;
            }
            return(list);
        }
예제 #7
0
        public List <DetailedCashflowRangeItem> GetDetailedCashflowsWithNotionalSchedule(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            CapFloorLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            //Check if the calendars are null. If not build them!
            var list1 = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
            NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(list1);
            Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
            NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
            InterestRateStream        interestRateStream   = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);
            //Add the principal exchanges to the cashflows.
            var principalExchangeList = list1.Select(cashflow => new PrincipalExchange
            {
                adjustedPrincipalExchangeDate = cashflow.First, adjustedPrincipalExchangeDateSpecified = true, principalExchangeAmount = cashflow.Second, principalExchangeAmountSpecified = true
            }).ToArray();

            interestRateStream.cashflows.principalExchange = principalExchangeList;
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                detailedCashflowRangeItem.PaymentDate    = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate      = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate        = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.NumberOfDays   = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                detailedCashflowRangeItem.FutureValue    = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                detailedCashflowRangeItem.PresentValue   = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                CalculationPeriod      calculationPeriod      = PaymentCalculationPeriodHelper.GetCalculationPeriods(paymentCalculationPeriod)[0];
                FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod);
                switch (detailedCashflowRangeItem.CouponType.ToLower())
                {
                case "cap":
                {
                    Strike strike = floatingRateDefinition.capRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    break;
                }

                case "floor":
                {
                    Strike strike = floatingRateDefinition.floorRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    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);
                }
                }
                //  If  floating rate - retrieve the spread.
                //
                detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                var fixingDate = new DateTime();
                var tempDate   = PaymentCalculationPeriodHelper.GetFirstFloatingFixingDate(paymentCalculationPeriod);
                if (tempDate != null)
                {
                    fixingDate = (DateTime)tempDate;
                }
                detailedCashflowRangeItem.FixingDate = fixingDate;
                detailedCashflowRangeItem.Currency   = "Not Specified";
                if (currency != null)
                {
                    detailedCashflowRangeItem.Currency = currency.Value;
                }
                list.Add(detailedCashflowRangeItem);
            }
            return(list);
        }