From 9e4c8608c181d20d27c99779e68fbb3d9c19a988 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Tue, 7 Mar 2023 18:16:08 +0100 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 db4e0a3eae6b4d2939cd3062e6106bcc17b8f2ba Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Thu, 9 Mar 2023 14:43:58 +0100 Subject: [PATCH 4/5] only fixes and tests --- .../Test/ScenarioParametersImportTest.ipynb | 223 ------------------ ifrs17-template/Test/Tests.ipynb | 11 +- 2 files changed, 1 insertion(+), 233 deletions(-) delete mode 100644 ifrs17-template/Test/ScenarioParametersImportTest.ipynb diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb deleted file mode 100644 index 50e4f4fc..00000000 --- a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb +++ /dev/null @@ -1,223 +0,0 @@ -{ - "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": [ - "#!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": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - } - ] -} \ No newline at end of file diff --git a/ifrs17-template/Test/Tests.ipynb b/ifrs17-template/Test/Tests.ipynb index 4a12e27e..7cc5ce85 100644 --- a/ifrs17-template/Test/Tests.ipynb +++ b/ifrs17-template/Test/Tests.ipynb @@ -71,15 +71,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "#!eval-notebook \"ScenarioParametersImportTest\"" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -144,4 +135,4 @@ "outputs": [] } ] -} \ No newline at end of file +} From 9b29aee5478ae506ffe2b397f57b2d1bc6eff684 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Thu, 9 Mar 2023 15:22:23 +0100 Subject: [PATCH 5/5] fix scenario reports --- .../Test/ScenarioYieldCurveImportTest.ipynb | 25 ++------- ifrs17/Constants/Consts.ipynb | 54 +++++++++++++++---- ifrs17/Import/ImportStorage.ipynb | 2 +- ifrs17/Report/ReportMutableScopes.ipynb | 10 ++-- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index 57245c6d..5e870b40 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,18 +86,9 @@ { "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];", + "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 actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" 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/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} " ],