Beispiel #1
0
        public static object CreateDiscountCurveFromDFs(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Curve name")] object CurveName,
            [ExcelArgument(Description = "Build date")] DateTime BuildDate,
            [ExcelArgument(Description = "Array of pillar dates")] double[] Pillars,
            [ExcelArgument(Description = "Array of discount factors")] double[] DiscountFactors,
            [ExcelArgument(Description = "Type of interpolation")] object InterpolationType,
            [ExcelArgument(Description = "Currency - default USD")] object Currency,
            [ExcelArgument(Description = "Collateral Spec - default LIBOR.3M")] object CollateralSpec,
            [ExcelArgument(Description = "Rate storage format - default Exponential")] object RateStorageType)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var curveName = CurveName.OptionalExcel(ObjectName);
                var curveTypeStr = InterpolationType.OptionalExcel("Linear");
                var ccyStr = Currency.OptionalExcel("USD");
                var colSpecStr = CollateralSpec.OptionalExcel("LIBOR.3M");
                var rateTypeStr = RateStorageType.OptionalExcel("CC");

                if (!Enum.TryParse(curveTypeStr, out Interpolator1DType iType))
                {
                    return $"Could not parse interpolator type - {curveTypeStr}";
                }

                if (!Enum.TryParse(rateTypeStr, out RateType rType))
                {
                    return $"Could not parse rate type - {rateTypeStr}";
                }

                var pDates = Pillars.ToDateTimeArray();
                ContainerStores.SessionContainer.GetService <ICalendarProvider>().Collection.TryGetCalendar(ccyStr, out var ccyCal);
                var ccy = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>()[ccyStr];

                var zeroRates = DiscountFactors
                                .Select((df, ix) =>
                                        DateTime.FromOADate(Pillars[ix]) == BuildDate ? 0.0
                    : IrCurve.RateFromDF(BuildDate.CalculateYearFraction(DateTime.FromOADate(Pillars[ix]), DayCountBasis.ACT365F), df, rType))
                                .ToArray();

                if (DateTime.FromOADate(Pillars[0]) == BuildDate && zeroRates.Length > 1)
                {
                    zeroRates[0] = zeroRates[1];
                }

                var cObj = new IrCurve(pDates, zeroRates, BuildDate, curveName, iType, ccy, colSpecStr, rType);
                return ExcelHelper.PushToCache <IIrCurve>(cObj, ObjectName);
            }));
        }
Beispiel #2
0
        public void IrCurveConversionFacts()
        {
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.Annual));
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.CC));
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.Linear));
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.SemiAnnual));
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.Quarterly));
            Assert.Equal(1.0, IrCurve.DFFromRate(0.0, 0.1, RateType.Monthly));
            Assert.Equal(0.1, IrCurve.DFFromRate(0.0, 0.1, RateType.DiscountFactor));

            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.Annual));
            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.CC));
            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.Linear));
            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.SemiAnnual));
            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.Quarterly));
            Assert.Equal(0.0, IrCurve.RateFromDF(1.0, 1.0, RateType.Monthly));
            Assert.Equal(1.0, IrCurve.RateFromDF(1.0, 1.0, RateType.DiscountFactor));
        }