public void ChainLadder_CalculatesFactorsCorrectly() { IEnumerable <decimal> factors = new List <decimal>() { 1.899454m, 1.3288m, 1.232147m, 1.119969m, 1.044378m }; FactorBasedMethod chainLadder = TestObjectBuilder.CreateChainLadderMethod(); bool calculatedCorrectly = chainLadder.Factors .Zip(factors, (x, y) => Math.Abs(x - Math.Round(y, 6)) <= 1e-6m) .Aggregate(true, (x, y) => x && y); Assert.IsTrue(calculatedCorrectly); }
public void ChainLadder_CalculatesProjectionCorrectly() { ISquare projection = new Square(6); projection.SetRow(new List <decimal>() { 1001m, 1855m, 2423m, 2988m, 3335m, 3483m }, 0); projection.SetRow(new List <decimal>() { 1113m, 2103m, 2774m, 3422m, 3844m, 4014.59m }, 1); projection.SetRow(new List <decimal>() { 1265m, 2433m, 3233m, 3977m, 4454.12m, 4651.78m }, 2); projection.SetRow(new List <decimal>() { 1490m, 2873m, 3880m, 4780.73m, 5354.27m, 5591.88m }, 3); projection.SetRow(new List <decimal>() { 1725m, 3261m, 4333.22m, 5339.16m, 5979.69m, 6245.06m }, 4); projection.SetRow(new List <decimal>() { 1889m, 3588.07m, 4767.82m, 5874.66m, 6579.44m, 6871.42m }, 5); bool calculatedCorrectly = true; IReservingMethod chainLadder = TestObjectBuilder.CreateChainLadderMethod(); for (int i = 0; i < chainLadder.Projection.Periods; i++) { IEnumerable <decimal> row = chainLadder.Projection.GetRow(i); calculatedCorrectly = calculatedCorrectly && row.Zip(projection.GetRow(i), (x, y) => Math.Abs(x - Math.Round(y, 2)) <= 0.01m) .Aggregate(true, (x, y) => x && y); } Assert.IsTrue(calculatedCorrectly); }