예제 #1
0
        public void TestComputeForwardRate1()
        {
            // Set the number of forward rates to be computed in the test.
            int numForwardRates = _forwardRates.Length;

            // Set test accuracy level.
            _tolerance = 1.0E-4d;

            // Compute each forward rate and test against expected rates.
            for (int i = 1; i < numForwardRates; ++i)
            {
                _actual = (double)CapletBootstrapEngineHelper.ComputeForwardRate
                              ("ACT/365.FIXED",
                              _offsets.ToArray(),
                              _discountFactors,
                              _calculationDate,
                              _dates[i - 1],
                              _dates[i]);

                _expected = _forwardRates[i - 1];

                Assert.AreEqual(_expected,
                                _actual,
                                _tolerance);
            }
        }
예제 #2
0
        public void TestComputeDiscountFactorMethod()
        {
            // Initialise the array of offsets.
            List <double> offsets = new List <double>();

            foreach (DateTime date in _dates)
            {
                TimeSpan dateDiff = date - _calculationDate;
                offsets.Add(dateDiff.Days);
            }

            #region Test: End Date Coincides with the Calculation Date

            _endDate = _calculationDate;
            _actual  = (double)CapletBootstrapEngineHelper.ComputeDiscountFactor
                           (_settingsObj, offsets.ToArray(), _discountFactors, _endDate);
            _expected = 1.0d;

            Assert.AreEqual(_expected, _actual);

            #endregion

            #region Test: End Date Coincides with a Nodal Date

            int idx = 0;
            foreach (DateTime date in _dates)
            {
                _endDate = date;
                _actual  = (double)CapletBootstrapEngineHelper.ComputeDiscountFactor
                               (_settingsObj, offsets.ToArray(), _discountFactors, _endDate);
                _expected = _discountFactors[idx];

                Assert.AreEqual(_expected, _actual);
                ++idx;
            }

            #endregion

            #region Test: End Date not at a Nodal Date

            string dateString = "2010-07-21";
            _endDate = DateTime.Parse(dateString);
            _actual  = (double)CapletBootstrapEngineHelper.ComputeDiscountFactor
                           (_settingsObj, offsets.ToArray(), _discountFactors, _endDate);
            _expected = 0.82389d;
            Assert.AreEqual(_expected,
                            _actual,
                            _tolerance);

            #endregion
        }
예제 #3
0
        public void TestGenerateRollSchedule()
        {
            // Generate the roll schedule.
            CapletBootstrapEngineHelper.GenerateRollSchedule
                (_settingsObj, _numYears, out _rollSchedule);

            // Test date output.
            Assert.AreEqual(_dates.Length, _rollSchedule.Count);

            int idx = 0;

            foreach (DateTime date in _rollSchedule)
            {
                Assert.AreEqual(_dates[idx], date);
                ++idx;
            }
        }
예제 #4
0
        public void TestGenerateUSDCapRollSchedule()
        {
            // Construct the settings object: only change the parameters that
            // are particular to this test case.
            const string CalculationDateString = @"2008-05-14";
            const bool   ValidateArguments     = true;

            _calculationDate = DateTime.Parse(CalculationDateString);
            _capStartLag     = 2;
            _currency        = "USD";
            _numYears        = 20.0d;

            _settingsObj = new CapletBootstrapSettings
                               (_calculationDate,
                               _capFrequency,
                               _capStartLag,
                               _currency,
                               _handle,
                               _parVolatilityInterpolation,
                               _rollConvention,
                               ValidateArguments);
            Assert.IsNotNull(_settingsObj);

            // Generate the roll schedule.
            CapletBootstrapEngineHelper.GenerateRollSchedule
                (_settingsObj, _numYears, out _rollSchedule);

            // Check the first and last dates in the roll schedule.
            const string FirstDateInSchedule = "2008-08-18";
            const string LastDateInSchedule  = "2028-05-16";

            Assert.AreEqual
                (DateTime.Parse(FirstDateInSchedule), _rollSchedule[0]);
            Assert.AreEqual(DateTime.Parse(LastDateInSchedule),
                            _rollSchedule[_rollSchedule.Count - 1]);
        }