public void ContangoPriceCurveFact() { var pillars = new[] { DateTime.Today.AddDays(100), DateTime.Today.AddDays(200) }; var rates = new[] { 0.1, 0.2 }; var sut = new ContangoPriceCurve(DateTime.Today, 100.0, DateTime.Today, pillars, rates, TestProviderHelper.CurrencyProvider); Assert.Equal(PriceCurveType.Linear, sut.CurveType); Assert.False(sut.UnderlyingsAreForwards); Assert.True(Enumerable.SequenceEqual(pillars, sut.PillarDates)); Assert.Equal(pillars.Length, sut.NumberOfPillars); Assert.Equal(100.0 * (1.0 + 100.0 / 360.0 * 0.1), sut.GetPriceForDate(pillars[0])); Assert.Equal(100.0 * (1.0 + 100.0 / 360.0 * 0.1), sut.GetPriceForFixingDate(pillars[0])); Assert.Equal(100.0 * (1.0 + 100.0 / 360.0 * 0.1), sut.GetAveragePriceForDates(new[] { pillars[0] })); Assert.Equal(100.0 * (1.0 + 150.0 / 360.0 * 0.15), sut.GetPriceForDate(DateTime.Today.AddDays(150))); Assert.Equal(DateTime.Today, sut.PillarDatesForLabel("Spot")); Assert.Equal(DateTime.Today.AddDays(100), sut.PillarDatesForLabel(DateTime.Today.AddDays(100).ToString("yyyy-MM-dd"))); var rb = sut.RebaseDate(DateTime.Today.AddDays(1)); Assert.Equal(DateTime.Today.AddDays(1), rb.BuildDate); var ds = sut.GetDeltaScenarios(0.1, null); Assert.Equal("Spot", ds.First().Key); }
public static object CreateContangoPriceCurve( [ExcelArgument(Description = "Object name")] string ObjectName, [ExcelArgument(Description = "Asset Id")] string AssetId, [ExcelArgument(Description = "Build date")] DateTime BuildDate, [ExcelArgument(Description = "Spot date")] DateTime SpotDate, [ExcelArgument(Description = "Spot price")] double SpotPrice, [ExcelArgument(Description = "Array of pillar dates")] double[] Pillars, [ExcelArgument(Description = "Array of contango values")] double[] ContangoRates, [ExcelArgument(Description = "Array of pillar labels (optional)")] object PillarLabels, [ExcelArgument(Description = "Spot lag (default 2b)")] object SpotLag, [ExcelArgument(Description = "Spot calendar (default USD)")] object SpotCalendar) { return(ExcelHelper.Execute(_logger, () => { var labels = (PillarLabels is ExcelMissing) ? null : ((object[, ])PillarLabels).ObjectRangeToVector <string>(); var pDates = Pillars.ToDateTimeArray(); ContainerStores.CalendarProvider.Collection.TryGetCalendar(SpotCalendar.OptionalExcel("Weekends"), out var spotCal); var cObj = new ContangoPriceCurve(BuildDate, SpotPrice, SpotDate, pDates, ContangoRates, ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>(), DayCountBasis.Act360, labels) { Name = AssetId ?? ObjectName, AssetId = AssetId ?? ObjectName, SpotLag = new Frequency(SpotLag.OptionalExcel("2b")), SpotCalendar = spotCal }; return ExcelHelper.PushToCache <IPriceCurve>(cObj, ObjectName); })); }