public IFundingInstrument Clone() => new IrSwap { BasisFixed = BasisFixed, BasisFloat = BasisFloat, Currency = Currency, Counterparty = Counterparty, DiscountCurve = DiscountCurve, EndDate = EndDate, FixedLeg = FixedLeg.Clone(), FloatLeg = FloatLeg.Clone(), FlowScheduleFixed = FlowScheduleFixed.Clone(), FlowScheduleFloat = FlowScheduleFloat.Clone(), ForecastCurve = ForecastCurve, NDates = NDates, Notional = Notional, ParRate = ParRate, PillarDate = PillarDate, ResetDates = ResetDates, ResetFrequency = ResetFrequency, SolveCurve = SolveCurve, StartDate = StartDate, SwapTenor = SwapTenor, SwapType = SwapType, TradeId = TradeId, RateIndex = RateIndex, PortfolioName = PortfolioName, HedgingSet = HedgingSet };
public static double LinearRateModel_FloatLegValue(string baseName, string floatLegName) { LinearRateModel model = ObjectMap.LinearRateModels[baseName]; FloatLeg fixedLeg = ObjectMap.FloatLegs[floatLegName]; return(model.ValueFloatLeg(fixedLeg)); }
public static object _CreateFloatLeg(string objectName, object[,] currency, object[,] floatingIndex, object[,] resetDates, object[,] paymentDates, object[,] notionals, object[,] spreads, object[,] accrualFractions) { try { Currency _currency = XU.GetCurrency0D(currency, "currency"); FloatingIndex _floatingIndex = XU.GetFloatingIndex0D(floatingIndex, "floatingIndex"); Date[] _resetDates = XU.GetDate1D(resetDates, "resetDates"); Date[] _paymentDates = XU.GetDate1D(paymentDates, "paymentDates"); Double[] _notionals = XU.GetDouble1D(notionals, "notionals"); Double[] _spreads = XU.GetDouble1D(spreads, "spreads"); Double[] _accrualFractions = XU.GetDouble1D(accrualFractions, "accrualFractions"); FloatLeg _result = XLRates.CreateFloatLeg(_currency, _floatingIndex, _resetDates, _paymentDates, _notionals, _spreads, _accrualFractions); return(XU.AddObject(objectName, _result)); } catch (Exception e) { return(XU.Error0D(e)); } }
public static void BasisSwap_Make(string baseName, string floatLegNoSpreadName, string floatLegSpreadName, int tradeSign) { FloatLeg floatLegNoSpread = ObjectMap.FloatLegs[floatLegNoSpreadName]; FloatLeg floatLegSpread = ObjectMap.FloatLegs[floatLegSpreadName]; TenorBasisSwap swap = new MasterThesis.TenorBasisSwap(floatLegSpread, floatLegNoSpread, tradeSign); ObjectMap.LinearRateInstruments[baseName] = swap; ObjectMap.BasisSwaps[baseName] = swap; }
public static void PlainVanillaSwap_Make(string baseName, string fixedLegName, string floatLegName, int tradeSign) { FixedLeg fixedLeg = ObjectMap.FixedLegs[fixedLegName]; FloatLeg floatLeg = ObjectMap.FloatLegs[floatLegName]; IrSwap swap = new MasterThesis.IrSwap(floatLeg, fixedLeg, tradeSign); ObjectMap.LinearRateInstruments[baseName] = swap; ObjectMap.IrSwaps[baseName] = swap; }
public void SetCalibrationDate(Date calibrationDate) { _floatLeg = SwapFactory.CreateFloatLeg(calibrationDate, _tenor, _index, _spread); _fixedLeg = SwapFactory.CreateFixedLeg(calibrationDate, _tenor, _index, _fixedRate); _floatLeg.SetValueDate(calibrationDate); _fixedLeg.SetValueDate(calibrationDate); _endDate = _floatLeg.GetCashflowDates(_index.Currency).Max(); var otherEndDate = _fixedLeg.GetCashflowDates(_index.Currency).Max(); if (_endDate < otherEndDate) { _endDate = otherEndDate; } }
public void SetCalibrationDate(Date calibrationDate) { _leg1 = SwapFactory.CreateFloatLeg(calibrationDate, _tenor, _leg1Index, _leg1Spread); _leg2 = SwapFactory.CreateFloatLeg(calibrationDate, _tenor, _leg2Index, _leg2Spread); _leg1.SetValueDate(calibrationDate); _leg2.SetValueDate(calibrationDate); _endDate = _leg1.GetCashflowDates(_leg1Index.Currency).Max(); var otherEndDate = _leg2.GetCashflowDates(_leg2Index.Currency).Max(); if (_endDate < otherEndDate) { _endDate = otherEndDate; } }
private FloatLeg CreateFloatingLeg(Currency ccy, Date startDate, double notional, FloatingIndex index, int tenorYears) { int quarters = tenorYears * 4; Date[] paymentDates = Enumerable.Range(1, quarters).Select(i => startDate.AddMonths(3 * i)).ToArray(); Date[] resetDates = Enumerable.Range(0, quarters).Select(i => startDate.AddMonths(3 * i)).ToArray(); double[] notionals = Vector.Ones(quarters).Multiply(notional); double[] spreads = Vector.Zeros(quarters); double[] accrualFractions = Vector.Ones(quarters).Multiply(0.25); FloatingIndex[] floatingIndices = Enumerable.Range(1, quarters).Select(i => index).ToArray(); FloatLeg leg = new FloatLeg(ccy, paymentDates, notionals, resetDates, floatingIndices, spreads, accrualFractions); return(leg); }
public void TestFloatLeg() { // Make the reference swap var rate = 0.0; var payFixed = true; double notional = 1000000; var startDate = new Date(2016, 9, 17); var tenor = Tenor.Years(1); var swap = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor); // Make a FloatLeg var resetDates = new Date[4]; var paymentDates = new Date[4]; var accrualFractions = new double[4]; var runningDate = new Date(2016, 9, 17); for (var i = 0; i < 4; i++) { resetDates[i] = new Date(runningDate); paymentDates[i] = resetDates[i].AddMonths(3); accrualFractions[i] = (paymentDates[i] - resetDates[i]) / 365.0; runningDate = paymentDates[i]; } var floatLeg = new FloatLeg(Currency.ZAR, paymentDates, new[] { 1e6, 1e6, 1e6, 1e6 }, resetDates, new[] { FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M }, new double[] { 0, 0, 0, 0 }, accrualFractions); // Set up the model var valueDate = new Date(2016, 9, 17); Date[] dates = { new Date(2016, 9, 17), new Date(2026, 9, 17) }; double[] rates = { 0.07, 0.07 }; IDiscountingSource discountCurve = new DatesAndRates(Currency.ZAR, valueDate, dates, rates); IFloatingRateSource forecastCurve = new ForecastCurve(valueDate, FloatingIndex.JIBAR3M, dates, rates); var curveSim = new DeterminsiticCurves(discountCurve); curveSim.AddRateForecast(forecastCurve); // Run the valuation var coordinator = new Coordinator(curveSim, new List <Simulator>(), 1); var swapValue = coordinator.Value(new Product[] { swap }, valueDate); var floatLegValue = coordinator.Value(new Product[] { floatLeg }, valueDate); Assert.AreEqual(swapValue, floatLegValue, 0.01); }
/// <summary> /// Curve based valuation of <see cref="FloatLeg"/>. Assumes that correct forecast and discount curves have been provided. /// </summary> /// <param name="leg"></param> /// <param name="forecastCurve"></param> /// <param name="discountCurve"></param> /// <returns></returns> public static double CurvePV(this FloatLeg leg, IFloatingRateSource forecastCurve, IDiscountingSource discountCurve) { var legIndex = forecastCurve.GetFloatingIndex(); var resetDates1 = leg.GetRequiredIndexDates(legIndex); var indexValues1 = new double[resetDates1.Count]; for (var i = 0; i < resetDates1.Count; i++) { indexValues1[i] = forecastCurve.GetForwardRate(resetDates1[i]); } leg.SetIndexValues(legIndex, indexValues1); var cfs1 = leg.GetCFs(); var value1 = cfs1.PV(discountCurve); return(value1); }