public void TestGetCapPremiumAUD_6M100M_5YExpiry05Vol20Pct()
        {
            var valuationDate = new DateTime(1994, 12, 14);
            var curveId       = BuildAndCacheRateCurve(valuationDate);
            CapFloorLegParametersRange_Old capLeg = GetCapFloorInputParameters(valuationDate, valuationDate.AddMonths(6), valuationDate.AddYears(5),
                                                                               CapFloorType.Cap, "Standard", curveId, curveId);
            InterestRateStream floatStream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(capLeg);

            floatStream.cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(floatStream, FixingCalendar, PaymentCalendar);
            double sumOfCapletPremiums = 0;
            var    rateCurve           = (RateCurve)Engine.GetCurve(curveId, false);

            foreach (PaymentCalculationPeriod paymentCalculationPeriod in floatStream.cashflows.paymentCalculationPeriod)
            {
                DateTime startDate      = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                DateTime endDate        = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                double   accrualFactor  = (endDate - startDate).TotalDays / 365.0;
                var      discountFactor = (double)paymentCalculationPeriod.discountFactor;
                var      rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                double   rate2          = rateCurve.GetForwardRate(startDate, endDate, "ACT/365.FIXED");
                double   diff           = rate - rate2;
                Debug.Print("Diff in forward rate: {0}", diff);
                var          strikeRate   = (double)capLeg.StrikeRate; //fixed - replace with a schedule
                const double volatility   = 0.2;                       //fixed - replace with a schedule
                double       timeToExpiry = (startDate - valuationDate).TotalDays / 365.0;
                double       optionValue  = accrualFactor * BlackModel.GetSwaptionValue(rate, strikeRate, volatility, timeToExpiry) * discountFactor;
                Debug.Print("Expiry:\t{0},\tPremium:\t{1}'", timeToExpiry, optionValue);
                sumOfCapletPremiums += optionValue;
            }
            Debug.Print("Premium : '{0}'", sumOfCapletPremiums * (double)capLeg.NotionalAmount);
        }
Example #2
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);
        }
Example #3
0
        public static List <DetailedCashflowRangeItem> GetDetailedCashflowsTestOnly(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            ValuationRange valuationRange)
        {
            InterestRateStream interestRateStream = GetCashflowsSchedule(fixingCalendar, paymentCalendar, legParametersRange);

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

            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 a spread.
                //
                if (legParametersRange.IsFloatingLegType())
                {
                    detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                }
            }

            return(list);
        }
Example #4
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);
        }