/// <summary> /// Create a <see cref="FloatLeg"/>. /// </summary> /// <param name="calibrationDate"></param> /// <param name="tenor"></param> /// <param name="index"></param> /// <param name="fixedRate"></param> /// <returns></returns> public static FixedLeg CreateFixedLeg(Date calibrationDate, Tenor tenor, FloatRateIndex index, double fixedRate) { DateGenerators.CreateDatesNoHolidays(calibrationDate, tenor, index.Tenor, out var resetDates, out var paymentDates, out var accrualFractions); var notionals = resetDates.Select(d => 1e6); var rates = resetDates.Select(d => fixedRate); return(new FixedLeg(index.Currency, paymentDates, notionals, rates, accrualFractions)); }
/// <summary> /// Create a <see cref="FloatLeg"/>. /// </summary> /// <param name="calibrationDate"></param> /// <param name="tenor"></param> /// <param name="index"></param> /// <param name="spread"></param> /// <returns></returns> public static FloatLeg CreateFloatLeg(Date calibrationDate, Tenor tenor, FloatRateIndex index, double spread) { DateGenerators.CreateDatesNoHolidays(calibrationDate, tenor, index.Tenor, out var resetDates, out var paymentDates, out var accrualFractions); var notionals = resetDates.Select(d => 1e6); var floatingIndices = resetDates.Select(d => index); var spreads = resetDates.Select(d => spread); return(new FloatLeg(index.Currency, paymentDates, notionals, resetDates, floatingIndices, spreads, accrualFractions)); }
public void TestQuantoCDS() { var spot = 1.00; var relJumpSizeInDefault = -0.2; var cdsSpread = 0.025; // Trades var anchorDate = new Date(2016, 11, 25); var refEntity = new ReferenceEntity("ABC"); Date[] paymentDates; double[] accrualFractions; DateGenerators.CreateDatesNoHolidays(Tenor.Months(3), anchorDate, 20, out paymentDates, out accrualFractions); var zarNotionals = Vector.Ones(paymentDates.Length).Multiply(1000000.0); var usdNotionals = zarNotionals.Divide(spot); var zarSpreads = Vector.Ones(paymentDates.Length).Multiply(cdsSpread); var usdSpreads = zarSpreads.Multiply(1 + relJumpSizeInDefault); // Adjusted for the FX jump size. var boughtProtection = true; var cdsZAR = new CDS(refEntity, Currency.ZAR, paymentDates, zarNotionals, zarSpreads, accrualFractions, boughtProtection); var cdsUSD = new CDS(refEntity, Currency.USD, paymentDates, zarNotionals, usdSpreads, accrualFractions, boughtProtection); // Model var curveDates = new[] { anchorDate, anchorDate.AddTenor(Tenor.Years(10)) }; var expectedRecovery = 0.4; var hazardRates = new[] { cdsSpread / (1 - expectedRecovery), cdsSpread / (1 - expectedRecovery) }; var usdRates = new[] { 0.01, 0.02 }; var zarRates = new[] { 0.07, 0.08 }; IDiscountingSource usdDiscountCurve = new DatesAndRates(Currency.USD, anchorDate, curveDates, usdRates); IDiscountingSource zarDiscountCurve = new DatesAndRates(Currency.ZAR, anchorDate, curveDates, zarRates); ISurvivalProbabilitySource abcHazardCurve = new HazardCurve(refEntity, anchorDate, curveDates, hazardRates); var otherCurrency = Currency.USD; var fxSource = new FXForecastCurve(otherCurrency, Currency.ZAR, spot, usdDiscountCurve, zarDiscountCurve); var fxVol = 0.15; NumeraireSimulator model = new DeterministicCreditWithFXJump(abcHazardCurve, otherCurrency, fxSource, zarDiscountCurve, fxVol, relJumpSizeInDefault, expectedRecovery); // Valuation var N = 5000; var coord = new Coordinator(model, new List <Simulator>(), N); var zarValue = coord.Value(new Product[] { cdsZAR }, anchorDate); var usdValue = coord.Value(new Product[] { cdsUSD }, anchorDate); Assert.AreEqual(0.0, zarValue, 800.0); // about 2bp Assert.AreEqual(0.0, usdValue, 800.0); // about 2bp }
public void TestQuantoCDS() { var spot = 1.00; var relJumpSizeInDefault = -0.2; var cdsSpread = 0.025; // Trades var anchorDate = new Date(2016, 11, 25); var refEntity = TestHelpers.TestCp; DateGenerators.CreateDatesNoHolidays(Tenor.FromMonths(3), anchorDate, 20, out var paymentDates, out var accrualFractions); var zarNotionals = Vector.Ones(paymentDates.Length).Multiply(1000000.0); var zarSpreads = Vector.Ones(paymentDates.Length).Multiply(cdsSpread); var usdSpreads = zarSpreads.Multiply(1 + relJumpSizeInDefault); // Adjusted for the FX jump size. var boughtProtection = true; var cdsZAR = new CDS(refEntity, TestHelpers.ZAR, paymentDates, zarNotionals, zarSpreads, accrualFractions, boughtProtection); var cdsUSD = new CDS(refEntity, TestHelpers.USD, paymentDates, zarNotionals, usdSpreads, accrualFractions, boughtProtection); // Model var curveDates = new[] { anchorDate, anchorDate.AddTenor(Tenor.FromYears(10)) }; var expectedRecovery = 0.4; var hazardRates = new[] { cdsSpread / (1 - expectedRecovery), cdsSpread / (1 - expectedRecovery) }; var usdRates = new[] { 0.01, 0.02 }; var zarRates = new[] { 0.07, 0.08 }; var usdDiscountCurve = new DatesAndRates(TestHelpers.USD, anchorDate, curveDates, usdRates); var zarDiscountCurve = new DatesAndRates(TestHelpers.ZAR, anchorDate, curveDates, zarRates); var abcHazardCurve = new HazardCurve(refEntity, anchorDate, curveDates, hazardRates); var fxSource = new FXForecastCurve(TestHelpers.USDZAR, spot, usdDiscountCurve, zarDiscountCurve); var fxVol = 0.15; var model = new DeterministicCreditWithFXJump(abcHazardCurve, TestHelpers.USDZAR, fxSource, zarDiscountCurve, fxVol, relJumpSizeInDefault, expectedRecovery); // Valuation var N = 5000; var coord = new Coordinator(model, new List <Simulator>(), N); var zarValue = coord.Value(new[] { cdsZAR }, anchorDate); var usdValue = coord.Value(new[] { cdsUSD }, anchorDate); Assert.AreEqual(0.0, zarValue, 800.0); // about 2bp Assert.AreEqual(0.0, usdValue, 800.0); // about 2bp }