From 9e4c8608c181d20d27c99779e68fbb3d9c19a988 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Tue, 7 Mar 2023 18:16:08 +0100 Subject: [PATCH 01/11] enable scenario switch --- .../Test/ScenarioDataImportTest.ipynb | 99 ++++++++++--------- .../Test/ScenarioYieldCurveImportTest.ipynb | 61 ++++++++++-- ifrs17/Constants/Consts.ipynb | 2 +- 3 files changed, 107 insertions(+), 55 deletions(-) diff --git a/ifrs17-template/Test/ScenarioDataImportTest.ipynb b/ifrs17-template/Test/ScenarioDataImportTest.ipynb index 5b3c3ea9..3c558fcd 100644 --- a/ifrs17-template/Test/ScenarioDataImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioDataImportTest.ipynb @@ -52,6 +52,24 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var EnableScenarioBackup = EnableScenario;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = true;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -226,11 +244,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().Be(0);", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n diffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);", - "\n}" + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -286,11 +302,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().NotBe(0);", - "\n cashflowVars.Length.Should().Be(0);", - "\n diffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);", - "\n}" + "actualVars.Length.Should().NotBe(0);", + "\ncashflowVars.Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -355,11 +369,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().Be(0);", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n diffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);", - "\n}" + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -416,11 +428,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", - "\n diffs.Where(x => x.EstimateType == EstimateTypes.F).ToArray().Length.Should().Be(0);", - "\n diffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);", - "\n}" + "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.F).ToArray().Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -483,11 +493,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", - "\n ivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.F).Count().Should().NotBe(0);", - "\n ivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.DA && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", - "\n}" + "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "\nivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.F).Count().Should().NotBe(0);", + "\nivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.DA && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -569,7 +577,7 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) diffs.Count().Should().Be(0);" + "diffs.Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -663,10 +671,8 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", - "\n diffs.Where(x => onlyActualETs.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", - "\n}" + "diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", + "\ndiffs.Where(x => onlyActualETs.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -726,11 +732,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n actualVars.Length.Should().Be(0);", - "\n diffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);", - "\n}" + "cashflowVars.Length.Should().NotBe(0);", + "\nactualVars.Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -810,11 +814,9 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().Be(0);", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n cashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);", - "\n}" + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);", + "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -927,10 +929,17 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().Be(0);", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n}" + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Restore Constants" ], "metadata": {}, "execution_count": 0, @@ -939,7 +948,7 @@ { "cell_type": "code", "source": [ - "" + "EnableScenario = EnableScenarioBackup;" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index bd8e71e2..2b647ce9 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -52,6 +52,24 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var EnableScenarioBackup = EnableScenario;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = true;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -258,10 +276,8 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) {", - "\n actualVars.Length.Should().Be(0);", - "\n cashflowVars.Length.Should().NotBe(0);", - "\n}" + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, @@ -307,7 +323,7 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) diffs.Count().Should().Be(0);" + "diffs.Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -370,7 +386,7 @@ "var bestEstimateYieldCurve = @\"", "\n@@Main", "\nYear,Month", - "\n2020,12", + "\n2020,1", "\n@@YieldCurve", "\nCurrency,Values0,Values1,Values2,Values3", "\nEUR,0.108,0.108,0.118,0.119", @@ -421,7 +437,16 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) if(EnableScenario) diffs.Count().Should().NotBe(0);" + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs" ], "metadata": {}, "execution_count": 0, @@ -458,7 +483,7 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) diffs.Count().Should().Be(0);" + "diffs.Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -495,7 +520,25 @@ { "cell_type": "code", "source": [ - "if(EnableScenario) diffs.Count().Should().NotBe(0);" + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Restore Constants" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = EnableScenarioBackup;" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Constants/Consts.ipynb b/ifrs17/Constants/Consts.ipynb index 2bd61cb2..6546cdf9 100644 --- a/ifrs17/Constants/Consts.ipynb +++ b/ifrs17/Constants/Consts.ipynb @@ -28,7 +28,7 @@ { "cell_type": "code", "source": [ - "public const bool EnableScenario = false;" + "public bool EnableScenario = false;" ], "metadata": {}, "execution_count": 0, From f426c2b8ef79075a2df076329555c20b897cceda Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Wed, 8 Mar 2023 11:04:58 +0100 Subject: [PATCH 02/11] fix and improve existing scenario tests --- .../Test/ScenarioParametersImportTest.ipynb | 38 ++++++ .../Test/ScenarioYieldCurveImportTest.ipynb | 126 +++++++++++++++--- ifrs17-template/Test/Tests.ipynb | 9 ++ ifrs17/Utils/Queries.ipynb | 5 +- 4 files changed, 161 insertions(+), 17 deletions(-) create mode 100644 ifrs17-template/Test/ScenarioParametersImportTest.ipynb diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb new file mode 100644 index 00000000..60b1326e --- /dev/null +++ b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb @@ -0,0 +1,38 @@ +{ + "metadata": { + "authors": [], + "id": "8AGRn6EDjEm0Kvo27RJFPw", + "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": "markdown", + "source": [ + "

Scenario Parameters Import Test

" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index 2b647ce9..ff48c683 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -286,7 +286,7 @@ { "cell_type": "markdown", "source": [ - "# Re-Import of the same Yield Curve does not trigger IFRS17 Calculations" + "# Re-Import of the same yield curve should not trigger IFRS17 Calculations" ], "metadata": {}, "execution_count": 0, @@ -332,7 +332,7 @@ { "cell_type": "markdown", "source": [ - "# Multiple Scenarios ", + "# Multiple Scenarios: re-import of Best Estimate yield curve", "\n", "\nIn this example, a new Cashflow for a different Scenario - SRUP1.0pct - is imported. ", "\nThe aim is to check how the Yield Curve importer behaves when a new Best Estimate Yield Curve is imported. ", @@ -386,12 +386,10 @@ "var bestEstimateYieldCurve = @\"", "\n@@Main", "\nYear,Month", - "\n2020,1", + "\n2020,12", "\n@@YieldCurve", "\nCurrency,Values0,Values1,Values2,Values3", - "\nEUR,0.108,0.108,0.118,0.119", - "\nCHF,0.103,0.103,0.103,0.103", - "\nUSD,0.903,0.103,0.103,0.103\";" + "\nUSD,0.006,0.004,0.004,0.005\";" ], "metadata": {}, "execution_count": 0, @@ -443,15 +441,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "diffs" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -526,6 +515,113 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Influence on the future: import of yield curve for previous month should not update current results" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var bestEstimateYieldCurvePast = @\"", + "\n@@Main", + "\nYear,Month", + "\n2020,6", + "\n@@YieldCurve", + "\nCurrency,Values0,Values1,Values2,Values3", + "\nUSD,0.123,0.123,0.123,0.123\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(bestEstimateYieldCurvePast).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Best Estimate should not change" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateImportPast = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsBestEstimateImportPast.Except(ivsBestEstimateUpdated, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario should not change" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioYieldCurve);", + "\nvar ivsScenarioYieldCurveImportPast = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioYieldCurveImportPast.Except(ivsScenarioYieldCurveUpdated, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17-template/Test/Tests.ipynb b/ifrs17-template/Test/Tests.ipynb index 969379fe..4a12e27e 100644 --- a/ifrs17-template/Test/Tests.ipynb +++ b/ifrs17-template/Test/Tests.ipynb @@ -71,6 +71,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"ScenarioParametersImportTest\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 87c7706a..af7021f4 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -436,11 +436,12 @@ "\n where T : IPartitioned", "\n where P : IPartition", "\n{", - "\n var partitionBackup = (Guid)querySource.Partition.GetCurrent(typeof(P).Name);", + "\n var partitionBackup = (Guid)(querySource.Partition.GetCurrent(typeof(P).Name)?? default(Guid));", "\n await querySource.Partition.SetAsync

(partition);", "\n // Temporary workaround for physical database: where clause is necessary", "\n var data = await querySource.Query().Where(x => x.Partition == partition).ToArrayAsync();", - "\n await querySource.Partition.SetAsync

(partitionBackup);", + "\n if(partitionBackup == default(Guid)) await querySource.Partition.SetAsync

(null);", + "\n else await querySource.Partition.SetAsync

(partitionBackup);", "\n return data;", "\n}" ], From 720bbfa182f765474899a358ad0382e13c352712 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Wed, 8 Mar 2023 17:31:51 +0100 Subject: [PATCH 03/11] bug fix import yield curve --- .../Test/ScenarioParametersImportTest.ipynb | 185 ++++++++++++++++++ .../Test/ScenarioYieldCurveImportTest.ipynb | 111 ++++++++++- ifrs17/Import/Importers.ipynb | 14 +- 3 files changed, 301 insertions(+), 9 deletions(-) diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb index 60b1326e..50e4f4fc 100644 --- a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb @@ -25,6 +25,191 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "DataSource.Reset(x => x.ResetType().ResetType()", + "\n .ResetType().ResetType());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Setting Constants" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var EnableScenarioBackup = EnableScenario;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = true;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var ws = Workspace.CreateNew();", + "\nws.InitializeFrom(DataSource);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenarioYieldCurve = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"YCUP1.0pct\", ImportFormats.Cashflow);", + "\nvar argsScenarioTransactionalData = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"SRUP1.0pct\", ImportFormats.Cashflow);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", + "\nawait initStorage.InitializeAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actualEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Actual];", + "\nvar cashflowEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Cashflow];", + "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", + "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Best Estimate initialization" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowBestEstimateInit = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Cashflow", + "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", + "\nDT1.1,PR,BE,CL,C,,100,0,0,100,0,0,100,0,0,100,0,0,0,100,0,0,100,0,0,100,0,0,100,0", + "\nDT1.1,NIC,BE,CL,C,,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25", + "\nDT1.1,,CU,CL,C,,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", + "\nDT1.1,,RA,CL,C,,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5", + "\nDTR1.1,PR,BE,CL,C,,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0", + "\nDTR1.1,NIC,BE,CL,C,,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5", + "\nDTR1.1,,CU,CL,C,,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5", + "\nDTR1.1,,RA,CL,C,,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowBestEstimateInit).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateInit = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index ff48c683..57245c6d 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -85,7 +85,9 @@ "source": [ "var argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", "\nvar argsScenarioYieldCurve = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"YCUP1.0pct\", ImportFormats.Cashflow);", - "\nvar argsScenarioTransactionalData = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"SRUP1.0pct\", ImportFormats.Cashflow);" + "\nvar argsScenarioTransactionalData = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"SRUP1.0pct\", ImportFormats.Cashflow);", + "\nvar argsBestEstimateNextPeriod = new ImportArgs (\"CH\", 2021, 3, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenarioYieldCurveNextPeriod = new ImportArgs (\"CH\", 2021, 3, Periodicity.Quarterly, \"YCDW1.0pct\", ImportFormats.Cashflow);" ], "metadata": {}, "execution_count": 0, @@ -622,6 +624,113 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Next period imports" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowBestEstimateNextPeriod = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2021,3", + "\n@@Cashflow", + "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", + "\nDT1.1,PR,BE,CL,C,,80,0,0,80,0,0,80,0,0,80,0,0,0,80,0,0,80,0,0,80,0,0,80,0", + "\nDT1.1,NIC,BE,CL,C,,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3", + "\nDT1.1,,RA,CL,C,,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var yieldCurveScenarioNextPeriod = @\"", + "\n@@Main", + "\nYear,Month,Scenario", + "\n2021,3,YCDW1.0pct", + "\n@@YieldCurve", + "\nCurrency,Values0,Values1,Values2,Values3", + "\nUSD,0.007,0.004,0.004,0.005\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowBestEstimateNextPeriod).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(yieldCurveScenarioNextPeriod).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Results with economic basis locked in basis should not be affected" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimateNextPeriod);", + "\nvar ivsBestEstimateNextPeriod = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioYieldCurveNextPeriod);", + "\nvar ivsScenarioYieldCurveNextPeriod = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioYieldCurveNextPeriod.Except(ivsBestEstimateNextPeriod, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Where(x => x.EconomicBasis == EconomicBases.C).Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EconomicBasis == EconomicBases.L).Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 3dc162d6..9c4db10f 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -814,13 +814,12 @@ "\n primaryArgs.ValidateArgsForPeriod();", "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", "\n var workspace = Workspace.CreateNew();", - "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization()", - "\n .DisableInitialization().DisableInitialization());", + "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization().DisableInitialization());", "\n", "\n var committedYieldCurves = await options.TargetDataSource.Query().ToArrayAsync();", "\n var hasNameColumn = dataSet.Tables[ImportFormats.YieldCurve].Columns.Any(x => x.ColumnName == nameof(YieldCurve.Name));", - "\n var importLog = await Import.FromDataSet(dataSet).WithType((dataset, datarow) => { ", - "\n var yieldCurve = new YieldCurve { ", + "\n var importLog = await Import.FromDataSet(dataSet).WithType(", + "\n (dataset, datarow) => new YieldCurve {", "\n Currency = datarow.Field(nameof(YieldCurve.Currency)),", "\n Year = primaryArgs.Year,", "\n Month = primaryArgs.Month, ", @@ -828,12 +827,11 @@ "\n Values = datarow.Table.Columns.Where(c => c.ColumnName.StartsWith(nameof(YieldCurve.Values))).OrderBy(c => c.ColumnName.Length).ThenBy(c => c.ColumnName)", "\n .Select(x => datarow.Field(x.ColumnName).CheckStringForExponentialAndConvertToDouble()).ToArray(),", "\n Name = hasNameColumn ? datarow.Field(nameof(YieldCurve.Name)) : default(string)", - "\n };", - "\n return committedYieldCurves.Contains(yieldCurve, YieldCurveComparer.Instance()) ? null : yieldCurve;", - "\n }).WithTarget(workspace).ExecuteAsync(); ", + "\n }", + "\n ).WithTarget(workspace).ExecuteAsync(); ", "\n", "\n if(importLog.Errors.Any()) return Activity.Finish().Merge(importLog); ", - "\n var toCommitYieldCurves = await workspace.Query().ToArrayAsync();", + "\n var toCommitYieldCurves = (await workspace.Query().ToArrayAsync()).Except(committedYieldCurves, YieldCurveComparer.Instance());", "\n if (!toCommitYieldCurves.Any()) {", "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", "\n return Activity.Finish().Merge(importLog);", From 5400012a72e91899c8b476713e8bb3e8972aaad2 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Fri, 10 Mar 2023 09:17:50 +0100 Subject: [PATCH 04/11] parameter import done, tests green --- .../Test/ScenarioDataImportTest.ipynb | 83 ++-- .../Test/ScenarioParametersImportTest.ipynb | 408 ++++++++++++++++-- .../Test/ScenarioYieldCurveImportTest.ipynb | 41 +- ifrs17/Constants/Consts.ipynb | 54 ++- ifrs17/Import/ImportStorage.ipynb | 2 +- ifrs17/Import/Importers.ipynb | 111 +++-- ifrs17/Report/ReportMutableScopes.ipynb | 10 +- ifrs17/Utils/EqualityComparers.ipynb | 29 ++ ifrs17/Utils/Queries.ipynb | 4 +- 9 files changed, 581 insertions(+), 161 deletions(-) diff --git a/ifrs17-template/Test/ScenarioDataImportTest.ipynb b/ifrs17-template/Test/ScenarioDataImportTest.ipynb index 3c558fcd..bc8e241a 100644 --- a/ifrs17-template/Test/ScenarioDataImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioDataImportTest.ipynb @@ -70,16 +70,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "var ws = Workspace.CreateNew();", - "\nws.InitializeFrom(DataSource);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -93,21 +83,12 @@ { "cell_type": "code", "source": [ - "var initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", - "\nawait initStorage.InitializeAsync();" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var actualETs = initStorage.EstimateTypesByImportFormat[ImportFormats.Actual];", - "\nvar cashflowETs = initStorage.EstimateTypesByImportFormat[ImportFormats.Cashflow];", - "\nvar actualOrCashflowETs = actualETs.Intersect(cashflowETs);", - "\nvar onlyActualETs = actualETs.Except(cashflowETs);", - "\nvar onlyCashflowETs = cashflowETs.Except(actualETs);" + "var estimateTypes = (await DataSource.Query().ToArrayAsync());", + "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", + "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", + "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", + "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], "metadata": {}, "execution_count": 0, @@ -233,9 +214,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioInitCashFlows = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioInitCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -291,9 +272,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioInitActuals = DataSource.Query().ToArray();", "\nvar diffs = ivsScenarioInitActuals.Except(ivsScenarioInitCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -358,9 +339,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioCashflowUpdateCU = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioCashflowUpdateCU.Except(ivsScenarioInitActuals, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -417,9 +398,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioActualUpdateACAAEA = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioActualUpdateACAAEA.Except(ivsScenarioCashflowUpdateCU, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -638,9 +619,9 @@ "await DataSource.Partition.SetAsync(argsBestEstimate);", "\nvar ivsBestEstimateReimportCashFlows = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsBestEstimateReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -671,8 +652,8 @@ { "cell_type": "code", "source": [ - "diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", - "\ndiffs.Where(x => onlyActualETs.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" + "diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", + "\ndiffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -721,9 +702,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioReimportCashFlowsImpact = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioReimportCashFlowsImpact.Except(ivsScenarioReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -780,8 +761,8 @@ "await DataSource.Partition.SetAsync(argsBestEstimate);", "\nvar ivsBestEstimateReimportActuals = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsBestEstimateReimportActuals.Except(ivsBestEstimateReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -804,8 +785,8 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioReimportActuals = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioReimportActuals.Except(ivsScenarioReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -919,8 +900,8 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioReimportCashFlowsWithCU = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioReimportCashFlowsWithCU.Except(ivsScenarioReimportCashflowNoCU, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb index 50e4f4fc..6945a2ae 100644 --- a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb @@ -37,8 +37,7 @@ { "cell_type": "code", "source": [ - "DataSource.Reset(x => x.ResetType().ResetType()", - "\n .ResetType().ResetType());" + "DataSource.Reset(x => x.ResetType().ResetType());" ], "metadata": {}, "execution_count": 0, @@ -74,8 +73,8 @@ { "cell_type": "code", "source": [ - "var ws = Workspace.CreateNew();", - "\nws.InitializeFrom(DataSource);" + "var argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenarioParameter = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"DUP10pct\", ImportFormats.Cashflow);" ], "metadata": {}, "execution_count": 0, @@ -84,9 +83,21 @@ { "cell_type": "code", "source": [ - "var argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", - "\nvar argsScenarioYieldCurve = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"YCUP1.0pct\", ImportFormats.Cashflow);", - "\nvar argsScenarioTransactionalData = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"SRUP1.0pct\", ImportFormats.Cashflow);" + "var estimateTypes = (await DataSource.Query().ToArrayAsync());", + "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", + "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", + "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", + "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Best Estimate initialization" ], "metadata": {}, "execution_count": 0, @@ -95,8 +106,20 @@ { "cell_type": "code", "source": [ - "var initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", - "\nawait initStorage.InitializeAsync();" + "var cashflowBestEstimateInit = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Cashflow", + "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", + "\nDT1.1,PR,BE,CL,C,,100,0,0,100,0,0,100,0,0,100,0,0,0,100,0,0,100,0,0,100,0,0,100,0", + "\nDT1.1,NIC,BE,CL,C,,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25", + "\nDT1.1,,CU,CL,C,,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", + "\nDT1.1,,RA,CL,C,,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5", + "\nDTR1.1,PR,BE,CL,C,,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0", + "\nDTR1.1,NIC,BE,CL,C,,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5", + "\nDTR1.1,,CU,CL,C,,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5", + "\nDTR1.1,,RA,CL,C,,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25\";" ], "metadata": {}, "execution_count": 0, @@ -105,11 +128,17 @@ { "cell_type": "code", "source": [ - "var actualEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Actual];", - "\nvar cashflowEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Cashflow];", - "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", - "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", - "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" + "await Import.FromString(cashflowBestEstimateInit).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateInit = await DataSource.Query().ToArrayAsync();" ], "metadata": {}, "execution_count": 0, @@ -118,7 +147,7 @@ { "cell_type": "markdown", "source": [ - "# Best Estimate initialization" + "# Scenario parameters import" ], "metadata": {}, "execution_count": 0, @@ -127,20 +156,140 @@ { "cell_type": "code", "source": [ - "var cashflowBestEstimateInit = @\"", + "var parametersScenarios = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,DUP10pct", + "\n@@SingleDataNodeParameter", + "\nDataNode,PremiumAllocation", + "\nDT1.1,0.51", + "\n@@InterDataNodeParameter", + "\nDataNode,LinkedDataNode,ReinsuranceCoverage", + "\nDT1.1,DTR1.1,0.951\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(parametersScenarios).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameter = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameter.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Re-import of the same parameters should not trigger calculations " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var log = await Import.FromString(parametersScenarios).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync();", + "\nlog" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "((log.Warnings.FirstOrDefault()?.ToString().Remove(0,40).Remove(125,2)?? \"\") == Get(Warning.VariablesAlreadyImported)).Should().Be(true);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterSameReimport = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameterSameReimport.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Best Estimate re-import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowBestEstimateReImport = @\"", "\n@@Main", "\nReportingNode,Year,Month,Scenario", "\nCH,2020,12,", "\n@@Cashflow", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", - "\nDT1.1,PR,BE,CL,C,,100,0,0,100,0,0,100,0,0,100,0,0,0,100,0,0,100,0,0,100,0,0,100,0", - "\nDT1.1,NIC,BE,CL,C,,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25", - "\nDT1.1,,CU,CL,C,,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", - "\nDT1.1,,RA,CL,C,,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5", - "\nDTR1.1,PR,BE,CL,C,,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0", - "\nDTR1.1,NIC,BE,CL,C,,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5", + "\nDT1.1,PR,BE,CL,C,,111,0,0,111,0,0,111,0,0,111,0,0,0,111,0,0,111,0,0,111,0,0,111,0", + "\nDT1.1,NIC,BE,CL,C,,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31", + "\nDT1.1,,CU,CL,C,,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", + "\nDT1.1,,RA,CL,C,,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6", + "\nDTR1.1,PR,BE,CL,C,,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0", + "\nDTR1.1,NIC,BE,CL,C,,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13", "\nDTR1.1,,CU,CL,C,,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5", - "\nDTR1.1,,RA,CL,C,,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25\";" + "\nDTR1.1,,RA,CL,C,,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31\";" ], "metadata": {}, "execution_count": 0, @@ -149,7 +298,16 @@ { "cell_type": "code", "source": [ - "await Import.FromString(cashflowBestEstimateInit).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + "await Import.FromString(cashflowBestEstimateReImport).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Best Estimate change" ], "metadata": {}, "execution_count": 0, @@ -159,7 +317,7 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsBestEstimate);", - "\nvar ivsBestEstimateInit = await DataSource.Query().ToArrayAsync();" + "\nvar ivsBestEstimateReimport = await DataSource.Query().ToArrayAsync();" ], "metadata": {}, "execution_count": 0, @@ -168,7 +326,7 @@ { "cell_type": "code", "source": [ - "" + "var diffs = ivsBestEstimateReimport.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -177,7 +335,16 @@ { "cell_type": "code", "source": [ - "" + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario should change" ], "metadata": {}, "execution_count": 0, @@ -186,7 +353,8 @@ { "cell_type": "code", "source": [ - "" + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterReimport = await DataSource.Query().ToArrayAsync();" ], "metadata": {}, "execution_count": 0, @@ -195,7 +363,7 @@ { "cell_type": "code", "source": [ - "" + "var diffs = ivsScenarioParameterReimport.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -204,7 +372,187 @@ { "cell_type": "code", "source": [ - "" + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Test" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//var ws = Workspace.CreateNew();", + "\n//ws.Initialize(x => x.FromSource(DataSource));", + "\n", + "\n//await ws.DeleteAsync( ws.Query().Where(x => x.AmountType == \"PR\").ToArray() );", + "\n//await ws.CommitToTargetAsync(DataSource);", + "\n//(DataSource.Query().Count(), ws.Query().Count(), ws.Query().Where(x => x.AmountType == \"PR\").Count())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//var ws = Workspace.CreateNew();", + "\n//ws.Initialize(x => x.FromSource(DataSource).DisableInitialization().DisableInitialization())", + "\n", + "\n//await ws.UpdateAsync( DataSource.Query().Where(x => x.AmountType != \"PR\").ToArray() );", + "\n//await ws.CommitToTargetAsync(DataSource);", + "\n//(DataSource.Query().Count(), ws.Query().Count(), ws.Query().Where(x => x.AmountType == \"PR\").Count())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//var ws = Workspace.CreateNew();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//await ws.UpdateAsync( Enumerable.Empty() )" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## import format" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "/*static ImportArgs[] myallargs;", + "\nstatic ImportArgs myprimaryargs;", + "\nstatic IDataSet mydataset;", + "\nstatic DataNodeParameter[] mytocommitparam;", + "\nstatic IWorkspace myworkspace;", + "\nstatic IWorkspace myworkspacetocompute;", + "\nstatic string[] mytargetDataNodes;", + "\n//static RawVariable[] mynominals;", + "\n", + "\nImport.DefineFormat(ImportFormats.DataNodeParameter, async (options, dataSet) => {", + "\nmydataset = dataSet;", + "\n Activity.Start();", + "\n var primaryArgs = GetArgsFromMain(dataSet) with {ImportFormat = ImportFormats.DataNodeParameter};", + "\n primaryArgs.ValidateArgsForPeriod();", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", + "\n var workspace = Workspace.CreateNew();", + "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization().DisableInitialization());", + "\n", + "\n var committedParameters = await options.TargetDataSource.Query().ToArrayAsync();", + "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, primaryArgs, workspace, options.TargetDataSource); ", + "\n", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log); ", + "\n var toCommitParameters = (await workspace.Query().ToArrayAsync()).Except(committedParameters, ParametersComparer.Instance());", + "\nmytocommitparam = toCommitParameters.ToArray();", + "\n if (!toCommitParameters.Any()) {", + "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", + "\n return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", + "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).Distinct().ToArray();", + "\n var workspaceToCompute = Workspace.CreateNew();", + "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", + "\nmyallargs = allArgs;", + "\nmyprimaryargs = primaryArgs;", + "\nmyworkspace = workspace;", + "\nmyworkspacetocompute = workspaceToCompute;", + "\nmytargetDataNodes = targetDataNodes;", + "\n foreach (var args in allArgs) { ", + "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", + "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", + "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", + "\n await options.TargetDataSource.Partition.SetAsync(null);", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(log);", + "\n ", + "\n // Avoid starting the computation if no best estimate cash flow and actuals has ever been imported ", + "\n if(args.Scenario == null) {", + "\n if(!(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", + "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", + "\n }", + "\n", + "\n // Remove data nodes which are unaffected by the updated yield curves", + "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition)).ToArrayAsync();", + "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", + "\nmynominals = nominals;", + "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n await workspaceToCompute.UpdateAsync(toCommitParameters);", + "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource);", + "\n return Activity.Finish().Merge(log);", + "\n});*/" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## query" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//(await myworkspace.LoadSingleDataNodeParametersAsync(myallargs[0]))[\"DT1.1\"]" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "//(await myworkspace.LoadInterDataNodeParametersAsync(myallargs[0]))[\"DT1.1\"]" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Restore constants" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = EnableScenarioBackup;" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index 57245c6d..5b244628 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -70,16 +70,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "var ws = Workspace.CreateNew();", - "\nws.InitializeFrom(DataSource);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -96,19 +86,10 @@ { "cell_type": "code", "source": [ - "var initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", - "\nawait initStorage.InitializeAsync();" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var actualEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Actual];", - "\nvar cashflowEstimateTypes = initStorage.EstimateTypesByImportFormat[ImportFormats.Cashflow];", - "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "var estimateTypes = (await DataSource.Query().ToArrayAsync());", + "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", + "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", + "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], @@ -288,7 +269,7 @@ { "cell_type": "markdown", "source": [ - "# Re-Import of the same yield curve should not trigger IFRS17 Calculations" + "# Re-import of the same yield curve should not trigger calculations" ], "metadata": {}, "execution_count": 0, @@ -297,7 +278,17 @@ { "cell_type": "code", "source": [ - "await Import.FromString(yieldCurveScenario).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync()" + "var log = await Import.FromString(yieldCurveScenario).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync();", + "\nlog" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "((log.Warnings.FirstOrDefault()?.ToString().Remove(0,40).Remove(125,2)?? \"\") == Get(Warning.VariablesAlreadyImported)).Should().Be(true);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Constants/Consts.ipynb b/ifrs17/Constants/Consts.ipynb index 6546cdf9..b3889647 100644 --- a/ifrs17/Constants/Consts.ipynb +++ b/ifrs17/Constants/Consts.ipynb @@ -25,15 +25,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "public bool EnableScenario = false;" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -379,6 +370,51 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Sensitivities" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public bool EnableScenario = false;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public const string ScenarioDefault = \"Best Estimate\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public const string ScenariosAll = \"All\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public const string ScenariosDelta = \"Delta\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index d2b8a07f..7b3bd562 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -132,7 +132,7 @@ "\n public async Task InitializeAsync()", "\n { ", "\n //Dimensions", - "\n var estimateTypes = (await workspace.Query().ToArrayAsync());", + "\n var estimateTypes = await workspace.Query().ToArrayAsync();", "\n ", "\n EstimateTypeDimension = estimateTypes.ToDictionary(x => x.SystemName);", "\n AmountTypeDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 9c4db10f..bbf5f118 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -503,18 +503,33 @@ { "cell_type": "code", "source": [ - "public async Task GetAllArgsAsync(ImportArgs args, IDataSource dataSource, string format, IDataSource targetDataSource)", + "public async Task GetAllArgsAsync(ImportArgs args, IDataSource dataSource, string format)", "\n{", "\n ImportArgs[] allArgs;", "\n switch(format)", "\n {", - "\n case ImportFormats.YieldCurve : ", + "\n case ImportFormats.Cashflow:", + "\n case ImportFormats.Actual: ", + "\n case ImportFormats.Opening:", + "\n case ImportFormats.SimpleValue:", + "\n {", + "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", + "\n var secondaryArgs = await dataSource.Query() ", + "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArrayAsync();", + "\n ", + "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", + "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", + "\n break;", + "\n }", + "\n default: ", "\n {", "\n if(args.Scenario == null) {", - "\n var scenariosWithYieldCurves = await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => x.Scenario).Distinct().ToArrayAsync();", + "\n var scenarios = (await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).ToArrayAsync())", + "\n .Concat(await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).ToArrayAsync())", + "\n .Distinct();", "\n var targetPartitions = await dataSource.Query()", - "\n .Where(x => x.Year == args.Year && x.Month == args.Month && !scenariosWithYieldCurves.Contains(x.Scenario)).OrderBy(x => x.Scenario).ToArrayAsync();", + "\n .Where(x => x.Year == args.Year && x.Month == args.Month && !scenarios.Contains(x.Scenario)).OrderBy(x => x.Scenario).ToArrayAsync();", "\n var targetScenarios = targetPartitions.Where(x => x.Scenario != null).Select(x => x.Scenario);", "\n if(targetScenarios.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", targetScenarios));", "\n allArgs = targetPartitions.Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArray();", @@ -526,17 +541,6 @@ "\n }", "\n break;", "\n }", - "\n default : ", - "\n {", - "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", - "\n var secondaryArgs = await targetDataSource.Query() ", - "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArrayAsync();", - "\n ", - "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", - "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", - "\n break;", - "\n }", "\n }", "\n return allArgs.Where(x => (!EnableScenario && x.Scenario == null) || EnableScenario).ToArray();", "\n}" @@ -837,7 +841,7 @@ "\n return Activity.Finish().Merge(importLog);", "\n }", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.YieldCurve, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.YieldCurve);", "\n var updatedCurrencies = toCommitYieldCurves.Select(x => x.Currency).Distinct();", "\n var dataNodesToUpdate = await workspace.Query().Where(x => updatedCurrencies.Contains(x.ContractualCurrency)).Select(x => x.SystemName).ToArrayAsync();", "\n var workspaceToCompute = Workspace.CreateNew();", @@ -846,8 +850,7 @@ "\n foreach (var args in allArgs) {", "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", - "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(", - "\n new ImportArgs(args.ReportingNode, args.Year, args.Month, default(Periodicity), null, ImportFormats.Cashflow) ));", + "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(importLog);", "\n ", "\n // Avoid starting the computation if no best estimate cash flow has ever been imported ", @@ -1091,21 +1094,12 @@ { "cell_type": "code", "source": [ - "public async Task UploadDataNodeParameterToWorkspaceAsync(IDataSet dataSet, Guid targetPartitionByReportingNodeId, IWorkspace workspace, IDataSource targetDataSource)", + "public async Task UploadDataNodeParameterToWorkspaceAsync(IDataSet dataSet, ImportArgs args, IWorkspace workspace, IDataSource targetDataSource)", "\n{", - "\n workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\n workspace.Initialize(x => x.FromSource(targetDataSource)", - "\n .DisableInitialization()", - "\n .DisableInitialization()", - "\n .DisableInitialization());", "\n Activity.Start();", - "\n var args = await GetArgsAndCommitPartitionAsync(dataSet, targetDataSource) with {ImportFormat = ImportFormats.DataNodeParameter};", - "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n", "\n var storage = new ParsingStorage(args, targetDataSource, workspace);", "\n await storage.InitializeAsync();", "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n", "\n var singleDataNode = new List();", "\n var interDataNode = new List<(string,string)>();", "\n ", @@ -1124,8 +1118,8 @@ "\n return new SingleDataNodeParameter {", "\n Year = args.Year,", "\n Month = args.Month,", + "\n Scenario = args.Scenario,", "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n", "\n DataNode = dataNode,", "\n PremiumAllocation = (datarow.Field(nameof(SingleDataNodeParameter.PremiumAllocation)))", "\n .ToString().CheckStringForExponentialAndConvertToDouble(),", @@ -1159,6 +1153,7 @@ "\n return new InterDataNodeParameter {", "\n Year = args.Year,", "\n Month = args.Month,", + "\n Scenario = args.Scenario,", "\n Partition = storage.TargetPartitionByReportingNode.Id,", "\n DataNode = dataNodes[0],", "\n LinkedDataNode = dataNodes[1],", @@ -1168,7 +1163,6 @@ "\n .WithTarget(workspace)", "\n .ExecuteAsync();", "\n ", - "\n targetPartitionByReportingNodeId = storage.TargetPartitionByReportingNode.Id;", "\n return Activity.Finish().Merge(importLog);", "\n}" ], @@ -1180,13 +1174,52 @@ "cell_type": "code", "source": [ "Import.DefineFormat(ImportFormats.DataNodeParameter, async (options, dataSet) => {", - "\n Guid partitionId = new Guid();", + "\n Activity.Start();", + "\n var primaryArgs = GetArgsFromMain(dataSet) with {ImportFormat = ImportFormats.DataNodeParameter};", + "\n primaryArgs.ValidateArgsForPeriod();", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", "\n var workspace = Workspace.CreateNew();", - "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, partitionId, workspace, options.TargetDataSource);", - "\n await workspace.CommitToAsync(options.TargetDataSource, partitionId, snapshot: false);", - "\n await workspace.CommitToAsync(options.TargetDataSource, partitionId, snapshot: false); ", - "\n ", - "\n return log;", + "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization().DisableInitialization());", + "\n", + "\n var committedParameters = await options.TargetDataSource.Query().ToArrayAsync();", + "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, primaryArgs, workspace, options.TargetDataSource); ", + "\n", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log); ", + "\n var toCommitParameters = (await workspace.Query().ToArrayAsync()).Except(committedParameters, ParametersComparer.Instance());", + "\n if (!toCommitParameters.Any()) {", + "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", + "\n return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", + "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).Distinct().ToArray();", + "\n var workspaceToCompute = Workspace.CreateNew();", + "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", + "\n", + "\n foreach (var args in allArgs) { ", + "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", + "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", + "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", + "\n await options.TargetDataSource.Partition.SetAsync(null);", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(log);", + "\n ", + "\n // Avoid starting the computation if no best estimate cash flow and actuals has ever been imported ", + "\n if(args.Scenario == null) {", + "\n if(!(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", + "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", + "\n }", + "\n", + "\n // Remove data nodes which are unaffected by the updated yield curves", + "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition)).ToArrayAsync();", + "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", + "\n", + "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n await workspaceToCompute.UpdateAsync(toCommitParameters);", + "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource);", + "\n return Activity.Finish().Merge(log);", "\n});" ], "metadata": {}, @@ -1288,7 +1321,7 @@ "\n var primaryArgs = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Cashflow};", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Cashflow, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Cashflow);", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Cashflow, primaryArgs, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n ", @@ -1389,7 +1422,7 @@ "\n var primaryArgs = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Actual};", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Actual, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Actual);", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Actual, primaryArgs, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", diff --git a/ifrs17/Report/ReportMutableScopes.ipynb b/ifrs17/Report/ReportMutableScopes.ipynb index 91f9faf9..f6cb212f 100644 --- a/ifrs17/Report/ReportMutableScopes.ipynb +++ b/ifrs17/Report/ReportMutableScopes.ipynb @@ -293,11 +293,13 @@ "\n string reportType, (string filterName, object filterValue)[] dataFilter)> ", "\n{", "\n IDataCube Cube { get{", - "\n var dataCube = GetScope(Identity.reportType).GetDataCube();", + "\n var data = GetScope(Identity.reportType).GetDataCube();", "\n // TODO: suggestion to place the filter here instead of having it in every applicability scope", - "\n if(Identity.scenario != \"Delta\") return dataCube;", - "\n var bestEstimateById = dataCube.Where(x => x.Scenario == null).ToDictionary(x => x.ToIdentityString());", - "\n return dataCube.Select(x => x.Scenario == null ? x : x with { Value = x.Value - (bestEstimateById.TryGetValue((x with {Scenario = null}).ToIdentityString(), out var be)? be.Value : 0.0) }).ToDataCube();", + "\n if(Identity.scenario != ScenariosAll && Identity.scenario != ScenariosDelta) return data;", + "\n if(Identity.scenario == ScenariosAll) return data.Select(x => x.Scenario == null? x with {Scenario = ScenarioDefault } : x).ToDataCube();", + "\n var bestEstimateById = data.Where(x => x.Scenario == null).ToDictionary(x => x.ToIdentityString());", + "\n return data.Select(x => x.Scenario == null ? x with { Scenario = ScenarioDefault } ", + "\n : x with { Value = x.Value - (bestEstimateById.TryGetValue((x with {Scenario = null}).ToIdentityString(), out var be)? be.Value : 0.0) }).ToDataCube();", "\n }}", "\n} " ], diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb index 98705583..7ad296bd 100644 --- a/ifrs17/Utils/EqualityComparers.ipynb +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -140,6 +140,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "class ParametersComparer: IEqualityComparer", + "\n{", + "\n private ParametersComparer(){}", + "\n", + "\n public bool Equals(DataNodeParameter x, DataNodeParameter y)", + "\n {", + "\n if (x == null && y == null) return true; ", + "\n if (x == null || y == null) return false; ", + "\n if (!(x.Year == y.Year && x.Month == y.Month && x.DataNode == y.DataNode && x.Scenario == y.Scenario)) return false; ", + "\n if (x is SingleDataNodeParameter && y is SingleDataNodeParameter &&", + "\n ((SingleDataNodeParameter)x).PremiumAllocation == ((SingleDataNodeParameter)y).PremiumAllocation) return true; ", + "\n if (x is InterDataNodeParameter && y is InterDataNodeParameter &&", + "\n ((InterDataNodeParameter)x).LinkedDataNode == ((InterDataNodeParameter)y).LinkedDataNode && ", + "\n ((InterDataNodeParameter)x).ReinsuranceCoverage == ((InterDataNodeParameter)y).ReinsuranceCoverage) return true;", + "\n return false;", + "\n }", + "\n\t", + "\n public int GetHashCode (DataNodeParameter x) => 0;", + "\n", + "\n public static ParametersComparer Instance() => new ParametersComparer();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index af7021f4..809fe695 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -372,8 +372,8 @@ "\n .GroupBy(x => x.DataNode != p.Key ? x.DataNode : x.LinkedDataNode)", "\n .Select(gg =>", "\n {", - "\n var currentCandidate = gg.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).FirstOrDefault();", - "\n var previousCandidate = gg.Where(x => x.Year < args.Year).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", + "\n var currentCandidate = gg.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).ThenByDescending(x => x.Scenario).FirstOrDefault();", + "\n var previousCandidate = gg.Where(x => x.Year < args.Year && x.Scenario == null).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", "\n return (key: p.Key,", "\n currentPeriod: currentCandidate != null ? currentCandidate : previousCandidate,", "\n previousPeriod: previousCandidate != null ? previousCandidate : currentCandidate);", From f5a3b2a3f29f0a18b922006cb1b87adac8f402e4 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Fri, 10 Mar 2023 18:34:51 +0100 Subject: [PATCH 05/11] implement feedback --- ifrs17/Import/Importers.ipynb | 4 ++-- ifrs17/Utils/EqualityComparers.ipynb | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index bbf5f118..b16b3c63 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1192,7 +1192,7 @@ "\n }", "\n", "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", - "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).Distinct().ToArray();", + "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).ToHashSet();", "\n var workspaceToCompute = Workspace.CreateNew();", "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", "\n", @@ -1209,7 +1209,7 @@ "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", "\n }", "\n", - "\n // Remove data nodes which are unaffected by the updated yield curves", + "\n // Only nominals corresponding to the target data nodes are added to the workspace", "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition)).ToArrayAsync();", "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", "\n", diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb index 7ad296bd..95c8b455 100644 --- a/ifrs17/Utils/EqualityComparers.ipynb +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -147,16 +147,19 @@ "\n{", "\n private ParametersComparer(){}", "\n", - "\n public bool Equals(DataNodeParameter x, DataNodeParameter y)", - "\n {", + "\n public bool Equals(DataNodeParameter x, DataNodeParameter y) {", "\n if (x == null && y == null) return true; ", "\n if (x == null || y == null) return false; ", - "\n if (!(x.Year == y.Year && x.Month == y.Month && x.DataNode == y.DataNode && x.Scenario == y.Scenario)) return false; ", - "\n if (x is SingleDataNodeParameter && y is SingleDataNodeParameter &&", + "\n if (!(x.Year == y.Year && x.Month == y.Month && x.Scenario == y.Scenario)) return false; ", + "\n if (x is SingleDataNodeParameter && y is SingleDataNodeParameter && x.DataNode == y.DataNode &&", "\n ((SingleDataNodeParameter)x).PremiumAllocation == ((SingleDataNodeParameter)y).PremiumAllocation) return true; ", - "\n if (x is InterDataNodeParameter && y is InterDataNodeParameter &&", - "\n ((InterDataNodeParameter)x).LinkedDataNode == ((InterDataNodeParameter)y).LinkedDataNode && ", - "\n ((InterDataNodeParameter)x).ReinsuranceCoverage == ((InterDataNodeParameter)y).ReinsuranceCoverage) return true;", + "\n if (x is InterDataNodeParameter && y is InterDataNodeParameter) {", + "\n var xi = (InterDataNodeParameter)x;", + "\n var yi = (InterDataNodeParameter)y;", + "\n if (xi.ReinsuranceCoverage != yi.ReinsuranceCoverage) return false;", + "\n if ((xi.LinkedDataNode == yi.LinkedDataNode && xi.DataNode == yi.DataNode) ||", + "\n (xi.LinkedDataNode == yi.DataNode && xi.DataNode == yi.LinkedDataNode)) return true;", + "\n }", "\n return false;", "\n }", "\n\t", From c34e1e1f9616f25ee63aa018de56bb656f14c3b3 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Mon, 13 Mar 2023 09:40:59 +0100 Subject: [PATCH 06/11] remove simple value --- ifrs17/Import/Importers.ipynb | 1 - 1 file changed, 1 deletion(-) diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index b16b3c63..4e5c1e72 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -511,7 +511,6 @@ "\n case ImportFormats.Cashflow:", "\n case ImportFormats.Actual: ", "\n case ImportFormats.Opening:", - "\n case ImportFormats.SimpleValue:", "\n {", "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", "\n var secondaryArgs = await dataSource.Query() ", From 532aa9c7bd66bf7daa63505a30745960d83a2443 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Tue, 14 Mar 2023 18:54:50 +0100 Subject: [PATCH 07/11] implement feedback --- .../Test/ScenarioDataImportTest.ipynb | 109 ++++++----- .../Test/ScenarioParametersImportTest.ipynb | 178 ++++++------------ .../Test/ScenarioYieldCurveImportTest.ipynb | 4 +- ifrs17/Import/Importers.ipynb | 15 +- 4 files changed, 132 insertions(+), 174 deletions(-) diff --git a/ifrs17-template/Test/ScenarioDataImportTest.ipynb b/ifrs17-template/Test/ScenarioDataImportTest.ipynb index c10a0048..594b996c 100644 --- a/ifrs17-template/Test/ScenarioDataImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioDataImportTest.ipynb @@ -86,7 +86,7 @@ "var estimateTypes = (await DataSource.Query().ToArrayAsync());", "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", - "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], @@ -216,7 +216,7 @@ "\nvar diffs = ivsScenarioInitCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -227,7 +227,7 @@ "source": [ "actualVars.Length.Should().Be(0);", "\ncashflowVars.Length.Should().NotBe(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -274,7 +274,7 @@ "\nvar diffs = ivsScenarioInitActuals.Except(ivsScenarioInitCashFlows, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -285,7 +285,7 @@ "source": [ "actualVars.Length.Should().NotBe(0);", "\ncashflowVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -341,7 +341,7 @@ "\nvar diffs = ivsScenarioCashflowUpdateCU.Except(ivsScenarioInitActuals, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -351,8 +351,10 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.F).Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().NotBe(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -400,7 +402,7 @@ "\nvar diffs = ivsScenarioActualUpdateACAAEA.Except(ivsScenarioCashflowUpdateCU, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -409,9 +411,10 @@ { "cell_type": "code", "source": [ - "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "cashflowVars.Count().Should().Be(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", "\ndiffs.Where(x => x.EstimateType == EstimateTypes.F).ToArray().Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -485,7 +488,7 @@ { "cell_type": "markdown", "source": [ - "# Robustness: back to Best Estimate" + "# Robustness: scenario back to Best Estimate" ], "metadata": {}, "execution_count": 0, @@ -558,7 +561,7 @@ { "cell_type": "code", "source": [ - "diffs.Count().Should().Be(0);" + "ivsScenarioReimportEqualToBestEstimate.Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -617,11 +620,11 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsBestEstimate);", - "\nvar ivsBestEstimateReimportCashFlows = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsBestEstimateReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", + "\nvar ivsBestEstimateReimportCashFlowsNoImpactScenario = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsBestEstimateReimportCashFlowsNoImpactScenario.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -632,7 +635,7 @@ "source": [ "diffs.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().NotBe(0);", "\nactualVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -642,8 +645,8 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsScenario);", - "\nvar ivsScenarioReimportCashFlows = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsScenarioReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + "\nvar ivsScenarioReimportCashFlowsNoImpactScenario = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioReimportCashFlowsNoImpactScenario.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -662,7 +665,7 @@ { "cell_type": "markdown", "source": [ - "# Reimport of Best Estimate Cashflow: impact on Scenario" + "# Reimport of Best Estimate Cashflow" ], "metadata": {}, "execution_count": 0, @@ -696,15 +699,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateReimportCashFlows = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsBestEstimateReimportCashFlows.Except(ivsBestEstimateReimportCashFlowsNoImpactScenario, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsScenario);", - "\nvar ivsScenarioReimportCashFlowsImpact = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsScenarioReimportCashFlowsImpact.Except(ivsScenarioReimportCashFlows, IfrsVariableComparer.Instance());", + "\nvar ivsScenarioReimportCashFlows = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioReimportCashFlows.Except(ivsScenarioReimportCashFlowsNoImpactScenario, IfrsVariableComparer.Instance());", "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -715,7 +738,7 @@ "source": [ "cashflowVars.Length.Should().NotBe(0);", "\nactualVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -740,7 +763,8 @@ "\n@@Actual", "\nDataNode,AocType,AmountType,EstimateType,AccidentYear,Value", "\nDT1.1,CF,NIC,A,,-2000", - "\nDT1.1,CF,PR,A,,-4000\";" + "\nDT1.1,CF,PR,A,,4000", + "\nDT1.1,CF,CL,A,,-3000\";" ], "metadata": {}, "execution_count": 0, @@ -772,8 +796,7 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().NotBe(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);" + "\ncashflowVars.Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -795,9 +818,9 @@ { "cell_type": "code", "source": [ - "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);" + "diffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);", + "\nactualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -821,16 +844,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "await DataSource.Partition.SetAsync(argsScenario);", - "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -859,13 +872,23 @@ "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", "\nDT1.1,PR,BE,CL,C,,200,0,0,200,0,0,200,0,0,200,0,0,0,200,0,0,200,0,0,200,0,0,200,0", "\nDT1.1,NIC,BE,CL,C,,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33", - "\nDT1.1,,CU,CL,C,,-71,-71,-70,-70,-69,-69,-68,-68,-67,-67,-66,-66,-65,-65,-64,-64,-63,-63,-62,-62,-61,-61,-60,-60", + "\nDT1.1,,CU,CL,C,,-719,-71,-70,-70,-69,-69,-68,-68,-67,-67,-66,-66,-65,-65,-64,-64,-63,-63,-62,-62,-61,-61,-60,-60", "\nDT1.1,,RA,CL,C,,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45\";" ], "metadata": {}, "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -911,7 +934,7 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);" + "\ndiffs.Count().Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, @@ -945,4 +968,4 @@ "outputs": [] } ] -} +} \ No newline at end of file diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb index 6945a2ae..a65ecdd9 100644 --- a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb @@ -86,7 +86,7 @@ "var estimateTypes = (await DataSource.Query().ToArrayAsync());", "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", - "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], @@ -134,6 +134,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var actualsBestEstimateInit = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Actual", + "\nDataNode,AocType,AmountType,EstimateType,AccidentYear,Value", + "\nDT1.1,CF,ACA,A,,-10", + "\nDT1.1,CF,AEA,A,,-5", + "\nDT1.1,CF,NIC,A,,-280", + "\nDT1.1,CF,PR,A,,400", + "\nDTR1.1,CF,PR,A,,-200", + "\nDTR1.1,CF,NIC,A,,140\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsBestEstimateInit).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -162,10 +191,10 @@ "\nCH,2020,12,DUP10pct", "\n@@SingleDataNodeParameter", "\nDataNode,PremiumAllocation", - "\nDT1.1,0.51", + "\nDT1.1,0.52", "\n@@InterDataNodeParameter", "\nDataNode,LinkedDataNode,ReinsuranceCoverage", - "\nDT1.1,DTR1.1,0.951\";" + "\nDT1.1,DTR1.1,0.62\";" ], "metadata": {}, "execution_count": 0, @@ -193,7 +222,7 @@ { "cell_type": "code", "source": [ - "var diffs = ivsScenarioParameter.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + "var diffs = ivsScenarioParameter.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance()).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -202,7 +231,8 @@ { "cell_type": "code", "source": [ - "diffs.Count().Should().NotBe(0);" + "diffs.Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, @@ -267,7 +297,7 @@ { "cell_type": "markdown", "source": [ - "# Best Estimate re-import" + "# Re-import of best estimate cashflow" ], "metadata": {}, "execution_count": 0, @@ -282,7 +312,7 @@ "\nCH,2020,12,", "\n@@Cashflow", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", - "\nDT1.1,PR,BE,CL,C,,111,0,0,111,0,0,111,0,0,111,0,0,0,111,0,0,111,0,0,111,0,0,111,0", + "\nDT1.1,PR,BE,CL,C,,131,0,0,111,0,0,111,0,0,111,0,0,0,111,0,0,111,0,0,111,0,0,111,0", "\nDT1.1,NIC,BE,CL,C,,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31", "\nDT1.1,,CU,CL,C,,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", "\nDT1.1,,RA,CL,C,,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6", @@ -354,7 +384,7 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsScenarioParameter);", - "\nvar ivsScenarioParameterReimport = await DataSource.Query().ToArrayAsync();" + "\nvar ivsScenarioParameterReimportBestEstimateCashflow = await DataSource.Query().ToArrayAsync();" ], "metadata": {}, "execution_count": 0, @@ -363,7 +393,7 @@ { "cell_type": "code", "source": [ - "var diffs = ivsScenarioParameterReimport.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" + "var diffs = ivsScenarioParameterReimportBestEstimateCashflow.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -381,7 +411,7 @@ { "cell_type": "markdown", "source": [ - "# Test" + "# Re-import of scenario parameters" ], "metadata": {}, "execution_count": 0, @@ -390,26 +420,16 @@ { "cell_type": "code", "source": [ - "//var ws = Workspace.CreateNew();", - "\n//ws.Initialize(x => x.FromSource(DataSource));", - "\n", - "\n//await ws.DeleteAsync( ws.Query().Where(x => x.AmountType == \"PR\").ToArray() );", - "\n//await ws.CommitToTargetAsync(DataSource);", - "\n//(DataSource.Query().Count(), ws.Query().Count(), ws.Query().Where(x => x.AmountType == \"PR\").Count())" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "//var ws = Workspace.CreateNew();", - "\n//ws.Initialize(x => x.FromSource(DataSource).DisableInitialization().DisableInitialization())", - "\n", - "\n//await ws.UpdateAsync( DataSource.Query().Where(x => x.AmountType != \"PR\").ToArray() );", - "\n//await ws.CommitToTargetAsync(DataSource);", - "\n//(DataSource.Query().Count(), ws.Query().Count(), ws.Query().Where(x => x.AmountType == \"PR\").Count())" + "var parametersScenariosReimport = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,DUP10pct", + "\n@@SingleDataNodeParameter", + "\nDataNode,PremiumAllocation", + "\nDT1.1,0.23", + "\n@@InterDataNodeParameter", + "\nDataNode,LinkedDataNode,ReinsuranceCoverage", + "\nDT1.1,DTR1.1,0.23\";" ], "metadata": {}, "execution_count": 0, @@ -418,7 +438,7 @@ { "cell_type": "code", "source": [ - "//var ws = Workspace.CreateNew();" + "await Import.FromString(parametersScenariosReimport).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync()" ], "metadata": {}, "execution_count": 0, @@ -427,96 +447,8 @@ { "cell_type": "code", "source": [ - "//await ws.UpdateAsync( Enumerable.Empty() )" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## import format" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "/*static ImportArgs[] myallargs;", - "\nstatic ImportArgs myprimaryargs;", - "\nstatic IDataSet mydataset;", - "\nstatic DataNodeParameter[] mytocommitparam;", - "\nstatic IWorkspace myworkspace;", - "\nstatic IWorkspace myworkspacetocompute;", - "\nstatic string[] mytargetDataNodes;", - "\n//static RawVariable[] mynominals;", - "\n", - "\nImport.DefineFormat(ImportFormats.DataNodeParameter, async (options, dataSet) => {", - "\nmydataset = dataSet;", - "\n Activity.Start();", - "\n var primaryArgs = GetArgsFromMain(dataSet) with {ImportFormat = ImportFormats.DataNodeParameter};", - "\n primaryArgs.ValidateArgsForPeriod();", - "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", - "\n var workspace = Workspace.CreateNew();", - "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization().DisableInitialization());", - "\n", - "\n var committedParameters = await options.TargetDataSource.Query().ToArrayAsync();", - "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, primaryArgs, workspace, options.TargetDataSource); ", - "\n", - "\n if(log.Errors.Any()) return Activity.Finish().Merge(log); ", - "\n var toCommitParameters = (await workspace.Query().ToArrayAsync()).Except(committedParameters, ParametersComparer.Instance());", - "\nmytocommitparam = toCommitParameters.ToArray();", - "\n if (!toCommitParameters.Any()) {", - "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", - "\n return Activity.Finish().Merge(log);", - "\n }", - "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", - "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).Distinct().ToArray();", - "\n var workspaceToCompute = Workspace.CreateNew();", - "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", - "\nmyallargs = allArgs;", - "\nmyprimaryargs = primaryArgs;", - "\nmyworkspace = workspace;", - "\nmyworkspacetocompute = workspaceToCompute;", - "\nmytargetDataNodes = targetDataNodes;", - "\n foreach (var args in allArgs) { ", - "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", - "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", - "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", - "\n await options.TargetDataSource.Partition.SetAsync(null);", - "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(log);", - "\n ", - "\n // Avoid starting the computation if no best estimate cash flow and actuals has ever been imported ", - "\n if(args.Scenario == null) {", - "\n if(!(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", - "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", - "\n }", - "\n", - "\n // Remove data nodes which are unaffected by the updated yield curves", - "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition)).ToArrayAsync();", - "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", - "\nmynominals = nominals;", - "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));", - "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", - "\n }", - "\n", - "\n await workspaceToCompute.UpdateAsync(toCommitParameters);", - "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource);", - "\n return Activity.Finish().Merge(log);", - "\n});*/" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## query" + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterReimport = await DataSource.Query().ToArrayAsync();" ], "metadata": {}, "execution_count": 0, @@ -525,7 +457,7 @@ { "cell_type": "code", "source": [ - "//(await myworkspace.LoadSingleDataNodeParametersAsync(myallargs[0]))[\"DT1.1\"]" + "var diffs = ivsScenarioParameterReimport.Except(ivsScenarioParameterReimportBestEstimateCashflow, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -534,7 +466,7 @@ { "cell_type": "code", "source": [ - "//(await myworkspace.LoadInterDataNodeParametersAsync(myallargs[0]))[\"DT1.1\"]" + "diffs.Count().Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index e5e8e110..6fce00f2 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -89,7 +89,7 @@ "var estimateTypes = (await DataSource.Query().ToArrayAsync());", "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", - "\nvar actualOrCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], @@ -750,4 +750,4 @@ "outputs": [] } ] -} +} \ No newline at end of file diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 4e5c1e72..bafce3f7 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -513,9 +513,10 @@ "\n case ImportFormats.Opening:", "\n {", "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", + "\n var importFormat = (format == ImportFormats.Actual)? ImportFormats.Actual : ImportFormats.Cashflow;", "\n var secondaryArgs = await dataSource.Query() ", "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArrayAsync();", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, importFormat)).ToArrayAsync();", "\n ", "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", @@ -563,10 +564,11 @@ "\n var ivs = universe.GetScopes(identities).SelectMany(x => x.CalculatedIfrsVariables);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n if(storage.DefaultPartition != storage.TargetPartition){", - "\n var bestEstimateIvs = await DataSource.LoadPartitionedDataAsync(storage.DefaultPartition);", - "\n ivs = ivs.Where(iv => Math.Abs(iv.Value) >= Precision).ToArray().Concat(", - "\n ivs.Where(iv => Math.Abs(iv.Value) < Precision).Intersect(bestEstimateIvs, EqualityComparer.Instance).Select(iv => iv with {Value = 0.0}).ToArray());", + "\n if(storage.DefaultPartition != storage.TargetPartition) {", + "\n var bestEstimateIvs = await workspaceToCompute.LoadPartitionedDataAsync(storage.DefaultPartition);", + "\n ivs = ivs.Where(iv => Math.Abs(iv.Value) >= Precision).ToArray()", + "\n .Except(bestEstimateIvs, IfrsVariableComparer.Instance(ignoreValue: false))", + "\n .Concat(ivs.Where(x => Math.Abs(x.Value) < Precision).Intersect(bestEstimateIvs, EqualityComparer.Instance).Select(x => x with {Value = 0.0}).ToArray());", "\n }", "\n", "\n workspace.Reset(x => x.ResetType());", @@ -1191,7 +1193,8 @@ "\n }", "\n", "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", - "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode).ToHashSet();", + "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode)", + "\n .Concat(toCommitParameters.Where(x => x is InterDataNodeParameter).Select(x => ((InterDataNodeParameter)x).LinkedDataNode)).ToHashSet();", "\n var workspaceToCompute = Workspace.CreateNew();", "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", "\n", From 1d0cfebfab9b283d17cf375b95cf58e32e21f2b5 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Tue, 14 Mar 2023 21:49:24 +0100 Subject: [PATCH 08/11] update benchmark --- .../Test/Data/ExportIfrsVariable.ipynb | 22 +++-- .../BM_CH_2020_12_MTUP10pct_A.csv | 16 +--- .../BM_CH_2020_12_MTUP10pct_AA.csv | 5 + .../BM_CH_2020_12_MTUP10pct_APA.csv | 5 +- .../BM_CH_2020_12_MTUP10pct_BE.csv | 93 +++++++++---------- .../BM_CH_2020_12_MTUP10pct_BEPA.csv | 3 +- .../BM_CH_2020_12_MTUP10pct_C.csv | 23 +---- .../BM_CH_2020_12_MTUP10pct_DA.csv | 11 +-- .../BM_CH_2020_12_MTUP10pct_F.csv | 6 +- .../BM_CH_2020_12_MTUP10pct_OA.csv | 5 + .../BM_CH_2020_12_MTUP10pct_RA.csv | 34 +------ ifrs17-template/Test/IfrsVariablesTest.ipynb | 11 ++- 12 files changed, 91 insertions(+), 143 deletions(-) create mode 100644 ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv create mode 100644 ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv diff --git a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb index 3cb7ebd8..fc079234 100644 --- a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb +++ b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb @@ -46,8 +46,8 @@ { "cell_type": "code", "source": [ - "//#!eval-notebook \"InitSystemorphToMemoryForTesting\"", - "\n#!eval-notebook \"../../PracticalUseCases/SingleVsMultipleCsmSwitch/CsmSwitchDataImport\"" + "#!eval-notebook \"InitSystemorphToMemoryForTesting\"", + "\n//#!eval-notebook \"../../PracticalUseCases/SingleVsMultipleCsmSwitch/CsmSwitchDataImport\"" ], "metadata": {}, "execution_count": 0, @@ -103,7 +103,8 @@ "source": [ "var exportScope = new ImportArgs[]{", "\n new ImportArgs (\"CH\", 2020, 12, (Periodicity)default, null, null),", - "\n new ImportArgs (\"CH\", 2021, 3, (Periodicity)default, null, null)", + "\n new ImportArgs (\"CH\", 2021, 3, (Periodicity)default, null, null),", + "\n new ImportArgs (\"CH\", 2020, 12, (Periodicity)default, \"MTUP10pct\", null)", "\n };" ], "metadata": {}, @@ -122,7 +123,7 @@ { "cell_type": "code", "source": [ - "var args = exportScope[0];", + "var args = exportScope[2];", "\nargs" ], "metadata": {}, @@ -134,7 +135,7 @@ "source": [ "await DataSource.Partition.SetAsync(new {ReportingNode = args.ReportingNode, Year = args.Year, Month = args.Month, Scenario = args.Scenario});", "\nvar ifrsVariables = (await DataSource.Query().ToArrayAsync())", - "\n .Select(v => v with { Value = Math.Round(v.Value, roundingDigits)})", + "\n //.Select(v => v with { Value = Math.Round(v.Value, roundingDigits)})", "\n .OrderBy(v => v.DataNode).ThenBy(v => v.AccidentYear).ThenBy(v => v.EstimateType).ThenBy(v => v.EconomicBasis).ThenBy(v => v.AmountType).ThenBy(v => v.Novelty)", "\n .ThenBy(v => v.AocType)", "\n .ToArray();" @@ -215,7 +216,7 @@ { "cell_type": "code", "source": [ - "var estimateType = \"BE\";" + "var estimateType = \"RA\";" ], "metadata": {}, "execution_count": 0, @@ -244,6 +245,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv index b950aba6..016b5edf 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv @@ -4,21 +4,9 @@ Month,ReportingNode,Scenario,Year @@A AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value ,NIC,CF,DT1.1,,A,C,-310 -,PR,CF,DT1.1,,A,C,400 -,ACA,CF,DT1.1,,A,C,-10 -,AEA,CF,DT1.1,,A,C,-5 2020,NIC,CF,DT1.2,,A,C,-310 -,NIC,CF,DT2.1,,A,C,-310 -,PR,CF,DT2.1,,A,C,400 -,ACA,CF,DT2.1,,A,C,-10 -,AEA,CF,DT2.1,,A,C,-5 ,NIC,CF,DT1.3,,A,C,-310 -,PR,CF,DT1.3,,A,C,400 -,ACA,CF,DT1.3,,A,C,-10 -,AEA,CF,DT1.3,,A,C,-5 +,NIC,CF,DT2.1,,A,C,-310 2020,NIC,CF,DT2.2,,A,C,-310 ,NIC,CF,DTR1.1,,A,C,170 -,PR,CF,DTR1.1,,A,C,-200 -2020,NIC,CF,DTR1.2,,A,C,170 -,PR,CF,DTR2.1,,A,C,-200 -,NIC,CF,DTR2.1,,A,C,140 \ No newline at end of file +2020,NIC,CF,DTR1.2,,A,C,170 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv new file mode 100644 index 00000000..da193d4d --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv @@ -0,0 +1,5 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@AA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv index 98071041..fcfb044a 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv @@ -2,7 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@APA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,PR,CF,DT1.1,,APA,C,320 -,PR,CF,DT2.1,,APA,C,320 -,PR,CF,DT1.3,,APA,C,400 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv index 97f1efee..c40053de 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv @@ -3,67 +3,60 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@BE AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,NIC,BOP,DT1.1,L,BE,N,658.62824 -,PR,BOP,DT1.1,L,BE,N,-798.53673 -,NIC,BOP,DT1.1,C,BE,N,658.62824 -,PR,BOP,DT1.1,C,BE,N,-798.53673 -,NIC,EOP,DT1.1,L,BE,C,329.6431 -,PR,EOP,DT1.1,L,BE,C,-399.63393 ,NIC,EOP,DT1.1,C,BE,C,329.6431 -,PR,EOP,DT1.1,C,BE,C,-399.63393 -,NIC,IA,DT1.1,L,BE,N,1.01487 -,PR,IA,DT1.1,L,BE,N,-1.0972 +,NIC,BOP,DT1.1,C,BE,N,658.62824 +,NIC,CF,DT1.1,C,BE,N,-330 ,NIC,IA,DT1.1,C,BE,N,1.01487 -,PR,IA,DT1.1,C,BE,N,-1.0972 +,NIC,EOP,DT1.1,L,BE,C,329.6431 +,NIC,BOP,DT1.1,L,BE,N,658.62824 ,NIC,CF,DT1.1,L,BE,N,-330 -,PR,CF,DT1.1,L,BE,N,400 -,NIC,CF,DT1.1,C,BE,N,-330 -,PR,CF,DT1.1,C,BE,N,400 -2020,NIC,BOP,DT1.2,L,BE,N,658.62824 -2020,NIC,BOP,DT1.2,C,BE,N,658.62824 -2020,NIC,EOP,DT1.2,L,BE,C,329.6431 +,NIC,IA,DT1.1,L,BE,N,1.01487 2020,NIC,EOP,DT1.2,C,BE,C,329.6431 -2020,NIC,IA,DT1.2,L,BE,N,1.01487 +2020,NIC,BOP,DT1.2,C,BE,N,658.62824 +2020,NIC,CF,DT1.2,C,BE,N,-330 2020,NIC,IA,DT1.2,C,BE,N,1.01487 +2020,NIC,EOP,DT1.2,L,BE,C,329.6431 +2020,NIC,BOP,DT1.2,L,BE,N,658.62824 2020,NIC,CF,DT1.2,L,BE,N,-330 -2020,NIC,CF,DT1.2,C,BE,N,-330 -,NIC,BOP,DTR1.1,L,BE,N,-329.31412 -,PR,BOP,DTR1.1,L,BE,N,399.26837 -,CDR,BOP,DTR1.1,L,BE,N,0.52925 -,NIC,BOP,DTR1.1,C,BE,N,-329.31412 -,PR,BOP,DTR1.1,C,BE,N,399.26837 +2020,NIC,IA,DT1.2,L,BE,N,1.01487 +,CDR,EOP,DTR1.1,C,BE,C,0.1268 ,CDR,BOP,DTR1.1,C,BE,N,0.52925 -,NIC,EOP,DTR1.1,L,BE,C,-164.82155 -,PR,EOP,DTR1.1,L,BE,C,199.81696 -,CDR,EOP,DTR1.1,L,BE,C,0.1268 +,CDR,CF,DTR1.1,C,BE,N,-0.40374 +,CDR,IA,DTR1.1,C,BE,N,0.00129 ,NIC,EOP,DTR1.1,C,BE,C,-164.82155 -,PR,EOP,DTR1.1,C,BE,C,199.81696 -,CDR,EOP,DTR1.1,C,BE,C,0.1268 -,NIC,IA,DTR1.1,L,BE,N,-0.50743 -,PR,IA,DTR1.1,L,BE,N,0.5486 -,CDR,IA,DTR1.1,L,BE,N,0.00129 +,NIC,BOP,DTR1.1,C,BE,N,-329.31412 +,NIC,CF,DTR1.1,C,BE,N,165 ,NIC,IA,DTR1.1,C,BE,N,-0.50743 -,PR,IA,DTR1.1,C,BE,N,0.5486 -,CDR,IA,DTR1.1,C,BE,N,0.00129 -,NIC,CF,DTR1.1,L,BE,N,165 -,PR,CF,DTR1.1,L,BE,N,-200 +,CDR,EOP,DTR1.1,L,BE,C,0.1268 +,CDR,BOP,DTR1.1,L,BE,N,0.52925 ,CDR,CF,DTR1.1,L,BE,N,-0.40374 -,NIC,CF,DTR1.1,C,BE,N,165 -,PR,CF,DTR1.1,C,BE,N,-200 -,CDR,CF,DTR1.1,C,BE,N,-0.40374 -2020,NIC,BOP,DTR1.2,L,BE,N,-329.31412 -2020,CDR,BOP,DTR1.2,L,BE,N,0.52925 -2020,NIC,BOP,DTR1.2,C,BE,N,-329.31412 +,CDR,IA,DTR1.1,L,BE,N,0.00129 +,NIC,EOP,DTR1.1,L,BE,C,-164.82155 +,NIC,BOP,DTR1.1,L,BE,N,-329.31412 +,NIC,CF,DTR1.1,L,BE,N,165 +,NIC,IA,DTR1.1,L,BE,N,-0.50743 +2020,CDR,EOP,DTR1.2,C,BE,C,0.1268 2020,CDR,BOP,DTR1.2,C,BE,N,0.52925 -2020,NIC,EOP,DTR1.2,L,BE,C,-164.82155 -2020,CDR,EOP,DTR1.2,L,BE,C,0.1268 +2020,CDR,CF,DTR1.2,C,BE,N,-0.40374 +2020,CDR,IA,DTR1.2,C,BE,N,0.00129 2020,NIC,EOP,DTR1.2,C,BE,C,-164.82155 -2020,CDR,EOP,DTR1.2,C,BE,C,0.1268 -2020,NIC,IA,DTR1.2,L,BE,N,-0.50743 -2020,CDR,IA,DTR1.2,L,BE,N,0.00129 +2020,NIC,BOP,DTR1.2,C,BE,N,-329.31412 +2020,NIC,CF,DTR1.2,C,BE,N,165 2020,NIC,IA,DTR1.2,C,BE,N,-0.50743 -2020,CDR,IA,DTR1.2,C,BE,N,0.00129 -2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,CDR,EOP,DTR1.2,L,BE,C,0.1268 +2020,CDR,BOP,DTR1.2,L,BE,N,0.52925 2020,CDR,CF,DTR1.2,L,BE,N,-0.40374 -2020,NIC,CF,DTR1.2,C,BE,N,165 -2020,CDR,CF,DTR1.2,C,BE,N,-0.40374 \ No newline at end of file +2020,CDR,IA,DTR1.2,L,BE,N,0.00129 +2020,NIC,EOP,DTR1.2,L,BE,C,-164.82155 +2020,NIC,BOP,DTR1.2,L,BE,N,-329.31412 +2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,NIC,IA,DTR1.2,L,BE,N,-0.50743,N,165 +2020,NIC,IA,DTR1.2,C,BE,N,-0.5074328025652143 +2020,CDR,EOP,DTR1.2,L,BE,C,0.12679876434718015 +2020,CDR,BOP,DTR1.2,L,BE,N,0.5292475300191577 +2020,CDR,CF,DTR1.2,L,BE,N,-0.40373597582193455 +2020,CDR,IA,DTR1.2,L,BE,N,0.001287210150087148 +2020,NIC,EOP,DTR1.2,L,BE,C,-164.8215523318298 +2020,NIC,BOP,DTR1.2,L,BE,N,-329.3141195292647 +2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,NIC,IA,DTR1.2,L,BE,N,-0.5074328025652143 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv index 4674e6db..afd6e7c6 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv @@ -2,5 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@BEPA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,PR,CF,DT1.1,L,BEPA,N,320 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv index dcfc1f10..b9f6ed7f 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv @@ -3,26 +3,13 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@C AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,BOP,DT1.1,,C,N,80.0332 -,,EOP,DT1.1,,C,C,22.35306 ,,AM,DT1.1,,C,C,-42.67021 -,,EA,DT1.1,,C,C,-15 +,,EOP,DT1.1,,C,C,22.35306 +,,BOP,DT1.1,,C,N,80.0332 ,,IA,DT1.1,,C,N,-0.00993 -,,EA,DT2.1,,C,C,-15 -,,AM,DT2.1,,C,C,-82.02271 -,,EOP,DT2.1,,C,C,42.96811 -,,BOP,DT2.1,,C,N,139.90849 -,,IA,DT2.1,,C,N,0.08233 -,,EA,DT1.3,,C,C,-15 -,,AM,DT1.3,,C,C,-82.02271 -,,EOP,DT1.3,,C,C,42.96811 -,,BOP,DT1.3,,C,N,139.90849 -,,IA,DT1.3,,C,N,0.08233 ,,AM,DTR1.1,,C,C,26.60498 ,,EOP,DTR1.1,,C,C,-13.93719 ,,BOP,DTR1.1,,C,N,-40.54585 -,,IA,DTR1.1,,C,N,0.00368 -,,AM,DTR2.1,,C,C,46.24958 -,,EOP,DTR2.1,,C,C,-24.22813 -,,BOP,DTR2.1,,C,N,-70.43538 -,,IA,DTR2.1,,C,N,-0.04234 \ No newline at end of file +,,IA,DTR1.1,,C,N,0.0036888043 +,,BOP,DTR1.1,,C,N,-40.545846351508814 +,,IA,DTR1.1,,C,N,0.003676678453477744 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv index 4ad94e50..60cc80c2 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv @@ -2,13 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@DA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,EOP,DT1.1,,DA,C,-5.15655 -,,AM,DT1.1,,DA,C,9.84345 -,,CF,DT1.1,,DA,C,-15 -,,CF,DT2.1,,DA,C,-15 -,,AM,DT2.1,,DA,C,9.84345 -,,EOP,DT2.1,,DA,C,-5.15655 -,,CF,DT1.3,,DA,C,-15 -,,AM,DT1.3,,DA,C,9.84345 -,,EOP,DT1.3,,DA,C,-5.15655 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv index 20a47c21..ffe034ac 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv @@ -2,8 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@F -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,AM,DT1.1,L,F,C,0.65623 -,,AM,DT1.2,L,F,C,1 -,,AM,DTR1.1,L,F,C,0.65623 -,,AM,DTR1.2,L,F,C,1 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv new file mode 100644 index 00000000..6ebb2b89 --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv @@ -0,0 +1,5 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@OA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv index 9b1cb78e..cf55d925 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv @@ -2,36 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@RA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,BOP,DT1.1,C,RA,N,59.87529 -,,BOP,DT1.1,L,RA,N,59.87529 -,,EOP,DT1.1,C,RA,C,29.96755 -,,EOP,DT1.1,L,RA,C,29.96755 -,,IA,DT1.1,C,RA,N,0.09226 -,,IA,DT1.1,L,RA,N,0.09226 -,,CF,DT1.1,C,RA,N,-30 -,,CF,DT1.1,L,RA,N,-30 -2020,,BOP,DT1.2,C,RA,N,59.87529 -2020,,BOP,DT1.2,L,RA,N,59.87529 -2020,,EOP,DT1.2,C,RA,C,29.96755 -2020,,EOP,DT1.2,L,RA,C,29.96755 -2020,,IA,DT1.2,C,RA,N,0.09226 -2020,,IA,DT1.2,L,RA,N,0.09226 -2020,,CF,DT1.2,C,RA,N,-30 -2020,,CF,DT1.2,L,RA,N,-30 -,,BOP,DTR1.1,C,RA,N,-29.93765 -,,BOP,DTR1.1,L,RA,N,-29.93765 -,,EOP,DTR1.1,C,RA,C,-14.98378 -,,EOP,DTR1.1,L,RA,C,-14.98378 -,,IA,DTR1.1,C,RA,N,-0.04613 -,,IA,DTR1.1,L,RA,N,-0.04613 -,,CF,DTR1.1,C,RA,N,15 -,,CF,DTR1.1,L,RA,N,15 -2020,,BOP,DTR1.2,C,RA,N,-29.93765 -2020,,BOP,DTR1.2,L,RA,N,-29.93765 -2020,,EOP,DTR1.2,C,RA,C,-14.98378 -2020,,EOP,DTR1.2,L,RA,C,-14.98378 -2020,,IA,DTR1.2,C,RA,N,-0.04613 -2020,,IA,DTR1.2,L,RA,N,-0.04613 -2020,,CF,DTR1.2,C,RA,N,15 -2020,,CF,DTR1.2,L,RA,N,15 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index f10996ee..52233a75 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -271,7 +271,7 @@ "\n //Get the computed Data", "\n var computedVariables = computedVariablesByEstimateType.TryGetValue(bmTableName, out var ret) ? ret : Enumerable.Empty();", "\n", - "\n if(!computedVariables.Any())", + "\n if(!computedVariables.Any() && scenario == null)", "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName, 0, 0));", "\n //CompareAgainstBm", "\n if (bmVariables.Any() && computedVariables.Any()) //TODO we are adding duplicates here", @@ -291,6 +291,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file From 24d538ec0ede9e9e05dd0e88468684c651933196 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Thu, 16 Mar 2023 11:30:23 +0100 Subject: [PATCH 09/11] rounding digit when exporting ifrs vars --- ifrs17-template/Test/Data/ExportIfrsVariable.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb index fc079234..7eb4f123 100644 --- a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb +++ b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb @@ -135,7 +135,7 @@ "source": [ "await DataSource.Partition.SetAsync(new {ReportingNode = args.ReportingNode, Year = args.Year, Month = args.Month, Scenario = args.Scenario});", "\nvar ifrsVariables = (await DataSource.Query().ToArrayAsync())", - "\n //.Select(v => v with { Value = Math.Round(v.Value, roundingDigits)})", + "\n .Select(v => v with { Value = Math.Round(v.Value, roundingDigits)})", "\n .OrderBy(v => v.DataNode).ThenBy(v => v.AccidentYear).ThenBy(v => v.EstimateType).ThenBy(v => v.EconomicBasis).ThenBy(v => v.AmountType).ThenBy(v => v.Novelty)", "\n .ThenBy(v => v.AocType)", "\n .ToArray();" From 5806fdd9f5c4060c31bb7a9808900c7d82001892 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Fri, 17 Mar 2023 00:06:41 +0100 Subject: [PATCH 10/11] openings format for reimport best estimate --- ifrs17/Import/Importers.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index bafce3f7..6c74f32c 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -513,10 +513,9 @@ "\n case ImportFormats.Opening:", "\n {", "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", - "\n var importFormat = (format == ImportFormats.Actual)? ImportFormats.Actual : ImportFormats.Cashflow;", "\n var secondaryArgs = await dataSource.Query() ", "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, importFormat)).ToArrayAsync();", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, format)).ToArrayAsync();", "\n ", "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", From 98cdb50de0933b4b181ba7b657b5de0169fb6c8e Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Fri, 17 Mar 2023 13:04:56 +0100 Subject: [PATCH 11/11] implement improvements suggested from Davide --- ifrs17-template/Test/IfrsVariablesTest.ipynb | 2 +- ifrs17/Import/Importers.ipynb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index 52233a75..fc9772ba 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -271,7 +271,7 @@ "\n //Get the computed Data", "\n var computedVariables = computedVariablesByEstimateType.TryGetValue(bmTableName, out var ret) ? ret : Enumerable.Empty();", "\n", - "\n if(!computedVariables.Any() && scenario == null)", + "\n if(!computedVariables.Any() && bmVariables.Any())", "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName, 0, 0));", "\n //CompareAgainstBm", "\n if (bmVariables.Any() && computedVariables.Any()) //TODO we are adding duplicates here", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 6c74f32c..a5b2932b 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -524,9 +524,10 @@ "\n default: ", "\n {", "\n if(args.Scenario == null) {", - "\n var scenarios = (await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).ToArrayAsync())", - "\n .Concat(await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).ToArrayAsync())", - "\n .Distinct();", + "\n var scenarios = format switch {", + "\n ImportFormats.YieldCurve => await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).Distinct().ToArrayAsync(),", + "\n ImportFormats.DataNodeParameter => await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).Distinct().ToArrayAsync()", + "\n };", "\n var targetPartitions = await dataSource.Query()", "\n .Where(x => x.Year == args.Year && x.Month == args.Month && !scenarios.Contains(x.Scenario)).OrderBy(x => x.Scenario).ToArrayAsync();", "\n var targetScenarios = targetPartitions.Where(x => x.Scenario != null).Select(x => x.Scenario);", @@ -1201,17 +1202,17 @@ "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", + "\n var previousPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null, Year = args.Year-1, Month = 12}));", "\n await options.TargetDataSource.Partition.SetAsync(null);", "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(log);", "\n ", "\n // Avoid starting the computation if no best estimate cash flow and actuals has ever been imported ", - "\n if(args.Scenario == null) {", - "\n if(!(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", - "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", - "\n }", + "\n if(args.Scenario == null && !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", + "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", "\n", "\n // Only nominals corresponding to the target data nodes are added to the workspace", - "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition)).ToArrayAsync();", + "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && ", + "\n (x.Partition == targetPartition || x.Partition == defaultPartition || x.Partition == previousPartition)).ToArrayAsync();", "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", "\n", "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));",