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
        public new virtual StepDownAutocallableContainer GetDealContainer(AutocallableRipper ripper)
        {
            StepDownAutocallableContainer container = new StepDownAutocallableContainer();

            parse(container, ripper);
            return(container);
        }
Esempio n. 3
0
        public virtual AutocallableContainer GetDealContainer(AutocallableRipper ripper)
        {
            AutocallableContainer container = new AutocallableContainer();

            parse(container, ripper);
            return(container);
        }
Esempio n. 4
0
        public static AutocallableRipper GetAutocallableRipper(string textToParse)
        {
            AutocallableRipper ripper = new AutocallableRipper {
                TextToParse = textToParse
            };

            addBasicDetailRippersToDealRipper(ripper);
            addAutocallableDetailRippersToDealRipper(ripper);
            return(ripper);
        }
Esempio n. 5
0
 public void AutocallableKnockInBarrierRipperWorks()
 {
     foreach (var testPair in _testFilePathAndKnockInBarrierDictionary)
     {
         string             testFilePath           = testPair.Key;
         string             textToParse            = GeneralUtils.GetStringFromTextFile(testFilePath);
         AutocallableRipper ripper                 = DealRipperFactory.GetAutocallableRipper(textToParse);
         double             expectedKnockInBarrier = testPair.Value;
         double             rippedKnockInBarrier   = ripper.GetKnockInBarrier();
         Assert.AreEqual(expectedKnockInBarrier, rippedKnockInBarrier);
     }
 }
Esempio n. 6
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);
     }
 }
Esempio n. 7
0
 private static void addAutocallableDetailRippersToDealRipper(AutocallableRipper ripper)
 {
     try
     {
         ripper.CouponBarrierRipper = DetailRipperFactory.GetNumberRipper(
             EDetailRipperType.CouponBarrier);
         ripper.KnockInBarrierRipper = DetailRipperFactory.GetNumberRipper(
             EDetailRipperType.KnockInBarrier);
         ripper.CouponAmountRipper = (CouponRipper)DetailRipperFactory.GetNumberRipper(
             EDetailRipperType.CouponAmount);
         ripper.CouponFrequencyRipper = DetailRipperFactory.GetStringRipper(
             EDetailRipperType.CouponFrequency);
         ripper.CallObservationDatesRipper = DetailRipperFactory.GetDateArrayRipper(
             EDetailRipperType.CallObservationDates);
         ripper.CouponObservationDatesRipper = DetailRipperFactory.GetDateArrayRipper(
             EDetailRipperType.CouponObservationDates);
     }
     catch (Exception e)
     {
         throw new DealRipperFactoryException("addAutocallableDetailRippersToDealRipper() " +
                                              "encountered exception in DealRipperFactory class.",
                                              e);
     }
 }
Esempio n. 8
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();
            }
        }
        /// <summary>
        /// Define the sql queries that will update our database for a given structure by
        /// (1) Instantiating both the appropriate Factory and DealRipper that can be used to fill a container
        /// that will be passed to the SqlQueryFactory class.
        /// (2) Calling the GetSqlQueriesForAddingDealToDatabase() method of SqlQueryFactory in order to get the sql
        /// queries.
        /// </summary>
        private string [] getSqlQueriesToAddDealToDatabase(EStructure structureType)
        {
            ISqlQueryGenerator sqlQueryGenerator;

            switch (structureType)
            {
            case EStructure.PrincipalProtectedNote:
                PrincipalProtectedNoteRipper    ppnRipper    = DealRipperFactory.GetPrincipalProtectedNoteRipper(_termSheetText);
                PrincipalProtectedNoteFactory   ppnFactory   = new PrincipalProtectedNoteFactory();
                PrincipalProtectedNoteContainer ppnContainer = ppnFactory.GetDealContainer(ppnRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(ppnContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.StandardPLUS:
                PLUSRipper    plusRipper    = DealRipperFactory.GetPLUSRipper(_termSheetText);
                PLUSFactory   plusFactory   = new PLUSFactory();
                PLUSContainer plusContainer = plusFactory.GetDealContainer(plusRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(plusContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.BufferedPLUS:
                BufferedPLUSRipper    bufferedPLUSRipper    = DealRipperFactory.GetBufferedPLUSRipper(_termSheetText);
                BufferedPLUSFactory   bufferedPLUSFactory   = new BufferedPLUSFactory();
                BufferedPLUSContainer bufferedPLUSContainer = bufferedPLUSFactory.GetDealContainer(bufferedPLUSRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(bufferedPLUSContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.TriggerPLUS:
                TriggerPLUSRipper    triggerPLUSRipper    = DealRipperFactory.GetTriggerPLUSRipper(_termSheetText);
                TriggerPLUSFactory   triggerPLUSFactory   = new TriggerPLUSFactory();
                TriggerPLUSContainer triggerPLUSContainer = triggerPLUSFactory.GetDealContainer(triggerPLUSRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(triggerPLUSContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.DualDirectionalTriggerPLUS:
                TriggerPLUSRipper dualDirectionalTriggerPLUSRipper = DealRipperFactory.GetTriggerPLUSRipper(_termSheetText);
                DualDirectionalTriggerPLUSFactory dualDirectionalTriggerPLUSFactory = new DualDirectionalTriggerPLUSFactory();
                TriggerPLUSContainer dualDirectionalTriggerPLUSContainer            = dualDirectionalTriggerPLUSFactory.GetDealContainer(dualDirectionalTriggerPLUSRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(dualDirectionalTriggerPLUSContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.StandardJump:
                JumpRipper    jumpRipper    = DealRipperFactory.GetStandardJumpRipper(_termSheetText);
                JumpFactory   jumpFactory   = new JumpFactory();
                JumpContainer jumpContainer = jumpFactory.GetDealContainer(jumpRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(jumpContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.BufferedJump:
                BufferedJumpRipper    bufferedJumpRipper    = DealRipperFactory.GetBufferedJumpRipper(_termSheetText);
                BufferedJumpFactory   bufferedJumpFactory   = new BufferedJumpFactory();
                BufferedJumpContainer bufferedJumpContainer = bufferedJumpFactory.GetDealContainer(bufferedJumpRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(bufferedJumpContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.TriggerJump:
                TriggerJumpRipper    triggerJumpRipper    = DealRipperFactory.GetTriggerJumpRipper(_termSheetText);
                TriggerJumpFactory   triggerJumpFactory   = new TriggerJumpFactory();
                TriggerJumpContainer triggerJumpContainer = triggerJumpFactory.GetDealContainer(triggerJumpRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(triggerJumpContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.EnhancedTriggerJump:
                TriggerJumpRipper            enhancedTriggerJumpRipper    = DealRipperFactory.GetTriggerJumpRipper(_termSheetText);
                EnhancedTriggerJumpFactory   enhancedTriggerJumpFactory   = new EnhancedTriggerJumpFactory();
                EnhancedTriggerJumpContainer enhancedTriggerJumpContainer = enhancedTriggerJumpFactory.GetDealContainer(enhancedTriggerJumpRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(enhancedTriggerJumpContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.DualDirectionalTriggerJump:
                TriggerJumpRipper dualDirectionalTriggerJumpRipper = DealRipperFactory.GetTriggerJumpRipper(_termSheetText);
                DualDirectionalTriggerJumpFactory dualDirectionalTriggerJumpFactory = new DualDirectionalTriggerJumpFactory();
                TriggerJumpContainer dualDirectionalTriggerJumpContainer            = dualDirectionalTriggerJumpFactory.GetDealContainer(dualDirectionalTriggerJumpRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(dualDirectionalTriggerJumpContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.AutocallableStandard:
                AutocallableRipper    autocallableRipper    = DealRipperFactory.GetAutocallableRipper(_termSheetText);
                AutocallableFactory   autocallableFactory   = new AutocallableFactory();
                AutocallableContainer autocallableContainer = autocallableFactory.GetDealContainer(autocallableRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(autocallableContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.AutocallableFixedCoupon:
                FixedCouponAutocallableRipper fixedCouponAutocallableRipper    = DealRipperFactory.GetFixedCouponAutocallableRipper(_termSheetText);
                AutocallableFactory           fixedCouponAutocallableFactory   = new AutocallableFactory();
                AutocallableContainer         fixedCouponAutocallableContainer = fixedCouponAutocallableFactory.GetDealContainer(fixedCouponAutocallableRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(fixedCouponAutocallableContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.AutocallableStepUp:
                AutocallableRipper          stepUpAutocallableRipper    = DealRipperFactory.GetAutocallableRipper(_termSheetText);
                StepUpAutocallableFactory   stepUpAutocallableFactory   = new StepUpAutocallableFactory();
                StepUpAutocallableContainer stepUpAutocallableContainer = stepUpAutocallableFactory.GetDealContainer(stepUpAutocallableRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(stepUpAutocallableContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.AutocallableStepDown:
                AutocallableRipper            stepDownAutocallableRipper    = DealRipperFactory.GetAutocallableRipper(_termSheetText);
                StepDownAutocallableFactory   stepDownAutocallableFactory   = new StepDownAutocallableFactory();
                StepDownAutocallableContainer stepDownAutocallableContainer = stepDownAutocallableFactory.GetDealContainer(stepDownAutocallableRipper);
                sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(stepDownAutocallableContainer);
                return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase());

            case EStructure.AutocallableWorstOf:
                string wOfErrorMsg = "defineSqlQueriesToAddDealToDatabase() method of CentralCommand unable to handle Worst-of Autocallables.";
                Debug.WriteLine(wOfErrorMsg);
                throw new ArgumentOutOfRangeException(wOfErrorMsg);

            default:
                throw new ArgumentOutOfRangeException("Unhandled structure type passed to defineSqlQueriesToAddDealToDatabase() method of CentralCommand.");
            }
        }