public FixedFloatSwapCurveInstrument(Tenor tenor, FloatRateIndex index, double spread, double fixedRate, DiscountingSourceDescription discountCurveDescription, CurveToStrip curveToStrip) { _tenor = tenor; _index = index; _spread = spread; _fixedRate = fixedRate; _discountCurveDescription = discountCurveDescription; switch (curveToStrip) { case CurveToStrip.Forecast: { _nameOfCurveToStrip = new FloatingRateSourceDescription(index).Name; break; } case CurveToStrip.Discount: { _nameOfCurveToStrip = _discountCurveDescription.Name; break; } default: throw new ArgumentOutOfRangeException(nameof(curveToStrip), curveToStrip, null); } }
public FloatingRateSourceFromDiscountCalibrator(DiscountingSourceDescription baseCurveDescription, FloatRateIndex index) { _baseCurveDescription = baseCurveDescription; _index = index; _name = new FloatingRateSourceDescription(index).Name; }
public BasisSwapCurveInstrument(Tenor tenor, FloatRateIndex leg1Index, FloatRateIndex leg2Index, double leg1Spread, double leg2Spread, DiscountingSourceDescription discountCurveDescription, CurveToStrip curveToStrip) { _tenor = tenor; _leg1Index = leg1Index; _leg2Index = leg2Index; _leg1Spread = leg1Spread; _leg2Spread = leg2Spread; _discountCurveDescription = discountCurveDescription; switch (curveToStrip) { case CurveToStrip.Leg1Forecast: { _curveName = new FloatingRateSourceDescription(leg1Index).Name; break; } case CurveToStrip.Leg2Forecast: { _curveName = new FloatingRateSourceDescription(leg2Index).Name; break; } case CurveToStrip.DiscountCurve: { _curveName = _discountCurveDescription.Name; break; } default: throw new ArgumentOutOfRangeException(nameof(curveToStrip), curveToStrip, null); } }
private DatesAndRates InitializeCurve(Date calibrationDate, InitialValueCollector initialValueCollector, ObjectiveFunction objective, DiscountingSourceDescription curveToStrip, IEnumerable <FloatRateIndex> indicesToBaseOffCurve) { if (curveToStrip == null) { return(null); } var curveNames = new List <string> { curveToStrip.Name }; var indices = indicesToBaseOffCurve.ToList(); curveNames.AddRange( indices.Select(ind => new FloatingRateSourceDescription(ind).Name)); var initial = initialValueCollector.GetValues(curveNames); var curve = new DatesAndRates(curveToStrip.Currency, calibrationDate, initial.dates, initial.values); foreach (var index in indices) { var name = new FloatingRateSourceDescription(index).Name; _floatingRateSources[name] = new ForecastCurveFromDiscount(curve, index, null); } objective.AddCurve(curve, initial.values); return(curve); }
public void RateCurveCalibrator_CanCalibrateTwoCurves() { var instruments = new List <IRateCurveInstrument>(); var zarCsaCurveDescription = new DiscountingSourceDescription(_zar, new BankAccountNumeraire(_zar)); var jibarDiscountDescription = new DiscountingSourceDescription(_zar, _jibar3M); instruments.Add(new DepoCurveInstrument(Tenor.FromMonths(3), 0.071, jibarDiscountDescription)); instruments.Add(new FixedFloatSwapCurveInstrument(Tenor.FromMonths(6), _jibar3M, 0.0, 0.07, zarCsaCurveDescription, FixedFloatSwapCurveInstrument.CurveToStrip.Forecast)); instruments.Add(new FixedFloatSwapCurveInstrument(Tenor.FromYears(2), _jibar3M, 0.0, 0.07, zarCsaCurveDescription, FixedFloatSwapCurveInstrument.CurveToStrip.Forecast)); instruments.Add(new DepoCurveInstrument(Tenor.FromDays(1), 0.06, zarCsaCurveDescription)); instruments.Add(new BasisSwapCurveInstrument(Tenor.FromYears(1), _jibar3M, _jibar1D, 0.0, 0.01, zarCsaCurveDescription, BasisSwapCurveInstrument.CurveToStrip.DiscountCurve)); instruments.Add(new BasisSwapCurveInstrument(Tenor.FromYears(2), _jibar3M, _jibar1D, 0.0, 0.01, zarCsaCurveDescription, BasisSwapCurveInstrument.CurveToStrip.DiscountCurve)); var calib = new RateCurveCalibrator(instruments, new MultiDimNewton(1e-8, 100), zarCsaCurveDescription, new FloatRateIndex[] { _jibar1D }, jibarDiscountDescription, new FloatRateIndex[] { _jibar3M }); var mdc = new MarketDataContainer(); mdc.Set(calib); calib.TryCalibrate(_calibrationDate, mdc); var testValues = instruments.Select(inst => Math.Abs(inst.Objective())); var maxTestValue = testValues.Max(); Assert.AreEqual(0.0, maxTestValue, 1e-8); }
/// <summary> /// Create a calibrator for a two curves and forecast curves based off each of them. /// </summary> /// <param name="instruments"></param> /// <param name="rootFinder"></param> /// <param name="curveToStrip"></param> /// <param name="indicesToBaseOffDiscountCurve"></param> /// <param name="secondCurveToStrip"></param> /// <param name="indicesToBaseOffSecondCurve"></param> public RateCurveCalibrator(List <IRateCurveInstrument> instruments, IVectorRootFinder rootFinder, DiscountingSourceDescription curveToStrip, IEnumerable <FloatRateIndex> indicesToBaseOffDiscountCurve, DiscountingSourceDescription secondCurveToStrip, IEnumerable <FloatRateIndex> indicesToBaseOffSecondCurve) : this(instruments, rootFinder, curveToStrip, indicesToBaseOffDiscountCurve) { _secondCurveToStrip = secondCurveToStrip; _indicesToBaseOffSecondCurve = indicesToBaseOffSecondCurve ?? throw new ArgumentNullException(nameof(indicesToBaseOffSecondCurve)); }
public void RateCurveCalibrator_CanCalibrateSingleCurve() { var instruments = new List <IRateCurveInstrument>(); var discountCurve = new DiscountingSourceDescription(TestHelpers.ZAR); instruments.Add(new DepoCurveInstrument(Tenor.FromMonths(1), 0.071, discountCurve)); instruments.Add(new DepoCurveInstrument(Tenor.FromMonths(3), 0.072, discountCurve)); instruments.Add(new DepoCurveInstrument(Tenor.FromMonths(6), 0.073, discountCurve)); instruments.Add(new FRACurveInstrument(Tenor.FromMonths(6), Tenor.FromMonths(9), TestHelpers.Jibar3M, 0.073)); var calib = new RateCurveCalibrator(instruments, new MultiDimNewton(1e-8, 100), discountCurve, new FloatRateIndex[] { TestHelpers.Jibar3M }); var mdc = new MarketDataContainer(); mdc.Set(calib); calib.TryCalibrate(_calibrationDate, mdc); var testValues = instruments.Select(inst => Math.Abs(inst.Objective())); var maxTestValue = testValues.Max(); Assert.AreEqual(0.0, maxTestValue, 1e-8); }
public DepoCurveInstrument(Tenor tenor, double simpleRate, DiscountingSourceDescription discountCurve) { _tenor = tenor; _simpleRate = simpleRate; _discountCurve = discountCurve; }