Пример #1
0
 public void AutocallableCouponPerPeriodRipperWorks()
 {
     foreach (var testPair in _testFilePathAndExpectedCouponPerPeriod)
     {
         string             testFilePath   = testPair.Key;
         string             textToParse    = GeneralUtils.GetStringFromTextFile(testFilePath);
         AutocallableRipper ripper         = DealRipperFactory.GetAutocallableRipper(textToParse);
         double             expectedCoupon = testPair.Value;
         double             rippedCoupon   = (double)ripper.GetCouponPerPeriod();
         string             msgOnFailure   = string.Format("The coupon per period we expected ({0} doesn't " +
                                                           "match the ripped coupon per period ({1}) for " +
                                                           "the following file path: {2}.",
                                                           expectedCoupon, rippedCoupon, testFilePath);
         Assert.AreEqual(expectedCoupon, rippedCoupon, msgOnFailure);
     }
 }
Пример #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();
            }
        }