Esempio n. 1
0
        /// <summary>
        /// Get carry rate from forward factor.
        /// </summary>
        protected override void GetCarryRate(Vector b, Vector forwardFactor, double t, double tPay)
        {
            Double date    = fBaseDate + CalcUtils.YearsToDays(t);
            Double payDate = fBaseDate + CalcUtils.YearsToDays(tPay);

            b.Assign(VectorMath.Log(forwardFactor) / CalcUtils.DayCountFraction(date, payDate, DayCount.BUS_252, ((IDIOptionDeal)Deal).Calendar()));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the discount rate used in the option valuation formula.
        /// </summary>
        protected override void GetDiscountRate(Vector r, IInterestRate discountRate, double t, double tPay)
        {
            Double date    = fBaseDate + CalcUtils.YearsToDays(t);
            Double payDate = fBaseDate + CalcUtils.YearsToDays(tPay);

            r.Assign(VectorMath.Log(discountRate.Get(t, tPay)) / CalcUtils.DayCountFraction(payDate, date, DayCount.BUS_252, ((IDIOptionDeal)Deal).Calendar()));
        }
Esempio n. 3
0
        /// <summary>
        /// Prepare for valuation anything that will be shared between scenarios.
        /// </summary>
        public override void PreCloneInitialize(PriceFactorList factors, BaseTimeGrid baseTimes, RequiredResults requiredResults)
        {
            base.PreCloneInitialize(factors, baseTimes, requiredResults);

            FixedInterestCashflowDeal deal = (FixedInterestCashflowDeal)fDeal;

            int    sign = (deal.Buy_Sell == BuySell.Buy ? +1 : -1);
            double accrualDayCountFraction = CalcUtils.DayCountFraction(deal.Accrual_Start_Date, deal.Accrual_End_Date, deal.Accrual_Day_Count, deal.GetHolidayCalendar());

            fAmount = sign * deal.Notional * accrualDayCountFraction * deal.Fixed_Rate;
        }
Esempio n. 4
0
        /// <summary>
        /// Calculate the dates and years fractions not specified on the deal and get any known rates.
        /// </summary>
        public void Prepare(double baseDate, RateFixingsProvider rateFixings)
        {
            // Calculates various date properties of the deal and cache them.
            var deal             = (FloatingInterestCashflowInterpolatedDeal)Deal;
            var accrualCalendars = deal.GetAccrualHolidayCalendars();
            var rateCalendars    = deal.GetRateHolidayCalendars();

            fPaymentDate = deal.Payment_Date;

            if (deal.Accrual_Year_Fraction > 0.0)
            {
                fAccrualYearFraction = deal.Accrual_Year_Fraction;
            }
            else
            {
                fAccrualYearFraction = CalcUtils.DayCountFraction(deal.Accrual_Start_Date, deal.Accrual_End_Date, deal.Accrual_Day_Count, accrualCalendars);
            }

            fKnownResetRate1 = null;
            fKnownResetRate2 = null;

            if (deal.HasRate1())
            {
                if (deal.Rate_1_End_Date > 0.0)
                {
                    fRate1EndDate = deal.Rate_1_End_Date;
                }
                else
                {
                    fRate1EndDate = DateAdjuster.Add(deal.Rate_Start_Date, deal.Rate_1_Tenor, 1, rateCalendars, true, deal.Rate_Adjustment_Method, deal.Rate_Sticky_Month_End == YesNo.Yes).ToOADate();
                }

                if (deal.Rate_1_Year_Fraction > 0.0)
                {
                    fRate1YearFraction = deal.Rate_1_Year_Fraction;
                }
                else
                {
                    fRate1YearFraction = CalcUtils.DayCountFraction(deal.Rate_Start_Date, fRate1EndDate, deal.Rate_Day_Count, rateCalendars, deal.Rate_1_Tenor);
                }

                fKnownResetRate1 = GetKnownResetRate(baseDate, deal.Reset_Date, fPaymentDate, deal.Use_Known_Rate_1, deal.Known_Rate_1, deal.Rate_1_Fixing, rateFixings, deal);
            }

            if (deal.HasRate2())
            {
                if (deal.Rate_2_End_Date > 0.0)
                {
                    fRate2EndDate = deal.Rate_2_End_Date;
                }
                else
                {
                    fRate2EndDate = DateAdjuster.Add(deal.Rate_Start_Date, deal.Rate_2_Tenor, 1, rateCalendars, true, deal.Rate_Adjustment_Method, deal.Rate_Sticky_Month_End == YesNo.Yes).ToOADate();
                }

                if (deal.Rate_2_Year_Fraction > 0.0)
                {
                    fRate2YearFraction = deal.Rate_2_Year_Fraction;
                }
                else
                {
                    fRate2YearFraction = CalcUtils.DayCountFraction(deal.Rate_Start_Date, fRate2EndDate, deal.Rate_Day_Count, rateCalendars, deal.Rate_2_Tenor);
                }

                fKnownResetRate2 = GetKnownResetRate(baseDate, deal.Reset_Date, fPaymentDate, deal.Use_Known_Rate_2, deal.Known_Rate_2, deal.Rate_2_Fixing, rateFixings, deal);
            }
        }