/// <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> /// Value the deal using the cashflow list. /// </summary> /// <param name="pv">Present value to be updated.</param> /// <param name="cash">Realised cash to be updated.</param> public void Value(Vector pv, Vector cash, double baseDate, double valueDate, Vector settlementDate, IInterestRate discount, IInterestRate forecast, IInterestRate repo, IInterestRateVol interestRateVol, IInterestYieldVol interestYieldVol, ISurvivalProb survivalProb, ISACCRResult saccrResult, IIntraValuationDiagnosticsWriter intraValuationDiagnosticsWriter) { CFFixedListDeal deal = (CFFixedListDeal)Deal; pv.Clear(); if (cash != null) { cash.Clear(); } deal.Cashflows.Value(pv, cash, baseDate, valueDate, settlementDate, discount, survivalProb, intraValuationDiagnosticsWriter, fCutoffDate); ApplySign(pv, cash, fBuySellSign); }
/// <summary> /// Single date valuation function. /// </summary> public void Value(Vector pv, Vector cash, double baseDate, double valueDate, Vector settlementDate, IInterestRate discount, IInterestRate forecast, IInterestRate repo, IInterestRateVol interestRateVol, IInterestYieldVol interestYieldVol, ISurvivalProb survivalProb, ISACCRResult saccrResult, IIntraValuationDiagnosticsWriter intraValuationDiagnosticsWriter) { FixedCashflowBaseDeal deal = (FixedCashflowBaseDeal)fDeal; double payDate = deal.Payment_Date; if (payDate < valueDate) { return; } using (var cache = Vector.CacheLike(pv)) { Vector amount = cache.Get(fAmount); if (settlementDate != null) { amount.MultiplyBy(settlementDate < payDate); } if (payDate == valueDate) { pv.Assign(amount); if (cash != null) { cash.Assign(amount); } } else { double t = CalcUtils.DaysToYears(valueDate - baseDate); double tPay = CalcUtils.DaysToYears(payDate - baseDate); if (survivalProb != null) { pv.Assign(amount * discount.Get(t, tPay) * survivalProb.Get(t, tPay)); } else { pv.Assign(amount * discount.Get(t, tPay)); } } } }
/// <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); } }
/// <summary> /// Value the deal using the cashflow list. /// </summary> /// <param name="pv">Present value to be updated.</param> /// <param name="cash">Realised cash to be updated.</param> public void Value(Vector pv, Vector cash, double baseDate, double valueDate, Vector settlementDate, IInterestRate discount, IInterestRate forecast, IInterestRate repo, IInterestRateVol interestRateVol, IInterestYieldVol interestYieldVol, ISurvivalProb survivalProb, ISACCRResult saccrResult, IIntraValuationDiagnosticsWriter intraValuationDiagnosticsWriter) { CFFixedInterestListDeal deal = (CFFixedInterestListDeal)Deal; pv.Clear(); if (cash != null) { cash.Clear(); } deal.Cashflows.Value(pv, cash, null, baseDate, valueDate, settlementDate, discount, survivalProb, fFxRate, fRateFxRate, intraValuationDiagnosticsWriter, fCutoffDate); using (var cache = Vector.CacheLike(pv)) { Vector sp = cache.Get(1.0); double dealSettlementDate = deal.Settlement_Date; double t = CalcUtils.DaysToYears(valueDate - baseDate); double tSettle = CalcUtils.DaysToYears(dealSettlementDate - baseDate); if (Use_Survival_Probability == YesNo.Yes && survivalProb != null) { survivalProb.GetValue(sp, t, tSettle); fRecoveryList.Value(pv, baseDate, valueDate, discount, survivalProb, intraValuationDiagnosticsWriter); } if (valueDate < dealSettlementDate) { // Forward deal before settlement date if (deal.Is_Defaultable == YesNo.No) { pv.Assign((pv / discount.Get(t, tSettle) - fSettlementAmount) * repo.Get(t, tSettle)); } else { pv.Subtract(fAccruedInterest * discount.Get(t, tSettle) * sp + (fSettlementAmount - fAccruedInterest) * repo.Get(t, tSettle)); } } else if (valueDate == dealSettlementDate) { // Forward deal at settlement date pv.Subtract(fSettlementAmount); if (cash != null) { if (deal.Settlement_Style == SettlementType.Cash) { cash.Assign(pv); } else { cash.Subtract(fSettlementAmount); } } } } pv.AssignProduct(fBuySellSign, pv); if (cash != null) { cash.AssignProduct(fBuySellSign, cash); } }
/// <summary> /// Prepare for valuation. /// </summary> public override void PreValue(PriceFactorList factors) { base.PreValue(factors); CFGeneralInterestSpreadListDeal deal = (CFGeneralInterestSpreadListDeal)Deal; // Get spread flow characteristics SpreadCashflowListCharacteristics spreadCashflowCharacteristics = fCashflows.ValuationPriceFactorDependencies(factors.BaseDate, fCurrency, fForecastCurrency, fForecast2Currency); // vols for first forecast rate if (spreadCashflowCharacteristics.NeedForecast1YieldVol) { fForecast1YieldVol = InterestVolBase.GetYieldVol(factors, deal.Forecast_Rate1_Swaption_Volatility, fForecastCurrency); } if (spreadCashflowCharacteristics.NeedForecast1RateVol) { fForecast1RateVol = InterestVolBase.GetRateVol(factors, deal.Forecast_Rate1_Cap_Volatility, fForecastCurrency); } // vols for second forecast rate if (spreadCashflowCharacteristics.NeedForecast2YieldVol) { fForecast2YieldVol = InterestVolBase.GetYieldVol(factors, deal.Forecast_Rate2_Swaption_Volatility, fForecast2Currency); } if (spreadCashflowCharacteristics.NeedForecast2RateVol) { fForecast2RateVol = InterestVolBase.GetRateVol(factors, deal.Forecast_Rate2_Cap_Volatility, fForecast2Currency); } // vols for discount rate if (spreadCashflowCharacteristics.NeedDiscountYieldVol) { fDiscountYieldVol = InterestVolBase.GetYieldVol(factors, deal.Discount_Rate_Swaption_Volatility, fCurrency); } if (spreadCashflowCharacteristics.NeedDiscountRateVol) { fDiscountRateVol = InterestVolBase.GetRateVol(factors, deal.Discount_Rate_Cap_Volatility, fCurrency); } bool convexity = spreadCashflowCharacteristics.NeedDiscountYieldVol || spreadCashflowCharacteristics.NeedDiscountRateVol; if (fForecastCurrency != fCurrency) { if (Quanto_Correction == YesNo.Yes) { // fx vol, fx/ir correl and forecast/discount correl fFx1Vol = FXVolHelper.Get(factors, fForecastCurrency, fCurrency); fForecast1Fx1Correl = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(FxRate), fForecastCurrency, fCurrency); } if (convexity) { fForecast1DiscountCorrel = CorrelationHelper.Get(factors, typeof(InterestRate), fCurrency, null, typeof(InterestRate), fForecastCurrency, null); } } if (fForecast2Currency != fCurrency) { if (Quanto_Correction == YesNo.Yes) { // fx vol, fx/ir correl and forecast/discount correl fFx2Vol = FXVolHelper.Get(factors, fForecast2Currency, fCurrency); fForecast2Fx2Correl = CorrelationHelper.Get(factors, typeof(InterestRate), fForecast2Currency, null, typeof(FxRate), fForecast2Currency, fCurrency); } if (convexity) { fForecast2DiscountCorrel = CorrelationHelper.Get(factors, typeof(InterestRate), fCurrency, null, typeof(InterestRate), fForecast2Currency, null); } } if (spreadCashflowCharacteristics.NeedForecast1Forecast2Correlation) { if (fForecastCurrency == fForecast2Currency) { // correl between forecast rates in same currency fForecast1Forecast2Correls = factors.Get <CMSRateCorrelations>(fForecastCurrency); } else { fForecast1Forecast2Correl = CorrelationHelper.Get(factors, typeof(InterestRate), fForecastCurrency, null, typeof(InterestRate), fForecast2Currency, null); } } }
/// <summary> /// Value the deal using the cashflow list. /// </summary> public void Value(Vector pv, Vector cash, double baseDate, double valueDate, Vector settlementDate, IInterestRate discount, IInterestRate forecast, IInterestRate repo, IInterestRateVol interestRateVol, IInterestYieldVol interestYieldVol, ISurvivalProb survivalProb, ISACCRResult saccrResult, IIntraValuationDiagnosticsWriter intraValuationDiagnosticsWriter) { var deal = (CFFloatingInterestListDeal)Deal; pv.Clear(); if (cash != null) { cash.Clear(); } bool valued = false; if (Use_Survival_Probability == YesNo.Yes && survivalProb != null) { fRecoveryList.Value(pv, baseDate, valueDate, discount, survivalProb, intraValuationDiagnosticsWriter); } else if (!fForecastIsForeign && fCharacteristics.IsStandardPayoff && fCharacteristics.IsStandardLibor && fCashflows.Compounding_Method != CompoundingMethod.Exponential) { if (fCharacteristics.HasSwaplet && !fCharacteristics.HasOptionlet) { ValueSwap(pv, cash, baseDate, valueDate, settlementDate, discount, forecast, intraValuationDiagnosticsWriter); valued = true; } else if (fCharacteristics.HasOptionlet && !fCharacteristics.HasSwaplet && fCashflows.Compounding_Method == CompoundingMethod.None) { fCashflows.ValueCap(pv, cash, baseDate, valueDate, settlementDate, discount, forecast, fForecastRateVol, saccrResult, intraValuationDiagnosticsWriter, fCutoffDate); valued = true; } } if (!valued) { // Use general cashflow list valuation if (fCashflows.Averaging_Method == AveragingMethod.Average_Rate) { fCashflows.ValueAverageRate(pv, cash, baseDate, valueDate, settlementDate, discount, forecast, fForecastRateVol, fForecastYieldVol, fFxRate, fForecastFxRate, fForecastFxVol, fForecastFxCorrel, survivalProb, intraValuationDiagnosticsWriter, fCutoffDate); } else { fCashflows.Value(pv, cash, baseDate, valueDate, settlementDate, discount, forecast, fDiscountRateVol, fDiscountYieldVol, interestRateVol, interestYieldVol, fFxRate, fForecastFxRate, fForecastFxVol, fForecastFxCorrel, fForecastDiscountCorrel, survivalProb, intraValuationDiagnosticsWriter, fCutoffDate); } } double dealSettlementDate = deal.Settlement_Date; if (valueDate <= dealSettlementDate) { using (var cache = Vector.CacheLike(pv)) { Vector accruedInterest = cache.Get(); fCashflows.CalculateAccrual(accruedInterest, baseDate, dealSettlementDate, false, deal.AccrualHolidayCalendar(), forecast); Vector settlementAmount = cache.Get(deal.Settlement_Amount); if (deal.Settlement_Amount_Is_Clean == YesNo.Yes) { settlementAmount.Add(accruedInterest); } if (valueDate < dealSettlementDate) { // Forward deal before settlement date double t = CalcUtils.DaysToYears(valueDate - baseDate); double tSettle = CalcUtils.DaysToYears(dealSettlementDate - baseDate); if (deal.Is_Defaultable == YesNo.No) { pv.Assign((pv / discount.Get(t, tSettle) - settlementAmount) * repo.Get(t, tSettle)); } else { pv.Subtract(accruedInterest * discount.Get(t, tSettle) + (settlementAmount - accruedInterest) * repo.Get(t, tSettle)); } } else if (valueDate == dealSettlementDate) { // Forward deal at settlement date pv.Subtract(settlementAmount); if (cash != null) { if (deal.Settlement_Style == SettlementType.Cash) { cash.Assign(pv); } else { cash.Subtract(settlementAmount); } } } } } pv.AssignProduct(fBuySellSign, pv); if (cash != null) { cash.AssignProduct(fBuySellSign, cash); } }