Exemple #1
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));
        }
Exemple #2
0
        /// <summary>
        /// Prepare for valuation anything that is dependent upon the scenario.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);

            CFFixedInterestListDeal deal = (CFFixedInterestListDeal)fDeal;

            // Get factor for translation from rate currency to settlement currency for cashflows with FX reset date
            if (!string.IsNullOrEmpty(deal.Rate_Currency) && deal.Rate_Currency != fCurrency)
            {
                fRateFxRate = factors.GetInterface <IFxRate>(deal.Rate_Currency);
            }
        }
Exemple #3
0
        /// <summary>
        /// Prepare for valuation.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            var deal = (CFFloatingInterestListDeal)Deal;

            base.PreValue(factors);

            bool quanto    = fForecastIsForeign && fCharacteristics.HasQuanto && Quanto_Correction == YesNo.Yes;
            bool convexity = !fCharacteristics.IsStandardLibor && Convexity_Correction == YesNo.Yes;

            // volatility surfaces for forecast rate
            if (fCharacteristics.HasCms)
            {
                fForecastYieldVol = InterestVolBase.GetYieldVol(factors, deal.Forecast_Rate_Swaption_Volatility, fForecastCurrency);
            }

            if (fCharacteristics.HasLibor && (fCharacteristics.HasOptionlet || convexity || quanto))
            {
                fForecastRateVol = InterestVolBase.GetRateVol(factors, deal.Forecast_Rate_Cap_Volatility, fForecastCurrency);
            }

            // volatility surfaces for discount rate
            if (convexity)
            {
                // Discount rate volatility and correlation for convexity correction
                if (fCharacteristics.HasCms)
                {
                    fDiscountYieldVol = InterestVolBase.GetYieldVol(factors, deal.Discount_Rate_Swaption_Volatility, fCurrency);
                }

                if (fCharacteristics.HasLibor)
                {
                    fDiscountRateVol = InterestVolBase.GetRateVol(factors, deal.Discount_Rate_Cap_Volatility, fCurrency);
                }
            }

            if (fForecastIsForeign)
            {
                // Get factor for translation from forecast rate currency to settlement currency for cashflows with FX reset date
                if (fCharacteristics.HasFXReset)
                {
                    fForecastFxRate = factors.GetInterface <IFxRate>(fForecastCurrency);
                }

                if (quanto)
                {
                    fForecastFxVol          = FXVolHelper.Get(factors, fForecastCurrency, fCurrency);
                    fForecastFxCorrel       = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(FxRate), fForecastCurrency, fCurrency);
                    fForecastDiscountCorrel = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(InterestRate), fCurrency, null);
                }
            }
        }
        /// <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]);
                }
            }
        }
Exemple #5
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));
        }
        /// <summary>
        /// Calculate a valuation profile for a range of scenarios.
        /// </summary>
        public override void Value(ValuationResults valuationResults, PriceFactorList factors, BaseTimeGrid baseTimes)
        {
            IAssetPrice price  = GetAssetPrice(factors);
            PVProfiles  result = valuationResults.Profile;

            double scale = fDeal.Units * (fDeal.Buy_Sell == BuySell.Buy ? +1 : -1);

            var tgi = new TimeGridIterator(fT);

            VectorEngine.For(tgi, () => result.AppendVector(tgi.Date, scale * price.Get(tgi.T)));

            result.Complete(fT);

            CashAccumulators cashAccumulators = valuationResults.Cash;
            double           endDate          = Deal.EndDate();

            if (!cashAccumulators.Ignore && endDate <= fT.fHorizon)
            {
                double  tEnd   = CalcUtils.DaysToYears(endDate - factors.BaseDate);
                IFxRate fxRate = factors.GetInterface <IFxRate>(fDeal.Currency);
                cashAccumulators.Accumulate(fxRate, endDate, scale * price.Get(tEnd) / fxRate.Get(tEnd));
            }
        }
Exemple #7
0
        /// <summary>
        /// Prepare for valuation.
        /// </summary>
        public override void PreValue(PriceFactorList factors)
        {
            base.PreValue(factors);
            var deal = (CFEquityFloatingInterestListDeal)Deal;

            deal.GetDealHelper().PreValueAsset(out fEquity, out fEquityVol, ref fEquityQuantoCompo, factors);

            // Get FX rate price factors
            fEquityCurrency       = deal.Equity_Currency;
            fEquityPayoffCurrency = string.IsNullOrEmpty(deal.Equity_Payoff_Currency) ? fEquityCurrency : deal.Equity_Payoff_Currency;
            fEquityFXRate         = factors.GetInterface <IFxRate>(fEquityCurrency);
            fEquityPayoffFXRate   = fEquityPayoffCurrency != fEquityCurrency?factors.GetInterface <IFxRate>(fEquityPayoffCurrency) : fEquityFXRate;

            bool quanto = fForecastIsForeign && Quanto_Correction == YesNo.Yes;

            if (fCharacteristics.fHasLibor)
            {
                // volatility surfaces for forecast rate
                if ((!fCharacteristics.fIsStandardLibor && Convexity_Correction == YesNo.Yes) || quanto)
                {
                    fForecastRateVol = InterestVolBase.GetRateVol(factors, deal.Forecast_Rate_Cap_Volatility, fForecastCurrency);
                }

                // volatility surfaces for discount rate
                if (!fCharacteristics.fIsStandardLibor && Convexity_Correction == YesNo.Yes)
                {
                    fDiscountRateVol = InterestVolBase.GetRateVol(factors, deal.Discount_Rate_Cap_Volatility, fCurrency);
                }
            }

            if (quanto)
            {
                fForecastFXVol          = FXVolHelper.Get(factors, fForecastCurrency, fCurrency);
                fForecastFXCorrel       = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(FxRate), fForecastCurrency, fCurrency);
                fForecastDiscountCorrel = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(InterestRate), fCurrency, null);
            }
        }
 private static decimal getSpread(IFxRate rate)
 {
     return Math.Round(rate.Offer - rate.Bid, 4);
 }
 private static decimal getDelta(IFxRate rate)
 {
     return Math.Round(rate.Offer - rate.PreviousOffer, 4);
 }
Exemple #10
0
        /// <summary>
        /// Value the deal from given base date, price factors and time grid.
        /// </summary>
        public void Value(PVProfiles pvResults, CashAccumulators cashResults, double baseDate, IInterestRate discountRate, IInterestRate forecastRate1, IInterestRate forecastRate2, IFxRate fxRate, TimeGrid timeGrid, int numScenarios)
        {
            var tgi  = new TimeGridIterator(timeGrid);
            var deal = (FloatingInterestCashflowInterpolatedDeal)Deal;

            bool   hasRate1          = deal.HasRate1();
            bool   hasRate2          = deal.HasRate2();
            double scale             = deal.Buy_Sell == BuySell.Buy ? +deal.Principal : -deal.Principal;
            double tPay              = CalcUtils.DaysToYears(fPaymentDate - baseDate);
            double tReset            = CalcUtils.DaysToYears(deal.Reset_Date - baseDate);
            double tRateStart        = CalcUtils.DaysToYears(deal.Rate_Start_Date - baseDate);
            double tRateEnd1         = hasRate1 ? CalcUtils.DaysToYears(fRate1EndDate - baseDate) : 0.0;
            double tRateEnd2         = hasRate2 ? CalcUtils.DaysToYears(fRate2EndDate - baseDate) : 0.0;
            double tRateEnd12        = tRateEnd2 - tRateEnd1;                                                                    // Time from rate 1 end date to rate 2 end date.
            double tAccrualEnd       = CalcUtils.DaysToYears(deal.Accrual_End_Date - baseDate);
            double interpCoefficient = Math.Abs(tRateEnd12) >= CalcUtils.MinTime ? (tAccrualEnd - tRateEnd1) / tRateEnd12 : 0.0; // Coefficient used to calculate interpolated rate.

            VectorEngine.For(tgi, () =>
            {
                using (var cache = Vector.Cache(numScenarios))
                {
                    Vector pv = cache.Get();

                    if (tgi.Date <= fPaymentDate && fPaymentDate > fCutoffDate)
                    {
                        Vector interpRate = cache.GetClear();
                        Vector rate1      = cache.GetClear();
                        Vector rate2      = cache.GetClear();

                        if (hasRate1)
                        {
                            if (fKnownResetRate1.HasValue)
                            {
                                rate1.Assign(fKnownResetRate1.Value);
                            }
                            else
                            {
                                InterestRateUtils.LiborRate(rate1, forecastRate1, tgi.T, tReset, tRateStart, tRateEnd1, fRate1YearFraction);
                            }
                        }

                        if (hasRate2)
                        {
                            if (fKnownResetRate2.HasValue)
                            {
                                rate2.Assign(fKnownResetRate2.Value);
                            }
                            else
                            {
                                InterestRateUtils.LiborRate(rate2, forecastRate2, tgi.T, tReset, tRateStart, tRateEnd2, fRate2YearFraction);
                            }
                        }

                        if (hasRate1 && hasRate2)
                        {
                            if (Math.Abs(tRateEnd12) >= CalcUtils.MinTime)
                            {
                                interpRate.Assign(rate1 + interpCoefficient * (rate2 - rate1));
                            }
                            else
                            {
                                interpRate.Assign(0.5 * rate1 + 0.5 * rate2);
                            }
                        }
                        else
                        {
                            interpRate.Assign(hasRate1 ? rate1 : rate2);
                        }

                        // Round the calculated rate, regardless whether the valuation date is before or after the reset date.
                        CFFloatingInterestList.RoundRateTo(deal.Interpolated_Rate_Rounding, interpRate);

                        pv.Assign(scale * (interpRate + deal.Margin) * fAccrualYearFraction);

                        CFFixedList.RoundCashflow(pv, Cashflow_Rounding);

                        if (tgi.Date < fPaymentDate)
                        {
                            pv.MultiplyBy(discountRate.Get(tgi.T, tPay));
                        }
                        else if (tgi.Date == fPaymentDate)
                        {
                            cashResults.Accumulate(fxRate, fPaymentDate, pv);
                        }
                    }
                    else
                    {
                        pv.Clear();
                    }

                    pvResults.AppendVector(tgi.Date, pv * fxRate.Get(tgi.T));
                }
            });

            // After maturity
            pvResults.Complete(timeGrid);
        }