public double LongEndTargetFunction(double zeroRateSpread) { DateTime baseDate = _baseCurve.GetBaseDate(); DateTime maturityDate = _asset.GetRiskMaturityDate(); _zeroRateSpreads[maturityDate] = zeroRateSpread; decimal dfMaturityBasisAdjustCurve = (decimal)RateBootstrapperNewtonRaphson.GetAdjustedDiscountFactor(baseDate, maturityDate, _dayCounter, zeroRateSpread, _baseCurve); UpdateDiscountFactors(baseDate); if (_items.ContainsKey(maturityDate)) { _items[maturityDate].Second = dfMaturityBasisAdjustCurve; } else { Pair <string, decimal> pair = new Pair <string, decimal>("", dfMaturityBasisAdjustCurve); _items.Add(maturityDate, pair); } List <DateTime> dates = _items.Keys.ToList(); List <decimal> rates = _items.Values.Select(a => a.Second).ToList(); RateCurve discountCurve = new RateCurve(_properties, _algorithm, dates, rates); double sum = 0; for (int i = 0; i < _assetDates.Count - 1; i++) { DateTime date0 = _assetDates[i]; DateTime date1 = _assetDates[i + 1]; double d0 = _baseCurve.GetDiscountFactor(date0); double d1 = _baseCurve.GetDiscountFactor(date1); double y = _dayCounter.YearFraction(date0, date1); double projectedRate = 1 / y * (d0 / d1 - 1); double basisAdjustedDf = discountCurve.GetDiscountFactor(date1); double subSum = basisAdjustedDf * y * (projectedRate + (double)_asset.MarketQuote.value); sum += subSum; } double discountFactor = discountCurve.GetDiscountFactor(_assetDates.First()); double result = -discountFactor + (double)dfMaturityBasisAdjustCurve + sum; return(result); }
public NewtonRaphsonSolverFunctions(IPriceableAssetController asset, IPriceableAssetController previousAsset, PricingStructureAlgorithmsHolder algorithmHolder, IRateCurve baseCurve, DateTime baseDate, SortedDictionary <DateTime, Pair <string, decimal> > items, double compoundingPeriod, IDictionary <DateTime, double> zeroRateSpreads, IDayCounter dayCounter, List <DateTime> assetDates) { _asset = asset; _baseCurve = baseCurve; _zeroRateSpreads = zeroRateSpreads; string currency = PropertyHelper.ExtractCurrency(baseCurve.GetPricingStructureId().Properties); _algorithm = algorithmHolder; _properties = new NamedValueSet(new Dictionary <string, object> { { CurveProp.PricingStructureType, "RateCurve" }, { CurveProp.Market, "DiscountCurveConstruction" }, { CurveProp.IndexTenor, "0M" }, { CurveProp.Currency1, currency }, { "Index", "XXX-XXX" }, { "Algorithm", "FastLinearZero" }, { "BaseDate", baseDate }, }); _items = items; _compoundingPeriod = compoundingPeriod; _dayCounter = dayCounter; _assetDates = assetDates; if (previousAsset != null) { DateTime previousAssetMaturity = previousAsset.GetRiskMaturityDate(); DateTime assetMaturity = asset.GetRiskMaturityDate(); IEnumerable <KeyValuePair <DateTime, string> > points = from b in baseCurve.GetTermCurve().point where (DateTime)b.term.Items[0] > previousAssetMaturity && (DateTime)b.term.Items[0] < assetMaturity select new KeyValuePair <DateTime, string>((DateTime)b.term.Items[0], b.id); foreach (KeyValuePair <DateTime, string> point in points) { _extraPoints.Add(point.Key, point.Value); Pair <string, decimal> pair = new Pair <string, decimal>(point.Value, 0); items.Add(point.Key, pair); } } }