Example #1
0
        ///<summary>
        ///</summary>
        ///<param name="discount"></param>
        ///<param name="shift"></param>
        public void Populate(QuarterlyDiscounts discount, QuarterlyShifts shift)
        {
            var forward                      = new double[_maxTenor + 1];
            var accumForward                 = new double[_maxTenor + 1];
            var accumForwardTimesRate        = new double[_maxTenor + 1];
            var accumForwardTimesShiftedRate = new double[_maxTenor + 1];

            accumForward[0]                 = 0;
            accumForwardTimesRate[0]        = 0;
            accumForwardTimesShiftedRate[0] = 0;
            var w = new double[_maxTenor];
            var h = new double[_maxTenor];

            for (int i = 0; i < _maxExpiry; i++)
            {
                for (int j = 0; j < _maxTenor - i; j++)
                {
                    //See "Engineering BGM" page 34 for explicit formula. Function definitions can be found in chapter 4.
                    forward[j + 1]      = RateAnalytics.ForwardContract(i + 1, i + j + 2, discount);
                    accumForward[j + 1] = accumForward[j] + forward[j + 1];
                    accumForwardTimesRate[j + 1]
                        = accumForwardTimesRate[j] + forward[j + 1] * RateAnalytics.CashForwardRate(i + j + 1, discount);
                    accumForwardTimesShiftedRate[j + 1]
                         = accumForwardTimesShiftedRate[j] + forward[j + 1] * RateAnalytics.ShiftedCashForwardRate(i + j + 1, discount, shift);
                    h[j] = 0.25 * RateAnalytics.ShiftedCashForwardRate(i + j + 1, discount, shift) / (1 + 0.25 * RateAnalytics.CashForwardRate(i + j + 1, discount));
                    for (int k = 0; k < j + 1; k++)
                    {
                        w[k] = forward[k + 1] * RateAnalytics.ShiftedCashForwardRate(i + k + 1, discount, shift) / accumForwardTimesShiftedRate[j + 1];
                        _weights[i][j][k] = w[k] - h[k] * ((accumForwardTimesRate[j + 1] - accumForwardTimesRate[k]) / accumForwardTimesShiftedRate[j + 1]
                                                           - (1 - accumForward[k] / accumForward[j + 1]) * accumForwardTimesRate[j + 1] / accumForwardTimesShiftedRate[j + 1]);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// The "shift" of the swap rate, or shifted swap rate - actual swap rate.
        /// </summary>
        /// <param name="expiry"></param>
        /// <param name="tenor"></param>
        /// <param name="discount"></param>
        /// <param name="shift"></param>
        /// <returns></returns>
        public static double SwapShift(int expiry, int tenor, QuarterlyDiscounts discount, QuarterlyShifts shift)
        {
            double numerator   = 0;
            double denominator = 0;

            for (int i = 0; i < tenor; i++)
            {
                double forward = ForwardContract(expiry, expiry + i + 1, discount);
                numerator   += forward * shift.Get(expiry + i);
                denominator += forward;
            }
            return(numerator / denominator);
        }
Example #3
0
        /// <summary>
        /// Computes the shifted quarterly cash forward rate for a specific future time.
        /// </summary>
        /// <param name="forwardDate"></param>
        /// <param name="discount">Discount factors used.</param>
        /// <param name="shift">Shifts used.</param>
        /// <returns></returns>
        public static double ShiftedCashForwardRate(int forwardDate, QuarterlyDiscounts discount, QuarterlyShifts shift)
        {
            double rate = 4 * (discount.Get(forwardDate) / discount.Get(forwardDate + 1) - 1);

            rate += shift.Get(forwardDate);
            return(rate);
        }