Example #1
0
        /// <summary>
        /// Prepare for valuation.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);

            SetModelParameters(fItems);

            PreValueDeals(fItems, factors);

            CallableStructuredDeal deal = (CallableStructuredDeal)Deal;

            // Set volatility price factors if they have been registered by model or underlying deals
            InterestVol.TryGet <IInterestRateVol>(factors, deal.Forecast_Rate_Cap_Volatility, fForecastCurrency, out fInterestRateVol);
            InterestVol.TryGet <IInterestYieldVol>(factors, deal.Forecast_Rate_Swaption_Volatility, fForecastCurrency, out fInterestYieldVol);

            bool needRating   = Respect_Default == YesNo.Yes && !string.IsNullOrEmpty(deal.Issuer);
            bool needSurvival = Use_Survival_Probability == YesNo.Yes && !string.IsNullOrEmpty(deal.Issuer);

            if (needRating)
            {
                fCreditRating = factors.Get <CreditRating>(deal.Issuer);
                fRecoveryRate = factors.Get <RecoveryRate>(InterestRateUtils.GetRateId(deal.Recovery_Rate, deal.Issuer));
            }

            if (needSurvival)
            {
                fSurvivalProb = factors.GetInterface <ISurvivalProb>(string.IsNullOrEmpty(deal.Survival_Probability) ? deal.Issuer : deal.Survival_Probability);
            }
        }
Example #2
0
        /// <summary>
        /// Prepare for valuation anything that is dependent upon the scenario.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);
            BondFutureOption deal = (BondFutureOption)Deal;

            fInterestYieldVol = InterestVolBase.GetYieldVol(factors, deal.Yield_Volatility, fCurrency);

            var bfb = (BondFuturesBasis)fFuturesBasis;

            GenerateCTD(factors.BaseDate, bfb.CTD_Issue_Date, bfb.CTD_Maturity_Date, bfb.CTD_Coupon_Interval, bfb.CTD_First_Coupon_Date, bfb.CTD_Penultimate_Coupon_Date, bfb.CTD_Day_Count, Deal.GetHolidayCalendar(), bfb.CTD_Coupon_Rate, bfb.CTD_Conversion_Factor);

            if (NeedRating(Respect_Default, deal.Issuer))
            {
                fCreditRating = factors.Get <CreditRating>(deal.Issuer);
                fRecoveryRate = factors.Get <RecoveryRate>(InterestRateUtils.GetRateId(deal.Recovery_Rate, deal.Issuer));
            }
            else
            {
                fCreditRating = null;
                fRecoveryRate = null;
            }

            if (NeedSurvivalProbability(Use_Survival_Probability, deal.Issuer))
            {
                fSurvivalProb = factors.GetInterface <ISurvivalProb>(InterestRateUtils.GetRateId(deal.Survival_Probability, deal.Issuer));
            }
            else
            {
                fSurvivalProb = null;
            }
        }
Example #3
0
        /// <summary>
        /// Get price factors.
        /// </summary>
        private void PreValue(PriceFactorList factors)
        {
            var deal = (CalendarSpreadOption)Deal;

            // Get forward price samples.
            fForwardSample = factors.Get <ForwardPriceSample>(deal.Sampling_Type);

            // Get ReferencePrice price factors.
            fReferencePrice1 = factors.GetInterface <IReferencePrice>(deal.Reference_Type);
            fReferencePrice2 = factors.GetInterface <IReferencePrice>(deal.Reference_Type);

            // Get ReferenceVol price factors.
            // Default to Reference Type if Reference Vol Type is not set.
            if (string.IsNullOrEmpty(deal.Reference_Vol_Type))
            {
                fReferenceVol1 = factors.Get <ReferenceVol>(deal.Reference_Type);
                fReferenceVol2 = factors.Get <ReferenceVol>(deal.Reference_Type);
            }
            else
            {
                fReferenceVol1 = factors.Get <ReferenceVol>(deal.Reference_Vol_Type);
                fReferenceVol2 = factors.Get <ReferenceVol>(deal.Reference_Vol_Type);
            }

            // Get correlation price factor based on the ID of the forward price.
            fCorrelations = factors.Get <ForwardPriceCorrelations>(fReferencePrice1.GetForwardPrice());

            // Get FX rate price factors.
            fFxRate            = factors.GetInterface <IFxRate>(deal.Currency);
            fFxPayoffRate      = factors.GetInterface <IFxRate>(deal.DealCurrency());
            fPriceFactorFxRate = factors.GetInterface <IFxRate>(fReferencePrice1.DomesticCurrency());

            // Get discount rate price factor.
            fDiscountRate = factors.GetInterface <IInterestRate>(InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency));
        }
Example #4
0
 /// <summary>
 /// Register price factors.
 /// </summary>
 public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
 {
     factors.Register <DiscountRate>(InterestRateUtils.GetRateId(fDeal.Discount_Rate, fDeal.Currency));
     factors.RegisterInterface <IFxRate>(fDeal.Currency);
     factors.RegisterInterface <IExpectedLoss>(fDeal.Reference_Index);
     factors.RegisterInterface <IRealizedLoss>(fDeal.Reference_Index);
 }
Example #5
0
        /// <summary>
        /// Register price factors used in valuation.
        /// </summary>
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            base.RegisterFactors(factors, errors);

            if (!string.IsNullOrEmpty(fForecastCurrency) && fForecastCurrency != fCurrency)
            {
                errors.Add(ErrorLevel.Error, "Settlement currency (Currency) and currency of Forecast_Rate must be the same");
            }

            SetModelParameters(fItems);
            ValidateModels(fItems, errors);

            fItems.RegisterFactors(factors, errors);

            CallableStructuredDeal deal = (CallableStructuredDeal)fDeal;

            bool needRating   = Respect_Default == YesNo.Yes && !string.IsNullOrEmpty(deal.Issuer);
            bool needSurvival = Use_Survival_Probability == YesNo.Yes && !string.IsNullOrEmpty(deal.Issuer);

            if (needRating)
            {
                factors.Register <CreditRating>(deal.Issuer);
                factors.Register <RecoveryRate>(InterestRateUtils.GetRateId(deal.Recovery_Rate, deal.Issuer));
            }

            if (needSurvival)
            {
                factors.RegisterInterface <ISurvivalProb>(string.IsNullOrEmpty(deal.Survival_Probability) ? deal.Issuer : deal.Survival_Probability);
            }
        }
Example #6
0
        /// <summary>
        /// Register price factors.
        /// </summary>
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            var deal = (SwaptionDeal)Deal;

            // Get underlying cashflow lists
            SwaptionBaseValuation.SetCashflowLists(errors, deal, ref fFixedCashflowList, ref fFloatCashflowList);

            if (!IsVanillaSwaption())
            {
                Deal.AddToErrors(errors, ErrorLevel.Error, "The Hull White swaption valuation model is for vanilla swaptions only.");
            }

            // Register deal currency
            factors.RegisterInterface <IFxRate>(deal.Currency);

            // Register discount rate
            var    discountId           = InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency);
            string discountRateCurrency = DiscountRate.Register(factors, discountId).GetCurrency();

            if (!string.IsNullOrEmpty(discountRateCurrency) && discountRateCurrency != deal.Currency)
            {
                errors.Add(ErrorLevel.Error, "Settlement currency (Currency) and currency of Discount_Rate must be the same");
            }

            // Register forecast rate
            var forecastId           = InterestRateUtils.GetRateId(deal.Forecast_Rate, discountId);
            var forecastRateCurrency = factors.RegisterInterface <IInterestRate>(forecastId).GetCurrency();

            if (forecastRateCurrency != deal.Currency)
            {
                errors.Add(ErrorLevel.Error, "Settlement currency (Currency) and currency of Forecast_Rate must be the same");
            }

            // Register the HW model parameters
            fModelParametersId = string.IsNullOrWhiteSpace(Model_Parameters) ? forecastId : Model_Parameters;

            factors.Register <HullWhite1FactorModelParameters>(fModelParametersId);

            // Check that floating cashflow list is standard enough to be valued by ValueSwap
            if (fFloatCashflowList == null || fFixedCashflowList == null)
            {
                errors.Add(ErrorLevel.Error, "Deal must contain exactly one floating and one fixed leg.");
            }
            else
            {
                var characteristics = fFloatCashflowList.Analyze(factors.BaseDate);
                if (!characteristics.HasSwaplet || characteristics.HasOptionlet ||
                    !characteristics.IsStandardPayoff || characteristics.HasCms || !characteristics.IsStandardLibor ||
                    fFloatCashflowList.Compounding_Method != CompoundingMethod.None || fFixedCashflowList.Compounding == YesNo.Yes)
                {
                    errors.Add(ErrorLevel.Error, "Underlying swap has non-standard floating cashflows.");
                }
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public CreditValuationParameters(DealCreditBase deal, CreditBaseValuation valuation, PriceFactorList factors, VectorScopedCache.Scope cache)
        {
            DF          = DiscountRate.Get(factors, InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency));
            X           = factors.GetInterface <IFxRate>(deal.Currency);
            SP          = factors.GetInterface <ISurvivalProb>(string.IsNullOrEmpty(deal.Survival_Probability) ? deal.Name : deal.Survival_Probability);
            RR          = null;
            CR          = null;
            DefaultTime = null;
            Weights     = null;
            NamesDefaultedBeforeBaseDate = null;

            if (valuation.Respect_Default == YesNo.Yes)
            {
                List <string> names = new List <string>();
                if (deal.ProtectionReferenceType() == DealCreditBase.ReferenceType.Single_Name)
                {
                    names.Add(deal.Name);
                    Weights = new double[] { 1.0 };
                }
                else
                {
                    IndexCDSPool indexCds = factors.Get <IndexCDSPool>(deal.Name);
                    Weights = new double[indexCds.Names.Count];
                    for (int i = 0; i < indexCds.Names.Count; ++i)
                    {
                        names.Add(indexCds.Names[i].Name);
                        Weights[i] = indexCds.Names[i].Weight;
                    }
                }

                if (valuation.RequiresRecoveryOnDefault())
                {
                    RR = new RecoveryRate[names.Count];
                    for (int i = 0; i < names.Count; ++i)
                    {
                        RR[i] = factors.Get <RecoveryRate>(string.IsNullOrEmpty(deal.Recovery_Rate) ? names[i] : deal.Recovery_Rate);
                    }
                }

                CR = new CreditRating[names.Count];
                NamesDefaultedBeforeBaseDate = new bool[names.Count];
                DefaultTime = new Vector[names.Count];
                for (int i = 0; i < names.Count; ++i)
                {
                    DefaultTime[i] = cache.Get();
                    CR[i]          = factors.Get <CreditRating>(names[i]);
                    NamesDefaultedBeforeBaseDate[i] = CreditRating.DefaultedBeforeBaseDate(CR[i], factors.BaseDate);
                    CR[i].DefaultTime(DefaultTime[i]);
                }
            }
        }
Example #8
0
        /// <inheritdoc />
        public void PreValue(PriceFactorList factors)
        {
            var deal = (SwaptionDeal)Deal;

            var discountId = InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency);
            var forecastId = InterestRateUtils.GetRateId(deal.Forecast_Rate, discountId);

            fModelParameters = factors.Get <HullWhite1FactorModelParameters>(fModelParametersId);

            fFxRate       = factors.GetInterface <IFxRate>(deal.Currency);
            fDiscountRate = DiscountRate.Get(factors, discountId);
            fForecastRate = factors.GetInterface <IInterestRate>(forecastId);

            fQuadrature = new Lazy <GaussHermiteNormalQuadrature>(() => new GaussHermiteNormalQuadrature(30));
        }
Example #9
0
        /// <summary>
        /// Register price factors.
        /// </summary>
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            BondFuture deal = (BondFuture)Deal;

            base.RegisterFactors(factors, errors);

            if (NeedRating(Respect_Default, deal.Issuer))
            {
                factors.Register <CreditRating>(deal.Issuer);

                // register realized recovery rate.
                factors.Register <RecoveryRate>(InterestRateUtils.GetRateId(deal.Recovery_Rate, deal.Issuer));
            }

            if (NeedSurvivalProbability(Use_Survival_Probability, deal.Issuer))
            {
                factors.RegisterInterface <ISurvivalProb>(InterestRateUtils.GetRateId(deal.Survival_Probability, deal.Issuer));
            }
        }
        // -----------------------------------------------------------------------------
        // Description: Register price factors
        // -----------------------------------------------------------------------------
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            factors.Register <DiscountRate>(InterestRateUtils.GetRateId(fCreditBaseDeal.Discount_Rate, fCreditBaseDeal.Currency));
            factors.RegisterInterface <IFxRate>(fCreditBaseDeal.Currency);
            factors.RegisterInterface <ISurvivalProb>(string.IsNullOrEmpty(fCreditBaseDeal.Survival_Probability) ? fCreditBaseDeal.Name : fCreditBaseDeal.Survival_Probability);

            if (Respect_Default == YesNo.Yes)
            {
                if (fCreditBaseDeal.ProtectionReferenceType() == DealCreditBase.ReferenceType.Single_Name)
                {
                    factors.Register <CreditRating>(fCreditBaseDeal.Name);
                    if (RequiresRecoveryOnDefault())
                    {
                        factors.Register <RecoveryRate>(string.IsNullOrEmpty(fCreditBaseDeal.Recovery_Rate) ? fCreditBaseDeal.Name : fCreditBaseDeal.Recovery_Rate);
                    }
                }
                else
                {
                    factors.Register <IndexCDSPool>(fCreditBaseDeal.Name);
                }
            }
        }
        /// <summary>
        /// Prepare for valuation anything that is dependent upon the scenario.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);

            CFListBaseDeal <TCashflowList> deal = (CFListBaseDeal <TCashflowList>)fDeal;

            if (string.IsNullOrEmpty(fDeal.GetIssuer()))
            {
                return;
            }

            if (UseSurvivalProbability())
            {
                fSurvivalProb = factors.GetInterface <ISurvivalProb>(string.IsNullOrEmpty(deal.GetSurvivalProbability()) ? deal.GetIssuer() : deal.GetSurvivalProbability());
            }

            if (RespectDefault())
            {
                fRecoveryRate = factors.Get <RecoveryRate>(InterestRateUtils.GetRateId(deal.GetRecoveryRate(), deal.GetIssuer()));
                fCreditRating = factors.Get <CreditRating>(deal.GetIssuer());
            }
        }
        /// <summary>
        /// Register price factors.
        /// </summary>
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            base.RegisterFactors(factors, errors);

            CFListBaseDeal <TCashflowList> deal = (CFListBaseDeal <TCashflowList>)fDeal;

            if (string.IsNullOrEmpty(fDeal.GetIssuer()))
            {
                return;
            }

            if (UseSurvivalProbability())
            {
                factors.RegisterInterface <ISurvivalProb>(string.IsNullOrEmpty(deal.GetSurvivalProbability()) ? deal.GetIssuer() : deal.GetSurvivalProbability());
            }

            if (RespectDefault())
            {
                factors.Register <RecoveryRate>(InterestRateUtils.GetRateId(deal.GetRecoveryRate(), deal.GetIssuer()));
                factors.Register <CreditRating>(deal.GetIssuer());
            }

            fSettlementOffsetHelper.ValidateHolidayCalendars(factors.CalendarData, errors);
        }
Example #13
0
        /// <summary>
        /// Register required price factors.
        /// </summary>
        public override void RegisterFactors(PriceFactorList factors, ErrorList errors)
        {
            var deal = (CalendarSpreadOption)Deal;

            // Register forward price factor - using a reference price.
            var referencePrice = factors.RegisterInterface <IReferencePrice>(deal.Reference_Type);

            // Register volatility price factor based on an explicit user-defined property.
            // Default to Reference Type if Reference Vol Type is not set.
            if (string.IsNullOrEmpty(deal.Reference_Vol_Type))
            {
                factors.Register <ReferenceVol>(deal.Reference_Type);
            }
            else
            {
                factors.Register <ReferenceVol>(deal.Reference_Vol_Type);
            }

            // Register FX rate price factors.
            factors.RegisterInterface <IFxRate>(deal.Currency);
            factors.RegisterInterface <IFxRate>(deal.DealCurrency());
            factors.RegisterInterface <IFxRate>(factors.BaseCcyCode);
            factors.RegisterInterface <IFxRate>(referencePrice.DomesticCurrency());

            // Register correlation price factor.
            factors.Register <ForwardPriceCorrelations>(referencePrice.GetForwardPrice());

            // Register forward price sample price factor for reference prices.
            var sample = factors.Register <ForwardPriceSample>(deal.Sampling_Type);

            if (!string.IsNullOrWhiteSpace(sample.Sampling_Convention))
            {
                sample.Prepare();

                // Validate period 1.
                IEnumerable <ContractPeriod> contractPeriods = deal.GetContractPeriods(deal.Period_Start_1, deal.Period_End_1);
                sample.ValidateRange(contractPeriods, "Set 1 of sample dates", deal, errors);

                // Validate period 2.
                contractPeriods = deal.GetContractPeriods(deal.Period_Start_2, deal.Period_End_2);
                sample.ValidateRange(contractPeriods, "Set 2 of sample dates", deal, errors);
            }

            // Register interest rate price factor to get discount factor.
            factors.RegisterInterface <IInterestRate>(deal.Currency);

            // Register interest rate price factor for discount rate currency.
            if (!string.IsNullOrEmpty(deal.Discount_Rate))
            {
                string discountRateCurrency = factors.RegisterInterface <IInterestRate>(InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency)).GetCurrency();
                if (!string.IsNullOrEmpty(discountRateCurrency) && discountRateCurrency != deal.Currency)
                {
                    errors.Add(ErrorLevel.Error, "Currency and currency of Discount_Rate must be the same");
                }
            }
        }
Example #14
0
 protected CDOValuationParameters(DealCDO deal, PriceFactorList factors)
 {
     DF = DiscountRate.Get(factors, InterestRateUtils.GetRateId(deal.Discount_Rate, deal.Currency));
     X  = factors.GetInterface <IFxRate>(deal.Currency);
 }
Example #15
0
        /// <summary>
        /// Validate the valuation models of the component deals.
        /// </summary>
        private void ValidateModels(ValuationList models, ErrorList errors)
        {
            const string Messsage = "{0} of underlying deals must be the same as {0} of {1}";

            // Get properties of Callable Structured Deal
            string discount = InterestRateUtils.GetRateId(fDeal.GetDiscountRate(), fDeal.Currency);
            string forecast = InterestRateUtils.GetRateId(fDeal.GetForecastRate(), discount);
            string issuer   = fDeal.GetIssuer();
            string recovery = InterestRateUtils.GetRateId(fDeal.GetRecoveryRate(), issuer);

            foreach (Valuation model in models)
            {
                if (model.Deal.fIgnore)
                {
                    continue;
                }
                else if (model.IsContainer())
                {
                    ValidateModels(model.fItems, errors);
                }
                else if (model.Deal is IRDealBase && model is ISingleDateValuation)
                {
                    IRDealBase underlyingDeal = (IRDealBase)model.Deal;

                    // Currency of underlying must match CSD
                    if (underlyingDeal.Currency != fDeal.Currency)
                    {
                        errors.Add(ErrorLevel.Error, string.Format(Messsage, "Currency", fDeal.GetType().Name));
                    }

                    // Discount_Rate and Forecast_Rate of underlying must either be left blank or match CSD
                    string underlyingDiscount = underlyingDeal.GetDiscountRate();
                    if (!string.IsNullOrEmpty(underlyingDiscount) && underlyingDiscount != discount)
                    {
                        errors.Add(ErrorLevel.Error, string.Format(Messsage, "Discount_Rate", fDeal.GetType().Name));
                    }

                    string underlyingForecast = underlyingDeal.GetForecastRate();
                    if (!string.IsNullOrEmpty(underlyingForecast) && underlyingForecast != forecast)
                    {
                        errors.Add(ErrorLevel.Error, string.Format(Messsage, "Forecast_Rate", fDeal.GetType().Name));
                    }

                    if (Use_Survival_Probability == YesNo.Yes && !string.IsNullOrEmpty(issuer))
                    {
                        // Issue and Recovery_Rate of underlying must either be left blank or match CSD
                        string underlyingIssuer = underlyingDeal.GetIssuer();
                        if (!string.IsNullOrEmpty(underlyingIssuer) && underlyingIssuer != issuer)
                        {
                            errors.Add(ErrorLevel.Error, string.Format(Messsage, "Issuer", fDeal.GetType().Name));
                        }
                    }

                    if (Respect_Default == YesNo.Yes && !string.IsNullOrEmpty(issuer))
                    {
                        string underlyingIssuer   = underlyingDeal.GetIssuer();
                        string underlyingRecovery = InterestRateUtils.GetRateId(underlyingDeal.GetRecoveryRate(), underlyingIssuer);
                        if (!string.IsNullOrEmpty(underlyingRecovery) && underlyingRecovery != recovery)
                        {
                            errors.Add(ErrorLevel.Error, string.Format(Messsage, "Recovery_Rate", fDeal.GetType().Name));
                        }
                    }
                }
                else
                {
                    // Underlying deal type must be IRDealBase and model must support ISingleDateValuation
                    errors.Add(ErrorLevel.Error, string.Format("{0} cannot be used in {1}", model.Deal.GetType().Name, fDeal.GetType().Name));
                }
            }
        }