Ejemplo n.º 1
0
 public static object CreateHazzardCurveFromCDSs(
     [ExcelArgument(Description = "Object name")] string ObjectName,
     [ExcelArgument(Description = "Origin date")] DateTime OriginDate,
     [ExcelArgument(Description = "CDSs")] object[,] CDSs,
     [ExcelArgument(Description = "Recovery Rate")] double RecoveryRate,
     [ExcelArgument(Description = "Discount Curve")] string DiscountCurve)
 {
     return(ExcelHelper.Execute(_logger, () =>
     {
         var cdsObjects = ExcelHelper.GetAnyFromCache <CDS>(CDSs);
         var disco = ContainerStores.GetObjectCache <IIrCurve>().GetObjectOrThrow(DiscountCurve, $"Could not find discount curve {DiscountCurve}");
         var solver = new NewtonRaphsonCreditCurveSolver();
         var hzCurve = solver.Solve(cdsObjects.ToList(), RecoveryRate, disco.Value, OriginDate);
         return ExcelHelper.PushToCache(hzCurve, ObjectName);
     }));
 }
Ejemplo n.º 2
0
        public void CDSStripperFacts()
        {
            var origin = new DateTime(2020, 06, 15);
            var usd    = TestProviderHelper.CurrencyProvider.GetCurrency("USD");
            var df     = new ConstantRateIrCurve(0.05, origin, "LIBOR", usd);

            var data = new Tuple <Frequency, double>[]
            {
                new Tuple <Frequency, double>(1.Years(), 0.01),
                new Tuple <Frequency, double>(2.Years(), 0.012),
                new Tuple <Frequency, double>(3.Years(), 0.013),
                new Tuple <Frequency, double>(4.Years(), 0.0135),
                new Tuple <Frequency, double>(5.Years(), 0.014),
            };

            var cdses = data.Select(d => new CDS()
            {
                Basis      = DayCountBasis.ACT365F,
                Currency   = usd,
                OriginDate = origin,
                Tenor      = d.Item1,
                Spread     = d.Item2,
                Notional   = 1e6
            }).ToList();

            foreach (var cds in cdses)
            {
                cds.Init();
            }

            var sut = new NewtonRaphsonCreditCurveSolver
            {
                UseSmallSteps = true
            };

            var hz = sut.Solve(cdses, 0.4, df, origin);

            var pz = cdses.Select(c => hz.GetSurvivalProbability(c.FinalSensitivityDate));

            foreach (var p in pz)
            {
                Assert.True(!double.IsNaN(p));
            }
        }