/// <summary> /// Bootstraps the specified priceable assets, where the assets /// are simple commodity asset with single cash flows on a /// single index observation. /// </summary> /// <param name="priceableAssets">The priceable assets.</param> /// <param name="referenceCurve">The reference curve.</param> /// <param name="baseDate">The base date.</param> /// <param name="extrapolationPermitted">The extrapolationPermitted flag.</param> /// <param name="tolerance">The tolerance for the solver</param> /// <param name="spreadXArray">THe spread interpolator produced in the bootstrapper</param> /// <param name="spreadYArray">THe spread interpolator produced in the bootstrapper</param> /// <returns></returns> public static TermPoint[] Bootstrap(IEnumerable <IPriceableCommoditySpreadAssetController> priceableAssets, ICommodityCurve referenceCurve, DateTime baseDate, bool extrapolationPermitted, double tolerance, ref IList <double> spreadXArray, ref IList <double> spreadYArray) { //only works for linear on zero. //InterpolationMethod interp = InterpolationMethodHelper.Parse("LinearInterpolation"); // Add the first element (date : discount factor) to the list var points = new Dictionary <DateTime, double>(); var items = new SortedDictionary <DateTime, Pair <string, decimal> >(); var dayCounter = new Actual365(); foreach (var priceableAsset in priceableAssets) { DateTime assetMaturityDate = priceableAsset.GetRiskMaturityDate(); if (points.Keys.Contains(assetMaturityDate)) { continue; } //This now should automatically extrapolate the required discount factor on a flat rate basis. if (IsSpreadAsset(priceableAsset)) { //These are simple assts so the solver is unnecessary. var value = (double)priceableAsset.CalculateImpliedQuoteWithSpread(referenceCurve); var dayCount = dayCounter.YearFraction(baseDate, assetMaturityDate); spreadXArray.Add(dayCount); spreadYArray.Add((double)priceableAsset.MarketQuote.value); //TODO Get the marketquote points.Add(assetMaturityDate, value); items.Add(assetMaturityDate, new Pair <string, decimal>(priceableAsset.Id, (decimal)points[assetMaturityDate])); } } if (spreadXArray.Count > 2) { var spreadCurveInterpolator = new LinearInterpolation(spreadXArray.ToArray(), spreadYArray.ToArray()); var index = 0; foreach (var assetMaturityDate in referenceCurve.GetTermCurve().GetListTermDates()) { if (points.Keys.Contains(assetMaturityDate)) { continue; } var dayCount = dayCounter.YearFraction(baseDate, assetMaturityDate); double spreadValue = spreadCurveInterpolator.ValueAt(dayCount, true); var value = referenceCurve.GetForward(baseDate, assetMaturityDate); points.Add(assetMaturityDate, value + spreadValue); items.Add(assetMaturityDate, new Pair <string, decimal>("RefCurvePillar_" + index, (decimal)points[assetMaturityDate])); index++; } return(TermPointsFactory.Create(items)); } return(null); }
/// <summary> /// This assumes that the rest dates are consistent with the curve. /// </summary> /// <param name="valuationDate"></param> /// <param name="paymentDate">The payment date. The same rest period is assumed as with the spot date.</param> /// <param name="indexCurve">The index curve should be already in the correct form for the fx.</param> /// <param name="currency1">Normally the domestic rate curve. </param> public CommoditySwapLegAnalytic(DateTime valuationDate, DateTime paymentDate, ICommodityCurve indexCurve, IRateCurve currency1) { //ToReportingCurrencyRate = EvaluateReportingCurrencyFxRate(valuationDate, reportingCurrencyFxCurve); var todayRate = indexCurve.GetForward(valuationDate, valuationDate); //TODO The spot rate may not be the same due to the carry effect, but the evolution works. var df1 = currency1.GetDiscountFactor(valuationDate, paymentDate); }
/// <summary> /// This assumes that the rest dates are consistent with the curve. /// </summary> /// <param name="valuationDate"></param> /// <param name="paymentDate"></param> /// <param name="indexCurve"></param> public CommoditySwapLegAnalytic(DateTime valuationDate, DateTime paymentDate, ICommodityCurve indexCurve) { //ToReportingCurrencyRate = EvaluateReportingCurrencyFxRate(valuationDate, reportingCurrencyFxCurve); Units = (decimal)indexCurve.GetForward(valuationDate, paymentDate); }