Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ifrs17/Import/ImportScopeCalculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
"\n{",
"\n private double[] NominalClaimsCashflow => GetStorage().GetClaims()",
"\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))",
"\n .Aggregate();",
"\n .AggregateDoubleArray();",
"\n ",
"\n private double nonPerformanceRiskRate => GetStorage().GetNonPerformanceRiskRate(Identity.Id);",
"\n ",
Expand All @@ -566,7 +566,7 @@
"\n{",
"\n double[] NominalCashflow.Values => GetStorage().GetClaims()",
"\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))",
"\n .Aggregate();",
"\n .AggregateDoubleArray();",
"\n}"
],
"metadata": {},
Expand Down Expand Up @@ -691,7 +691,7 @@
"\n .Values",
"\n .Select(aoc => GetScope<DiscountedCashflow>((Identity.Id with {AocType = aoc.AocType, Novelty = aoc.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.Accidentyear)).Values)",
"\n .Where(cf => cf.Count() > 0)",
"\n .Aggregate();",
"\n .AggregateDoubleArray();",
"\n ",
"\n double[] Values => Subtract(CurrentValues, PreviousValues);",
"\n}"
Expand Down
131 changes: 131 additions & 0 deletions ifrs17/Test/AggregateDoubleArrayTest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"metadata": {
"authors": [],
"kernelspec": {
"display_name": "Formula Framework",
"language": "C#",
"name": "C#"
},
"language_info": {
"file_extension": ".cs",
"mimetype": "text/plain",
"name": "C#"
}
},
"nbformat": 4,
"nbformat_minor": 5,
"cells": [
{
"cell_type": "code",
"source": [
"#!import \"../Utils/Extensions\"",
"\n#!import \"../Utils/TestHelper\""
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public void CheckAggregateDoubleArray(double[][] arrayOfDoubleArrays, double[] bmAggregatedArray)",
"\n{",
"\n var aggregatedArray = arrayOfDoubleArrays.AggregateDoubleArray();",
"\n aggregatedArray.Should().BeEquivalentTo(bmAggregatedArray);",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"var array = new double [] [] {new[] {-100d,-50d }, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,}, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,}, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,} };",
"\nCheckAggregateDoubleArray(array, new[] {-400d,-200d,-150d,-150d,0d,0d,0d,0d, 0d,0d,})"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {null, new[] {-100d,-50d }};",
"\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {new[] {-100d,-50d }, null};",
"\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {Enumerable.Empty<double>().ToArray(), new[] {-100d,-50d }};",
"\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {Enumerable.Empty<double>().ToArray(), Enumerable.Empty<double>().ToArray()};",
"\nCheckAggregateDoubleArray(array, Enumerable.Empty<double>().ToArray())"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {new[] {-100d,-50d }};",
"\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {Enumerable.Empty<double>().ToArray()};",
"\nCheckAggregateDoubleArray(array, Enumerable.Empty<double>().ToArray())"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"array = new double [] [] {null};",
"\nCheckAggregateDoubleArray(array, Enumerable.Empty<double>().ToArray())"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {},
"execution_count": 0,
"outputs": []
}
]
}
9 changes: 9 additions & 0 deletions ifrs17/Test/Tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#!eval-notebook \"AggregateDoubleArrayTest\""
],
"metadata": {},
"execution_count": 0,
"outputs": []
}
]
}
38 changes: 37 additions & 1 deletion ifrs17/Utils/Extensions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Loading external dependencies"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#r \"nuget:morelinq\""
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"using static MoreLinq.Extensions.ZipLongestExtension;"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
Expand Down Expand Up @@ -96,7 +123,16 @@
{
"cell_type": "code",
"source": [
"public static double[] Prune (this IEnumerable<double> source, double precision = Precision) => source.Reverse().SkipWhile(x => Math.Abs(x) < precision).Reverse().ToArray();"
"public static double[] Prune(this IEnumerable<double> source, double precision = Precision) => source.Reverse().SkipWhile(x => Math.Abs(x) < precision).Reverse().ToArray();"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public static double[] AggregateDoubleArray(this IEnumerable<IEnumerable<double>> source) => source.Where(x => x is not null).DefaultIfEmpty(Enumerable.Empty<double>()).Aggregate((x, y) => x.ZipLongest(y, (a, b) => a + b)).ToArray();"
],
"metadata": {},
"execution_count": 0,
Expand Down