internal static void AssertCurveConsistentWithInputs <T>(IEnumerable <Contract <T> > inputContracts, Func <T, double> weighting, DoubleCurve <T> curve, double tolerance) where T : ITimePeriod <T> { foreach (var inputContract in inputContracts) { var weightedAverageCurvePrice = curve.Price(inputContract.Start, inputContract.End); Assert.AreEqual(inputContract.Price, weightedAverageCurvePrice, tolerance); } }
public void Price_EmptyCurve_ThrowsInvalidOperationException() { DoubleCurve <Month> emptyCurve = DoubleCurve <Month> .Empty; Assert.Throws <InvalidOperationException>(() => { // ReSharper disable once UnusedVariable var price = emptyCurve.Price(Month.CreateJanuary(2020)); }); }
public void Price_MonthlyCurveBusinessDayWeight_EqualsWeightedAverage() { var curve = new DoubleCurve <Month>(Month.CreateJanuary(2020), new[] { 56.54, 54.15, 51.14 }, Weighting.BusinessDayCount <Month>(new Day[0])); double q1Price = curve.Price(Quarter.CreateQuarter1(2020)); const double expectedQ1Price = (56.54 * 23.0 + 54.15 * 20.0 + 51.14 * 22.0) / 65.0; Assert.AreEqual(expectedQ1Price, q1Price); }
public void PriceStartAndEndParameters_MonthlyCurveBusinessDayWeight_EqualsWeightedAverage() { var curve = new DoubleCurve <Month>(Month.CreateJanuary(2020), new [] { 56.54, 54.15, 51.14 }, Weighting.BusinessDayCount <Month>(new Day[0])); double febMarPrice = curve.Price(Month.CreateFebruary(2020), Month.CreateMarch(2020)); const double expectedFebMarPrice = (54.15 * 20.0 + 51.14 * 22.0) / 42.0; Assert.AreEqual(expectedFebMarPrice, febMarPrice); }
public void BuilderWithData_ConstructedWithCapacityParameter_AddsPointsToBuiltSeries() { var curve = new DoubleCurve <Month> .Builder(1, month => 1.0) .WithData(Month.CreateJanuary(2019), 1.0) .WithData(Month.CreateFebruary(2019), 2.0) .WithData(Month.CreateMarch(2019), 3.0) .Build(); Assert.AreEqual(3, curve.Count); Assert.AreEqual(1.0, curve[Month.CreateJanuary(2019)]); Assert.AreEqual(2.0, curve[Month.CreateFebruary(2019)]); Assert.AreEqual(3.0, curve[Month.CreateMarch(2019)]); Assert.AreEqual(2.0, curve.Price(Quarter.CreateQuarter1(2019))); }
public void BuilderBuild_ConstructedWithCapacityParameter_AsExpected() { var curve = new DoubleCurve <Month> .Builder(2, month => 1.0) { { Month.CreateJanuary(2019), 1.0 }, { Month.CreateFebruary(2019), 2.0 }, { Month.CreateMarch(2019), 3.0 } } .Build(); Assert.AreEqual(3, curve.Count); Assert.AreEqual(1.0, curve[Month.CreateJanuary(2019)]); Assert.AreEqual(2.0, curve[Month.CreateFebruary(2019)]); Assert.AreEqual(3.0, curve[Month.CreateMarch(2019)]); Assert.AreEqual(2.0, curve.Price(Quarter.CreateQuarter1(2019))); }