public void TestTryParse_1y1m1q_Negative()
        {
            string tenor = "1y1m1q";
            bool   flag  = Tenor.TryParse(tenor, out Tenor res);

            Assert.IsFalse(flag);
        }
        public void TestTryParse_null_Negative()
        {
            string tenor = null;
            bool   flag  = Tenor.TryParse(tenor, out Tenor res);

            Assert.IsFalse(flag);
        }
        public void TestTryParse_1d1w1m1y_PositiveResult()
        {
            string tenor = "1d1w1m1y";
            bool   flag  = Tenor.TryParse(tenor, out Tenor res);

            Assert.AreEqual(1, res.Years);
            Assert.AreEqual(1, res.Months);
            Assert.AreEqual(1, res.Weeks);
            Assert.AreEqual(1, res.Days);
            Assert.IsTrue(flag);
        }
Esempio n. 4
0
        private static Sensitivity ReadSensitivityFx(EntryObject o)
        {
            if (!Enum.TryParse(o.ProductClass, out Model.Product product))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid ProductClass property.");
            }

            if (product != Model.Product.RatesFx)
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry associated to a product class other than {Model.Product.RatesFx}.");
            }

            Amount          amount          = ReadAmount(o);
            RegulationsInfo regulationsInfo = ReadRegulationsInfo(o);
            TradeInfo       tradeInfo       = ReadTradeInfo(o);

            if (o.RiskType == "Risk_FX")
            {
                if (!Currency.TryParse(o.Qualifier, out Currency currency))
                {
                    throw new InvalidDataException("The CRIF file contains a Risk_FX entry with an invalid Qualifier property.");
                }

                if (!String.IsNullOrEmpty(o.Bucket) || !String.IsNullOrEmpty(o.Label1) || !String.IsNullOrEmpty(o.Label2))
                {
                    throw new InvalidDataException("The CRIF file cannot specify Bucket, Label1 and Label2 properties for Risk_FX entries.");
                }

                return(Sensitivity.FxDelta(currency, amount, regulationsInfo, tradeInfo));
            }

            if (!CurrencyPair.TryParse(o.Qualifier, out CurrencyPair pair))
            {
                throw new InvalidDataException("The CRIF file contains a Risk_FXVol entry with an invalid Qualifier property.");
            }

            if (!Tenor.TryParse(o.Label1, out Tenor tenor))
            {
                throw new InvalidDataException("The CRIF file contains a Risk_FXVol entry with an invalid Label1 property.");
            }

            if (!String.IsNullOrEmpty(o.Bucket) || !String.IsNullOrEmpty(o.Label2))
            {
                throw new InvalidDataException("The CRIF file cannot specify the Label2 property for Risk_EquityVol entries.");
            }

            return(Sensitivity.FxVega(pair, tenor, amount, regulationsInfo, tradeInfo));
        }
Esempio n. 5
0
        private static Sensitivity ReadSensitivityEquity(EntryObject o)
        {
            if (!Enum.TryParse(o.ProductClass, out Model.Product product))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid ProductClass property.");
            }

            if (product != Model.Product.Equity)
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry associated to a product class other than {Model.Product.Equity}.");
            }

            if (!DataValidator.IsValidQualifier(o.Qualifier, false))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Qualifier property.");
            }

            if (!BucketEquity.TryParse(o.Bucket, out BucketEquity bucket))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Bucket property.");
            }

            Amount          amount          = ReadAmount(o);
            RegulationsInfo regulationsInfo = ReadRegulationsInfo(o);
            TradeInfo       tradeInfo       = ReadTradeInfo(o);

            if (o.RiskType == "Risk_Equity")
            {
                if (!String.IsNullOrEmpty(o.Label1) || !String.IsNullOrEmpty(o.Label2))
                {
                    throw new InvalidDataException("The CRIF file cannot specify Label1 and Label2 properties for Risk_Equity entries.");
                }

                return(Sensitivity.EquityDelta(o.Qualifier, bucket, amount, regulationsInfo, tradeInfo));
            }

            if (!Tenor.TryParse(o.Label1, out Tenor tenor))
            {
                throw new InvalidDataException("The CRIF file contains a Risk_EquityVol entry with an invalid Label1 property.");
            }

            if (!String.IsNullOrEmpty(o.Label2))
            {
                throw new InvalidDataException("The CRIF file cannot specify the Label2 property for Risk_EquityVol entries.");
            }

            return(Sensitivity.EquityVega(o.Qualifier, bucket, tenor, amount, regulationsInfo, tradeInfo));
        }
Esempio n. 6
0
        private static Sensitivity ParseSensitivityCreditNonQualifying(EntryObject o)
        {
            if (!Enum.TryParse(o.ProductClass, out Model.Product product))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid ProductClass property.");
            }

            if (product != Model.Product.Credit)
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry associated to a product class other than {Model.Product.Credit}.");
            }

            if (!BucketCreditNonQualifying.TryParse(o.Bucket, out BucketCreditNonQualifying bucket))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Bucket property.");
            }

            if (!Tenor.TryParse(o.Label1, out Tenor tenor))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Label1 property.");
            }

            if (!tenor.IsCreditTenor)
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry associated to an improper tenor (accepted tenors are: {String.Join(", ", Tenor.Values.Where(x => x.IsCreditTenor).Select(x => x.Name))}.");
            }

            if (!String.IsNullOrEmpty(o.Label2))
            {
                throw new InvalidDataException($"The CRIF file cannot specify the Label2 property for {o.RiskType} entries.");
            }

            Amount          amount          = ReadAmount(o);
            RegulationsInfo regulationsInfo = ReadRegulationsInfo(o);
            TradeInfo       tradeInfo       = ReadTradeInfo(o);

            if (o.RiskType == "Risk_CreditNonQ")
            {
                if (!DataValidator.IsValidQualifier(o.Qualifier, true))
                {
                    throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Qualifier property.");
                }

                return(Sensitivity.CreditNonQualifyingDelta(o.Qualifier, bucket, tenor, amount, regulationsInfo, tradeInfo));
            }

            return(Sensitivity.CreditNonQualifyingVega(o.Qualifier, bucket, tenor, amount, regulationsInfo, tradeInfo));
        }
Esempio n. 7
0
        private static Sensitivity ReadSensitivityInterestRate(EntryObject o)
        {
            if (!Enum.TryParse(o.ProductClass, out Model.Product product))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid ProductClass property.");
            }

            if (product != Model.Product.RatesFx)
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry associated to a product class other than {Model.Product.RatesFx}.");
            }

            if (!Currency.TryParse(o.Qualifier, out Currency currency))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Qualifier property.");
            }

            if (!Tenor.TryParse(o.Label1, out Tenor tenor))
            {
                throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with an invalid Label1 property.");
            }

            Amount          amount          = ReadAmount(o);
            RegulationsInfo regulationsInfo = ReadRegulationsInfo(o);
            TradeInfo       tradeInfo       = ReadTradeInfo(o);

            if (o.RiskType == "Risk_IRCurve")
            {
                if (String.IsNullOrEmpty(o.Bucket))
                {
                    throw new InvalidDataException("The CRIF file contains a Risk_IRCurve entry with an invalid Bucket property.");
                }

                String currencyVolatility = ((Int32)currency.Volatility + 1).ToString();

                if (o.Bucket != currencyVolatility)
                {
                    throw new InvalidDataException($"The CRIF file contains a Risk_IRCurve entry with mismatching currency volatility and volatility bucket (for {currency} the Bucket property must be set to {currencyVolatility}).");
                }

                o.Label2 = DataValidator.FormatLibor(o.Label2, true);

                if (!Enum.TryParse(o.Label2, out Curve curve))
                {
                    throw new InvalidDataException("The CRIF file contains a Risk_IRCurve entry with an invalid Label2 property.");
                }

                if ((currency != Currency.Usd) && ((curve == Curve.Municipal) || (curve == Curve.Prime)))
                {
                    throw new InvalidDataException($"The CRIF file contains a {o.RiskType} entry with a {curve} curve associated to a currency other than {Currency.Usd}.");
                }

                return(Sensitivity.InterestRateDelta(currency, tenor, curve, amount, regulationsInfo, tradeInfo));
            }

            if (!String.IsNullOrEmpty(o.Bucket) || !String.IsNullOrEmpty(o.Label2))
            {
                throw new InvalidDataException("The CRIF file cannot specify Bucket and Label2 properties for Risk_IRVol entries.");
            }

            return(Sensitivity.InterestRateVega(currency, tenor, amount, regulationsInfo, tradeInfo));
        }