Esempio n. 1
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);
        }
Esempio n. 2
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]);
                    }
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Computes the swap rate of a quarterly swap.
        /// </summary>
        /// <param name="expiry">Expiry time in quarters.</param>
        /// <param name="tenor">Length of the swap in quarters.</param>
        /// <param name="discount">Discount factors used.</param>
        /// <returns></returns>
        public static double SwapRate(int expiry, int tenor, QuarterlyDiscounts discount)
        {
            double numerator   = 0;
            double denominator = 0;

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

            return(rate);
        }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="paymentDate">Contract payment time, in quarters.</param>
 /// <param name="settleDate">Delivery time, in quarters.</param>
 /// <param name="discount">Discount factors used.</param>
 /// <returns></returns>
 public static double ForwardContract(int paymentDate, int settleDate, QuarterlyDiscounts discount)
 {
     return(discount.Get(settleDate) / discount.Get(paymentDate));
 }