Exemple #1
0
        public static object CreateBasisPriceCurve(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Asset Id")] string AssetId,
            [ExcelArgument(Description = "Base curve object")] string BaseCurve,
            [ExcelArgument(Description = "Build date")] DateTime BuildDate,
            [ExcelArgument(Description = "Array of pillar dates")] double[] Pillars,
            [ExcelArgument(Description = "Array of swap objects")] object[,] Swaps,
            [ExcelArgument(Description = "Discount curve name")] string DiscountCurveName,
            [ExcelArgument(Description = "Type of curve, e.g. LME, ICE, NYMEX etc")] object CurveType,
            [ExcelArgument(Description = "Currency")] string Currency,
            [ExcelArgument(Description = "(Optional) Pillar labels")] object PillarLabels)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var curveTypeStr = CurveType.OptionalExcel <string>("Coal");
                if (!Enum.TryParse(curveTypeStr, out PriceCurveType cType))
                {
                    return $"Could not parse price curve type - {curveTypeStr}";
                }

                var irCache = ContainerStores.GetObjectCache <IIrCurve>();
                if (!irCache.TryGetObject(DiscountCurveName, out var irCurveObj))
                {
                    return $"Could not find ir curve with name {DiscountCurveName}";
                }
                var irCurve = irCurveObj.Value;

                var curveCache = ContainerStores.GetObjectCache <IPriceCurve>();
                if (!curveCache.TryGetObject(BaseCurve, out var bCurveObj))
                {
                    return $"Could not find ir curve with name {DiscountCurveName}";
                }
                var baseCurve = bCurveObj.Value;

                var pf = Instruments.InstrumentFunctions.GetPortfolio(Swaps);
                var ccy = ContainerStores.CurrencyProvider.GetCurrency(Currency);

                var labels = PillarLabels is ExcelMissing ? null : ((object[, ])PillarLabels).ObjectRangeToVector <string>().ToList();

                var pDates = Pillars.ToDateTimeArray().ToList();
                var cObj = new BasisPriceCurve(pf.Instruments.Where(x => x is IAssetInstrument).Select(x => x as IAssetInstrument).ToList(), pDates, irCurve, baseCurve, BuildDate, cType, new Models.Calibrators.NewtonRaphsonAssetBasisCurveSolver(ContainerStores.CurrencyProvider), labels)
                {
                    Name = ObjectName,
                    AssetId = AssetId,
                    Currency = ccy
                };

                curveCache.PutObject(ObjectName, new SessionItem <IPriceCurve> {
                    Name = ObjectName, Value = cObj
                });
                return ObjectName + '¬' + curveCache.GetObject(ObjectName).Version;
            }));
        }
Exemple #2
0
        public void StripCrackedCurveAsBasisCurve()
        {
            var buildDate = new DateTime(2018, 07, 28);

            string[] futures       = { "COV8", "COX8", "COZ8", "COF9", "COG9" };
            double[] futuresPrices = { 77, 78, 79, 79.5, 79.75 };
            string[] periods       = { "AUG18", "SEP18", "OCT18", "NOV18" };
            double[] strikes       = { -10, -11, -12, -13 };

            var cal = TestProviderHelper.CalendarProvider.Collection["LON"];
            var usd = TestProviderHelper.CurrencyProvider["USD"];

            var bPillars   = futures.Select(x => FutureCode.GetExpiryFromCode(x, TestProviderHelper.FutureSettingsProvider)).ToArray();
            var brentCurve = new PriceCurve(buildDate, bPillars, futuresPrices, PriceCurveType.ICE, TestProviderHelper.CurrencyProvider, futures)
            {
                AssetId = "Brent"
            };


            var instruments = periods.Select((p, ix) =>
                                             (IAssetInstrument)AssetProductFactory.CreateTermAsianBasisSwap(p, strikes[ix], "Brent", "Sing180", cal, cal, cal, 0.Bd(), usd, 0.Bd(), 0.Bd(), 1000, 1000 / 6.35))
                              .ToList();
            var pillars = instruments.Select(x => ((AsianBasisSwap)x).RecSwaplets.Max(sq => sq.AverageEndDate)).ToList();

            DateTime[] dPillars      = { buildDate, buildDate.AddDays(1000) };
            double[]   dRates        = { 0, 0 };
            var        discountCurve = new IrCurve(dPillars, dRates, buildDate, "zeroDiscount", Interpolator1DType.LinearFlatExtrap, usd);

            var curve = new BasisPriceCurve(instruments, pillars, discountCurve, brentCurve, buildDate, PriceCurveType.NYMEX, TestProviderHelper.CurrencyProvider);

            for (var i = 0; i < instruments.Count; i++)
            {
                var resultPV = Calibrators.NewtonRaphsonAssetBasisCurveSolver.BasisSwapPv(curve, instruments[i], discountCurve, brentCurve);
                Assert.Equal(0, resultPV, 6);
            }

            var curve2 = curve.Clone();

            for (var i = 0; i < instruments.Count; i++)
            {
                var resultPV = Calibrators.NewtonRaphsonAssetBasisCurveSolver.BasisSwapPv(curve2, instruments[i], discountCurve, brentCurve);
                Assert.Equal(0, resultPV, 6);
            }
        }