Esempio n. 1
0
        public void AutocallableCallDatesRipperWorks()
        {
            foreach (var testPair in _testFilePathAndExpectedCallDates)
            {
                string testFilePath = testPair.Key;
                string textToParse  = GeneralUtils.GetStringFromTextFile(testFilePath);
                _autocallableRipper = DealRipperFactory.GetAutocallableRipper(textToParse);
                DateTime [] expectedCallObservationDates = testPair.Value;
                DateTime [] rippedCallObservationDates   = _autocallableRipper.GetCallObservationDates();

                int    expectedDateCount = expectedCallObservationDates.Length;
                int    rippedDateCount   = rippedCallObservationDates.Length;
                string msgOnFailure      = string.Format("The expected number of call observations ({0}) " +
                                                         "doesn't match the ripped number of call " +
                                                         "observations ({1}) in following file path: " +
                                                         "{2}.",
                                                         expectedDateCount, rippedDateCount, testFilePath);

                Assert.AreEqual(expectedDateCount, rippedDateCount, msgOnFailure);

                for (int i = 0; i < expectedCallObservationDates.Length; i++)
                {
                    DateTime expectedDate = expectedCallObservationDates [i];
                    DateTime rippedDate   = rippedCallObservationDates [i];
                    msgOnFailure = string.Format("The call observation date we expected ({0}) " +
                                                 "is different than the call observation date we " +
                                                 "ripped ({1}) in the following file path: {2}.",
                                                 expectedDate, rippedDate, testFilePath);
                    Assert.AreEqual(expectedDate, rippedDate, msgOnFailure);
                }
            }
        }
Esempio n. 2
0
        protected virtual void parse(AutocallableContainer container, AutocallableRipper ripper)
        {
            base.parse(container, ripper);
            DateTime [] couponObservationDates;
            try
            {
                DateTime [] callObservationDates = ripper.GetCallObservationDates();
                container.CallObservationDates = callObservationDates;
                try
                {
                    couponObservationDates           = ripper.GetCouponObservationDates();
                    container.CouponObservationDates = couponObservationDates;
                }
                catch
                {
                    string warning = "Unable to extract coupon observation dates on their own so " +
                                     "assuming they are the same as the call observation dates.";
                    Debug.WriteLine(warning);
                    container.CouponObservationDates = callObservationDates;
                }
            }
            catch (DetailParsingException)
            {
                string warning = "Unable to extract call observation dates on their own so assuming " +
                                 "they are the same as the coupon observation dates.";
                Debug.WriteLine(warning);
                couponObservationDates           = ripper.GetCouponObservationDates();
                container.CouponObservationDates = couponObservationDates;
                container.CallObservationDates   = couponObservationDates;
            }
            container.CouponAmountPerPeriod = ripper.GetCouponPerPeriod();
            container.CouponBarrier         = ripper.GetCouponBarrier();
            double knockInBarrier = ripper.GetKnockInBarrier();

            // If the KI Barrier is less than one, it is likely that it represents a % amount.
            if (knockInBarrier < 1)
            {
                knockInBarrier = knockInBarrier * container.InitialUnderlyingLevel;
            }
            container.KnockInBarrier = knockInBarrier;
            // If we fail to rip the coupon frequency, we "swallow" the error because we can
            // ultimately determine it by the distance between coupon observation dates.
            try
            {
                if (ripper.CouponFrequency == null)
                {
                    container.CouponFrequency = ripper.GetCouponFrequency();
                }
                else
                {
                    container.CouponFrequency = ripper.CouponFrequency;
                }
            }
            catch (Exception) { }

            // If we failed to parse the Final Valuation Date on its own, then we set it equal to the last coupon
            // observation date
            if (container.FinalValuationDate.IsEmpty())
            {
                string warning = String.Format("Final Valuation Date empty in AutocallableFactory for " +
                                               "Cusip {0}. Therefore, assuming it is the final coupon " +
                                               "observation date.", container.Cusip);
                Debug.WriteLine(warning);
                container.FinalValuationDate = container.CouponObservationDates.Last();
            }
        }