/// <summary> /// Calculate valuation profiles. /// </summary> public override void Value(ValuationResults valuationResults, PriceFactorList factors, BaseTimeGrid baseTimes) { PreValue(factors); TimeGridIterator tgi = new TimeGridIterator(fT); PVProfiles result = valuationResults.Profile; CommitmentDeal deal = (CommitmentDeal)Deal; VectorEngine.For(tgi, () => { if (tgi.Date < deal.Effective_Date) { result.AppendZeroVector(tgi.Date); } else { double amount = deal.Amortisation.GetPrincipal(deal.Amount, tgi.Date - 1.0); result.AppendVector(tgi.Date, fFxRate.Get(tgi.T) * amount); } }); result.Complete(fT); }
/// <summary> /// Calculate valuation profiles. /// </summary> public override void Value(ValuationResults valuationResults, PriceFactorList factors, BaseTimeGrid baseTimes) { PreValue(factors); TimeGridIterator tgi = new TimeGridIterator(fT); PVProfiles result = valuationResults.Profile; CashAccumulators cashAccumulator = valuationResults.Cash; double baseDate = factors.BaseDate; CallableStructuredDeal deal = (CallableStructuredDeal)fDeal; int buySellSign = deal.Buy_Sell == BuySell.Buy ? +1 : -1; int callPutSign = deal.Option_Type == OptionType.Call ? 1 : -1; InterestRateOptionPricer optionPricer = CreateOptionPricer(factors); CalcUtils.CreateDealProfilesIfRequired(valuationResults, fItems, factors); bool needRating = Respect_Default == YesNo.Yes && !string.IsNullOrEmpty(deal.Issuer); using (var cache = Vector.Cache(factors.NumScenarios)) { Vector exercised = cache.GetClear(); // vector taking value 0 or 1 indicating exercise before tgi.date Vector exercisedToday = cache.Get(); // vector taking value 0 or 1 indicating exercise at tgi.date Vector optionPv = cache.Get(); Vector pv = cache.Get(); Vector cash = cache.Get(); Vector settlementDateAtExercise = cache.GetClear(); Vector defaultDate = needRating ? cache.Get(CalcUtils.DateTimeMaxValueAsDouble) : null; var defaultedBeforeBaseDate = needRating && CreditRating.DefaultedBeforeBaseDate(fCreditRating, baseDate); while (tgi.Next()) { if (defaultedBeforeBaseDate) { pv.Clear(); result.AppendVector(tgi.Date, pv); break; } if (needRating) { UpdateDefaultDate(fCreditRating, tgi.Date, tgi.T, defaultDate); } double val; bool allExercised = exercised.AllElementsTheSame(out val) && val == 1.0; if (deal.Settlement_Style == SettlementType2.Physical) { // Calculate value of option (option value is zero after last exercise date) if (!allExercised) { optionPricer.Value(baseDate, tgi.Date, optionPv, exercised, exercisedToday, settlementDateAtExercise, defaultDate); } // Calculate value of underlying cashflows after settlementDateAtExercise pv.Clear(); cash.Clear(); InterestRateOptionPricer.ValueDeals(fItems, pv, cash, baseDate, tgi.Date, settlementDateAtExercise, defaultDate, fDiscountRate, fForecastRate, fRepoRate, fInterestRateVol, fInterestYieldVol, fSurvivalProb, fRecoveryRate); pv.MultiplyBy(callPutSign); cash.MultiplyBy(callPutSign); if (!allExercised) { // If exercised today the cashflow is the value of the option minus the value of the physically settled part // Else if already exercised, cash is the unnderlying cash. // Else (before exercise) there is no cash. cash.AssignConditional(exercisedToday, optionPv - pv, exercised * cash); // If already exercised, pv is the unnderlying pv. // Else (before exercise or exercised today), pv is the option pv. pv.AssignConditional(exercised, pv, optionPv); pv.AssignConditional(exercisedToday, optionPv, pv); } } else { if (allExercised) { // Already exercised on all scenarios result.AppendZeroVector(tgi.Date); continue; } if (deal.Settlement_Style == SettlementType2.Cash) { // Calculate value of option optionPricer.Value(baseDate, tgi.Date, pv, exercised, exercisedToday, settlementDateAtExercise, defaultDate); // If exercised today then option pv is settled today, otherwise there is no cash cash.AssignProduct(pv, exercisedToday); } else // Embedded option (callable or puttable) { // Calculate underlying value pv.Clear(); cash.Clear(); InterestRateOptionPricer.ValueDeals(fItems, pv, cash, baseDate, tgi.Date, null, defaultDate, fDiscountRate, fForecastRate, fRepoRate, fInterestRateVol, fInterestYieldVol, fSurvivalProb, fRecoveryRate); // Calculate value of option optionPricer.Value(baseDate, tgi.Date, optionPv, exercised, exercisedToday, settlementDateAtExercise, defaultDate); // Add or subtract value of embedded option pv.AddProduct(-callPutSign, optionPv); // Option payoff is Max(callPutSign * (underlyingPv - accruedInterest - discountedFee), 0) // Callable/puttable payoff on exercise is // underlyingPv - callPutSign * (callPutSign * (underlyingPv - accruedInterest - discountedFee)) // = accruedInterest + discountedFee // Set pv and cash to zero if already exercised. // If exercised today then the pv is settled today. pv.AssignConditional(exercised, exercisedToday * pv, pv); cash.AssignConditional(exercised, exercisedToday * pv, cash); } } pv.MultiplyBy(buySellSign); cash.MultiplyBy(buySellSign); result.AppendVector(tgi.Date, fFxRate.Get(tgi.T) * pv); cashAccumulator.Accumulate(fFxRate, tgi.Date, cash); } } result.Complete(fT); }