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);
        }
Exemple #2
0
        private static InterestRateStream GetCashflowsSchedule(IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                                                               CapFloorLegParametersRange legParametersRange)
        {
            InterestRateStream stream    = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange);
            Cashflows          cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar);

            stream.cashflows = cashflows;
            return(stream);
        }
        public static InterestRateStream GetCashflowsSchedule(SwapLegParametersRange legParametersRange)
        {
            InterestRateStream stream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange);

            Cashflows cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream);

            stream.cashflows = cashflows;

            return(stream);
        }
        private static InterestRateStream GetCashflowsScheduleWithNotionalSchedule(
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            NonNegativeAmountSchedule notionalSchedule)
        {
            InterestRateStream stream = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange);

            InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(stream, notionalSchedule);
            Cashflows cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar);

            stream.cashflows = cashflows;
            return(stream);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="leg1Parameters"></param>
        /// <param name="leg1PaymentCalendar"> </param>
        /// <param name="capStrikeSchedule"></param>
        /// <param name="floorStrikeSchedule"> </param>
        /// <param name="spreadSchedule"></param>
        /// <param name="notionalSchedule"></param>
        /// <param name="leg1FixingCalendar"> </param>
        /// <returns></returns>
        public static Trade CreateTrade(CapFloorLegParametersRange leg1Parameters,
                                        IBusinessCalendar leg1FixingCalendar,
                                        IBusinessCalendar leg1PaymentCalendar,
                                        Schedule capStrikeSchedule,
                                        Schedule floorStrikeSchedule,
                                        Schedule spreadSchedule,
                                        NonNegativeAmountSchedule notionalSchedule)
        {
            var stream1 = GetCashflowsSchedule(leg1FixingCalendar, leg1PaymentCalendar, leg1Parameters);

            if (null != capStrikeSchedule && null != floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetCapRateSchedule(stream1, capStrikeSchedule, true);
                InterestRateStreamParametricDefinitionGenerator.SetFloorRateSchedule(stream1, floorStrikeSchedule, false);
            }
            if (null != capStrikeSchedule && null == floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetCapRateSchedule(stream1, capStrikeSchedule, true);
            }
            if (null == capStrikeSchedule && null != floorStrikeSchedule)
            {
                InterestRateStreamParametricDefinitionGenerator.SetFloorRateSchedule(stream1, floorStrikeSchedule, true);
            }
            if (null != spreadSchedule) //for float legs only
            {
                InterestRateStreamParametricDefinitionGenerator.SetSpreadSchedule(stream1, spreadSchedule);
            }
            if (null != notionalSchedule)
            {
                //  Set notional schedule
                //
                InterestRateStreamParametricDefinitionGenerator.SetNotionalSchedule(stream1, notionalSchedule);
            }
            var capFloor = CapFloorFactory.Create(stream1);
            var trade    = new Trade();

            XsdClassesFieldResolver.TradeSetCapFloor(trade, capFloor);
            return(trade);
        }