/// <summary>
 /// Constructor for the class.
 /// </summary>
 /// <param name="expiry">Cap expiry.</param>
 /// <param name="volatility">Cap volatility.</param>
 /// <param name="volatilityType">Type of volatility: ETO or Cap/Floor.
 /// </param>
 public CapVolatilityDataElement(T expiry,
                                 decimal volatility,
                                 VolatilityDataType volatilityType)
 {
     // Map all arguments to the appropriate private field.
     Expiry         = expiry;
     Volatility     = volatility;
     VolatilityType = volatilityType;
 }
Example #2
0
        public void TestAccessorMethods()
        {
            // Instantiate the Cap Volatility Data element.
            _expiry         = 2;
            _volatility     = 0.096724m;
            _volatilityType = VolatilityDataType.CapFloor;

            CapVolatilityDataElement <int> capObj =
                new CapVolatilityDataElement <int>
                    (_expiry, _volatility, _volatilityType);

            Assert.IsNotNull(capObj);
            _actual   = capObj.Expiry;
            _expected = 2;
            Assert.AreEqual(_expected, _actual);
            Assert.IsTrue(capObj.VolatilityType == VolatilityDataType.CapFloor);
        }
Example #3
0
        public void TestCompareTo()
        {
            // Instantiate the container.
            List <CapVolatilityDataElement <int> > container =
                new List <CapVolatilityDataElement <int> >();

            // Add the first element to the container: ETO
            _expiry         = 182; // 6M ETO expiry
            _volatility     = 0.8820m;
            _volatilityType = VolatilityDataType.ETO;
            CapVolatilityDataElement <int> capObj1 =
                new CapVolatilityDataElement <int>
                    (_expiry, _volatility, _volatilityType);

            Assert.IsNotNull(capObj1);
            container.Add(capObj1);
            int count = 1;

            Assert.AreEqual(count, container.Count);

            // Add the second element to the container: CAP/FLOOR
            _expiry         = 1; // 1Y Cap/Floor expiry
            _volatilityType =
                VolatilityDataType.CapFloor;
            CapVolatilityDataElement <int> capObj2 =
                new CapVolatilityDataElement <int>
                    (_expiry, _volatility, _volatilityType);

            Assert.IsNotNull(capObj2);
            container.Add(capObj2);
            Assert.AreEqual(++count, container.Count);

            // Add the third element to the container: ETO
            _expiry         = 273; // 9M Cap/Floor expiry
            _volatilityType = VolatilityDataType.ETO;
            CapVolatilityDataElement <int> capObj3 =
                new CapVolatilityDataElement <int>
                    (_expiry, _volatility, _volatilityType);

            Assert.IsNotNull(capObj3);
            container.Add(capObj3);
            Assert.AreEqual(++count, container.Count);

            // Test that the container is sorted correctly.
            CapVolatilityDataElementComparer myComparer =
                new CapVolatilityDataElementComparer();

            container.Sort(myComparer);
            int numElements = container.Count;

            for (int i = 1; i < numElements; ++i)
            {
                AssertExtension.LessOrEqual((int)container[i - 1].VolatilityType,
                                            (int)container[i].VolatilityType);

                if (container[i - 1].VolatilityType == container[i].VolatilityType)
                {
                    AssertExtension.Less(container[i - 1].Expiry, container[i].Expiry);
                }
            }
        }