diff --git a/ifrs17-template/Files/DataNodes/DataNodes_CH.csv b/ifrs17-template/Files/DataNodes/DataNodes_CH.csv index c694756e..8dfaa92d 100644 --- a/ifrs17-template/Files/DataNodes/DataNodes_CH.csv +++ b/ifrs17-template/Files/DataNodes/DataNodes_CH.csv @@ -3,7 +3,7 @@ ReportingNode,,,,,, CH,,,,,, ,,,,,, @@InsurancePortfolio,,,,,, -SystemName,DisplayName,ContractualCurrency,LineOfBusiness,ValuationApproach,OciType, +SystemName,DisplayName,ContractualCurrency,LineOfBusiness,ValuationApproach,OciType,Scenario, DT,DT Complex CF,USD,ANN,BBA,Default, DT1,DT1 OCI,USD,ANN,BBA,Default, DT2,DT2 NOCI,USD,ANN,BBA,, @@ -12,7 +12,7 @@ DT4,DT4 OCI,USD,ANN,BBA,Default, DT5,DT5 Simple Import,USD,ANN,BBA,Default, ,,,,,, @@GroupOfInsuranceContract,,,,,, -SystemName,DisplayName,InsurancePortfolio,AnnualCohort,LiabilityType,Profitability, +SystemName,DisplayName,InsurancePortfolio,AnnualCohort,LiabilityType,Profitability,Scenario, GicComplex,Gic test discounting,DT,2020,LRC,P, DT1.1,DT1.1 OCI LRC PA 0.8,DT1,2020,LRC,P, DT1.2,DT1.2 OCI LIC,DT1,2020,LIC,P, @@ -26,13 +26,13 @@ DT4.1,DT4.1 CSM PA 0.8,DT4,2020,LRC,P, DT5.1,DT5.1 Simple Import on DT 4.1,DT5,2020,LRC,P, ,,,,,, @@ReinsurancePortfolio,,,,,, -SystemName,DisplayName,ContractualCurrency,LineOfBusiness,ValuationApproach,OciType, +SystemName,DisplayName,ContractualCurrency,LineOfBusiness,ValuationApproach,OciType,Scenario, DTR,DTR complex CF,USD,ANN,BBA,, DTR1,DTR1 OCI,USD,ANN,BBA,Default, DTR2,DTR2 NOCI,USD,ANN,BBA,, ,,,,,, @@GroupOfReinsuranceContract,,,,,, -SystemName,DisplayName,ReinsurancePortfolio,AnnualCohort,LiabilityType,Profitability,Partner +SystemName,DisplayName,ReinsurancePortfolio,AnnualCohort,LiabilityType,Profitability,Partner,Scenario, GricComplex,Gric test for discounting,DTR,2020,LRC,P,PT1 DTR1.1,DTR1.1 OCI LRC,DTR1,2020,LRC,P,PT1 DTR1.2,DTR1.2 OCI LIC,DTR1,2020,LIC,P,PT1 diff --git a/ifrs17-template/Files/Parameters/YieldCurve_2020_1.csv b/ifrs17-template/Files/Parameters/YieldCurve_2020_1.csv new file mode 100644 index 00000000..a8a0e4a4 --- /dev/null +++ b/ifrs17-template/Files/Parameters/YieldCurve_2020_1.csv @@ -0,0 +1,7 @@ +@@Main +Year,Month,Scenario +2020,1, +@@YieldCurve +Currency,Values0,Values1,Values2,Values3 +USD,0.002,0.002,0.002,0.002 + diff --git a/ifrs17-template/Files/Parameters/YieldCurve_2020_12.csv b/ifrs17-template/Files/Parameters/YieldCurve_2020_12.csv new file mode 100644 index 00000000..c7c38f28 --- /dev/null +++ b/ifrs17-template/Files/Parameters/YieldCurve_2020_12.csv @@ -0,0 +1,7 @@ +@@Main +Year,Month,Scenario +2020,12, +@@YieldCurve +Currency,Values0,Values1,Values2,Values3 +USD,0.002,0.002,0.002,0.002 + diff --git a/ifrs17-template/Files/Parameters/YieldCurve_2020_3.csv b/ifrs17-template/Files/Parameters/YieldCurve_2020_3.csv new file mode 100644 index 00000000..febe06aa --- /dev/null +++ b/ifrs17-template/Files/Parameters/YieldCurve_2020_3.csv @@ -0,0 +1,9 @@ +@@Main +Year,Month,Scenario +2020,3, +@@YieldCurve +Currency,Values0,Values1,Values2,Values3 +EUR,0.008685495,0.008685495,0.018498471,0.019966839 +CHF,0.002,0.002,0.002,0.002 +USD,0.002,0.002,0.002,0.002 +GBP,0.002,0.002,0.002,0.002 diff --git a/ifrs17-template/Files/Parameters/YieldCurve_2021_3.csv b/ifrs17-template/Files/Parameters/YieldCurve_2021_3.csv new file mode 100644 index 00000000..2e2f41f5 --- /dev/null +++ b/ifrs17-template/Files/Parameters/YieldCurve_2021_3.csv @@ -0,0 +1,8 @@ +@@Main +Year,Month,Scenario +2021,3, +@@YieldCurve +Currency,Values0,Values1,Values2,Values3 +CHF,0.1,0.1,0.1,0.1 +USD,0.005,0.005,0.005,0.005 +GBP,0.005,0.005,0.005,0.005 diff --git a/ifrs17-template/Import/CloseImportTemplate.ipynb b/ifrs17-template/Import/CloseImportTemplate.ipynb index 1f9b84ac..c69e4bdb 100644 --- a/ifrs17-template/Import/CloseImportTemplate.ipynb +++ b/ifrs17-template/Import/CloseImportTemplate.ipynb @@ -91,6 +91,7 @@ "\n- ImportFormats.DataNode : [Portfolios](https://portal.systemorph.cloud/project/ifrs17/env/v1.0.0/DataModel/DataStructure#portfolios) and [Group of Contracts](https://portal.systemorph.cloud/project/ifrs17/env/v1.0.0/DataModel/DataStructure#group-of-contracts)", "\n- ImportFormats.DataNodeState : the [state of a data node](https://portal.systemorph.cloud/project/ifrs17/env/v1.0.0/DataModel/DataStructure#data-node-state) can be either active or inactive.", "\n- ImportFormats.DataNodeParameter : parameters are described [here](https://portal.systemorph.cloud/project/ifrs17/env/v1.0.0/DataModel/DataStructure#data-node-parameters). For **Group of Insurance Contracts** a default [Premium Allocation factor](https://portal.systemorph.cloud/project/ifrs17/env/v1.0.0/Import/ImportScopeCalculation#experience-adjustment-on-premium) of 1 is applied if the parameter is not imported.", + "\n- ImportFormat.YieldCurve : TODO", "\n" ], "metadata": {}, diff --git a/ifrs17-template/Initialization/InitSystemorphRefDataToMemory.ipynb b/ifrs17-template/Initialization/InitSystemorphRefDataToMemory.ipynb index b0125ccd..e23769f2 100644 --- a/ifrs17-template/Initialization/InitSystemorphRefDataToMemory.ipynb +++ b/ifrs17-template/Initialization/InitSystemorphRefDataToMemory.ipynb @@ -154,7 +154,12 @@ { "cell_type": "code", "source": [ - "await Import.FromFile(\"../Files/Parameters/YieldCurve.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync()" + "//await Import.FromFile(\"../Files/Parameters/YieldCurve.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync()", + "\nvar log1 = await Import.FromFile(\"../Files/Parameters/YieldCurve_2020_1.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync();", + "\nvar log2 = await Import.FromFile(\"../Files/Parameters/YieldCurve_2020_3.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync();", + "\nvar log3 = await Import.FromFile(\"../Files/Parameters/YieldCurve_2020_12.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync();", + "\nvar log4 = await Import.FromFile(\"../Files/Parameters/YieldCurve_2021_3.csv\").WithType().SnapshotMode().WithTarget(DataSource).ExecuteAsync();", + "\nlog1.Merge(log2).Merge(log3).Merge(log4)" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioParameterTest.ipynb b/ifrs17-template/Test/ScenarioParameterTest.ipynb new file mode 100644 index 00000000..a7c27330 --- /dev/null +++ b/ifrs17-template/Test/ScenarioParameterTest.ipynb @@ -0,0 +1,181 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Context" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphToMemory\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nWorkspace.Initialize(x => x.FromSource(DataSource));", + "\nvar defaultVarsBE = Workspace.Query();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Yield Curve Scenario" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var yieldCurve = @\"", + "\n@@YieldCurve", + "\nCurrency,Year,Month,Scenario,Values0,Values1,Values2,Values3", + "\nEUR,2020,3,,0.008685495,0.008685495,0.018498471,0.019966839", + "\nCHF,2020,3,,0.002,0.002,0.002,0.002", + "\nCHF,2021,3,,0.1,0.1,0.1,0.1", + "\nUSD,2021,3,,0.005,0.005,0.005,0.005", + "\nUSD,2020,12,,0.002,0.002,0.002,0.002", + "\nUSD,2020,3,,0.002,0.002,0.002,0.002", + "\nUSD,2020,1,,0.002,0.002,0.002,0.002", + "\nEUR,2018,3,MTUP10pct,0.009554045,0.009554045,0.020348318,0.021963523", + "\nCHF,2018,3,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nCHF,2019,3,MTUP10pct,0.11,0.11,0.11,0.11", + "\nUSD,2019,3,MTUP10pct,0.0055,0.0055,0.0055,0.0055", + "\nUSD,2018,12,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nUSD,2018,3,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nUSD,2018,1,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nEUR,2020,12,MTUP10pct,0.009554045,0.009554045,0.020348318,0.021963523", + "\nCHF,2020,12,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nCHF,2021,3,MTUP10pct,0.11,0.11,0.11,0.11", + "\nUSD,2021,3,MTUP10pct,0.0055,0.0055,0.0055,0.0055", + "\nUSD,2020,12,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nUSD,2020,3,MTUP10pct,0.0022,0.0022,0.0022,0.0022", + "\nUSD,2020,1,MTUP10pct,0.0022,0.0022,0.0022,0.0022\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var log = await Import.FromString(yieldCurve).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync();", + "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nWorkspace.Initialize(x => x.FromSource(DataSource));", + "\nlog.Warnings.Count().Should().Be(6);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Test 2020Q4 with Scenario MTUP10pct" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "log" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var argsBestEstimate = new ImportArgs (\"CH\",2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar defaultPartition = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsBestEstimate)); ", + "\n", + "\nvar scenarioArgs = new ImportArgs (\"CH\",2020, 12, Periodicity.Quarterly, \"MTUP10pct\", ImportFormats.Cashflow);", + "\nawait Workspace.Partition.SetAsync(scenarioArgs);", + "\nawait DataSource.Partition.SetAsync(scenarioArgs);", + "\nvar diffIfrsVars = Workspace.Query().Except(defaultVarsBE.Where(x => x.Partition == defaultPartition).ToArray(), IfrsVariableComparer.Instance());", + "\ndiffIfrsVars.ToArray().Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Test 2021Q1 with Scenario MTUP10pct" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var argsBestEstimate = new ImportArgs (\"CH\",2021, 3, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar defaultPartition = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsBestEstimate)); ", + "\n", + "\nvar scenarioArgs = new ImportArgs (\"CH\",2021, 3, Periodicity.Quarterly, \"MTUP10pct\", ImportFormats.Cashflow);", + "\nawait Workspace.Partition.SetAsync(scenarioArgs);", + "\nawait DataSource.Partition.SetAsync(scenarioArgs);", + "\nvar diffIfrsVars = Workspace.Query().Except(defaultVarsBE.Where(x => x.Partition == defaultPartition).ToArray(), IfrsVariableComparer.Instance());", + "\ndiffIfrsVars.ToArray().Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Robustness: Reimport does not trigger Calculations" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var log = await Import.FromString(yieldCurve).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync();", + "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nWorkspace.Initialize(x => x.FromSource(DataSource));", + "\nlog.Warnings.Count().Should().Be(1);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17-template/Test/ScenarioTest.ipynb b/ifrs17-template/Test/ScenarioTest.ipynb index 8effcfa3..3ace96dc 100644 --- a/ifrs17-template/Test/ScenarioTest.ipynb +++ b/ifrs17-template/Test/ScenarioTest.ipynb @@ -27,7 +27,27 @@ { "cell_type": "code", "source": [ - "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"", + "\nvar actual_EstimateTypes = new[] {\"A\",\"AA\",\"OA\",\"DA\"};", + "\nvar args_Best_Estimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar args_Test_Scenario = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"Test\", ImportFormats.Cashflow);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task ImportAndInitializeWorkspaceAsync(string inputString, string importFormat, bool fromFile = true)", + "\n{ ", + "\n var log = fromFile ", + "\n ? await Import.FromFile(inputString).WithFormat(importFormat).WithTarget(DataSource).ExecuteAsync()", + "\n : await Import.FromString(inputString).WithFormat(importFormat).WithTarget(DataSource).ExecuteAsync();", + "\n Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\n Workspace.Initialize(x => x.FromSource(DataSource));", + "\n return log;", + "\n}" ], "metadata": {}, "execution_count": 0, @@ -45,10 +65,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12.csv\").WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(\"../Files/TransactionalData/NominalCashflows_CH_2020_12.csv\", ImportFormats.Cashflow)" ], "metadata": {}, "execution_count": 0, @@ -57,10 +74,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromFile(\"../Files/TransactionalData/Actuals_CH_2020_12.csv\").WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(\"../Files/TransactionalData/Actuals_CH_2020_12.csv\", ImportFormats.Actual)" ], "metadata": {}, "execution_count": 0, @@ -123,10 +137,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromString(cashflows_scenarioTest).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(cashflows_scenarioTest, ImportFormats.Cashflow, false)" ], "metadata": {}, "execution_count": 0, @@ -135,11 +146,11 @@ { "cell_type": "code", "source": [ - "await Workspace.Partition.SetAsync(new{ReportingNode = \"CH\", Scenario = \"Test\", Year = 2020, Month = 12});", - "\nawait DataSource.Partition.SetAsync(new{ReportingNode = \"CH\", Scenario = \"Test\", Year = 2020, Month = 12});", + "await Workspace.Partition.SetAsync(args_Test_Scenario);", + "\nawait DataSource.Partition.SetAsync(args_Test_Scenario);", "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", - "\ndiffs.Where(x => (new[]{\"A\",\"AA\",\"OA\",\"DA\"}).Contains(x.EstimateType)).ToArray().Length.Should().Be(0);", - "\ndiffs.Where(x => !(new[]{\"A\",\"AA\",\"OA\",\"DA\"}).Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);" + "\ndiffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().Be(0);", + "\ndiffs.Where(x => !actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, @@ -187,10 +198,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromString(actuals_scenarioTest).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(actuals_scenarioTest, ImportFormats.Actual, false)" ], "metadata": {}, "execution_count": 0, @@ -199,10 +207,10 @@ { "cell_type": "code", "source": [ - "await Workspace.Partition.SetAsync(new{ReportingNode = \"CH\", Scenario = \"Test\", Year = 2020, Month = 12});", - "\nawait DataSource.Partition.SetAsync(new{ReportingNode = \"CH\", Scenario = \"Test\", Year = 2020, Month = 12});", + "await Workspace.Partition.SetAsync(args_Test_Scenario);", + "\nawait DataSource.Partition.SetAsync(args_Test_Scenario);", "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", - "\ndiffs.Where(x => (new[]{\"A\",\"AA\",\"OA\",\"DA\"}).Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);", + "\ndiffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);", "\ndiffs.Where(x => x.EstimateType == \"CU\").ToArray().Length.Should().Be(0);" ], "metadata": {}, @@ -221,10 +229,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromString(actuals_scenarioTest_equalTo_BestEstimate).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(actuals_scenarioTest_equalTo_BestEstimate, ImportFormats.Actual, false)" ], "metadata": {}, "execution_count": 0, @@ -233,10 +238,7 @@ { "cell_type": "code", "source": [ - "var log = await Import.FromString(cashflows_scenarioTest_equalTo_BestEstimate).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync();", - "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\nWorkspace.Initialize(x => x.FromSource(DataSource));", - "\nlog" + "await ImportAndInitializeWorkspaceAsync(cashflows_scenarioTest_equalTo_BestEstimate, ImportFormats.Cashflow, false)" ], "metadata": {}, "execution_count": 0, @@ -251,10 +253,126 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Reimport of Best Estimate Cashflow" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var new_Cashflows_BestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Cashflow", + "\nDataNode,AmountType,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,CL,C,,210,0,0,210,0,0,210,0,0,210,0,0,0,210,0,0,210,0,0,210,0,0,210,0", + "\nDT1.1,NIC,CL,C,,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37,-37", + "\nDT1.1,CU,CL,C,,-21,-21,-21,-21,-21,-21,-21,-21,-21,-21,-21,-21,-21,-17,-17,-17,-17,-17,-17,-17,-17,-17,-17,-3.3", + "\nDT1.1,RA,CL,C,,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42,-42\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await ImportAndInitializeWorkspaceAsync(new_Cashflows_BestEstimate, ImportFormats.Cashflow, false)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ - "" + "await Workspace.Partition.SetAsync(args_Best_Estimate);", + "\nawait DataSource.Partition.SetAsync(args_Best_Estimate);", + "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", + "\nvar items = diffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).Select(x => x.EstimateType).Distinct().ToArray();", + "\nitems.Length.Should().Be(1);", + "\n(items.First() == \"DA\").Should().Be(true);", + "\ndiffs.Where(x => !actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.Partition.SetAsync(args_Test_Scenario);", + "\nawait DataSource.Partition.SetAsync(args_Test_Scenario);", + "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", + "\nvar items = diffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).Select(x => x.EstimateType).Distinct().ToArray();", + "\nitems.Length.Should().Be(1);", + "\n(items.First() == \"DA\").Should().Be(true);", + "\ndiffs.Where(x => !actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reimport of Best Estimate Actuals" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var new_actuals_BestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,NIC,,-2000\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await ImportAndInitializeWorkspaceAsync(new_actuals_BestEstimate, ImportFormats.Actual, false)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.Partition.SetAsync(args_Best_Estimate);", + "\nawait DataSource.Partition.SetAsync(args_Best_Estimate);", + "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", + "\ndiffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == \"CU\").ToArray().Length.Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.Partition.SetAsync(args_Test_Scenario);", + "\nawait DataSource.Partition.SetAsync(args_Test_Scenario);", + "\nvar diffs = Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance());", + "\ndiffs.Where(x => actual_EstimateTypes.Contains(x.EstimateType)).ToArray().Length.Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == \"CU\").ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioViaBestEstimateTest.ipynb b/ifrs17-template/Test/ScenarioViaBestEstimateTest.ipynb new file mode 100644 index 00000000..766ee1e4 --- /dev/null +++ b/ifrs17-template/Test/ScenarioViaBestEstimateTest.ipynb @@ -0,0 +1,213 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphToMemory\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nWorkspace.Initialize(x => x.FromSource(DataSource));", + "\nvar defaulttRawVarsBE = await DataSource.Query().ToArrayAsync();", + "\nvar defaultVarsBE = await Workspace.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var yieldCurve_Test = @\"", + "\n@@YieldCurve", + "\nCurrency,Year,Month,Scenario,Values0,Values1,Values2,Values3", + "\nUSD,2021,6,,0.003,0.003,0.003,0.003", + "\nUSD,2021,6,MTUP10pct,0.103,0.103,0.103,0.103\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflows_BestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2021,6,", + "\n@@Cashflow", + "\nDataNode,AmountType,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,CL,C,,110,0,0,110,0,0,110,0,0,110,0,0,0,110,0,0,110,0,0,110,0,0,110,0", + "\nDT1.1,NIC,CL,C,,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5,-27.5", + "\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,-5.5,-5.5,-5.5,-5.5,-5.5,-3.3", + "\nDT1.1,RA,CL,C,,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75,-2.75\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actuals_BestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2021,6,", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,NIC,,-3008\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var argsBestEstimate = new ImportArgs (\"CH\", 2021, 6, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenario = new ImportArgs (\"CH\", 2021, 6, Periodicity.Quarterly, \"MTUP10pct\", ImportFormats.Cashflow);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var yieldCurveLog = await Import.FromString(yieldCurve_Test).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync();", + "\nWorkspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nWorkspace.Initialize(x => x.FromSource(DataSource));", + "\nyieldCurveLog" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Import Cashflow" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflows_BestEstimate).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nawait DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar rawVarsBE = await DataSource.Query().ToArrayAsync();", + "\nvar ifrsVarsBE = await DataSource.Query().ToArrayAsync();", + "\nrawVarsBE.Length.Should().NotBe(0);", + "\nifrsVarsBE.Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nawait DataSource.Partition.SetAsync(argsScenario);", + "\nvar rawVarsSCE = await DataSource.Query().ToArrayAsync();", + "\nvar ifrsVarsSCE = await DataSource.Query().ToArrayAsync();", + "\nrawVarsSCE.Length.Should().Be(0);", + "\nifrsVarsSCE.Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "ifrsVarsSCE.Where(x => x.EconomicBasis == \"C\").Intersect(ifrsVarsBE.Where(x => x.EconomicBasis == \"C\"), IfrsVariableComparer.Instance()).ToArray().Length.Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Import Actuals" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actuals_BestEstimate).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nawait DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar newRawVarsBE = await DataSource.Query().ToArrayAsync();", + "\nvar newIfrsVarsBE = await DataSource.Query().ToArrayAsync();", + "\nnewRawVarsBE.Length.Should().NotBe(0);", + "\nnewIfrsVarsBE.Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "newIfrsVarsBE.Except(ifrsVarsBE, IfrsVariableComparer.Instance()).ToArray().Length.Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17/Constants/Consts.ipynb b/ifrs17/Constants/Consts.ipynb index ceb279db..fdaef659 100644 --- a/ifrs17/Constants/Consts.ipynb +++ b/ifrs17/Constants/Consts.ipynb @@ -201,6 +201,7 @@ "\n public const string DataNode = nameof(DataNode); // Importer for Data Node", "\n public const string DataNodeState = nameof(DataNodeState); // Importer for Data Node State", "\n public const string DataNodeParameter = nameof(DataNodeParameter); // Importer for Data Node Parameters", + "\n public const string YieldCurve = nameof(YieldCurve); // Importer for YieldCurve", "\n", "\n public const string AocConfiguration = nameof(AocConfiguration); // Importer for Analysis of Change Configuration settings", "\n}" diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 79f3dd04..cd6a98c4 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -1194,7 +1194,7 @@ "\n [Dimension(typeof(Currency))]", "\n public string Currency { get; init; }", "\n", - "\n [Required]", + "\n //[Required]", "\n [IdentityProperty]", "\n [NoArithmetics(ArithmeticOperation.Scale)]", "\n [Dimension(typeof(int), nameof(Year))]", @@ -1202,7 +1202,7 @@ "\n [Display(Order = 20)]", "\n public int Year { get; init; }", "\n ", - "\n [Required]", + "\n //[Required]", "\n [IdentityProperty]", "\n [NoArithmetics(ArithmeticOperation.Scale)]", "\n [Dimension(typeof(int), nameof(Month))]", @@ -1301,11 +1301,6 @@ "\n [Dimension(typeof(ReportingNode))]", "\n [IdentityProperty]", "\n public string ReportingNode { get; init; }", - "\n", - "\n [Display(Order = 50)]", - "\n [Dimension(typeof(Scenario))]", - "\n [IdentityProperty]", - "\n public string Scenario { get; init; }", "\n}" ], "metadata": {}, @@ -1352,6 +1347,11 @@ "\n [Dimension(typeof(int), nameof(Month))]", "\n [IdentityProperty]", "\n public int Month { get; init; }", + "\n ", + "\n [Display(Order = 50)]", + "\n [Dimension(typeof(Scenario))]", + "\n [IdentityProperty]", + "\n public string Scenario { get; init; }", "\n}" ], "metadata": {}, @@ -1422,6 +1422,11 @@ "\n [Dimension(typeof(OciType))]", "\n //[Immutable]", "\n public string OciType { get; init; }", + "\n ", + "\n [NotVisible] ", + "\n [Dimension(typeof(Scenario))]", + "\n //[Immutable]", + "\n public string Scenario { get; init; }", "\n}" ], "metadata": {}, diff --git a/ifrs17/Export/ExportConfiguration.ipynb b/ifrs17/Export/ExportConfiguration.ipynb index 1190acbc..8eb90368 100644 --- a/ifrs17/Export/ExportConfiguration.ipynb +++ b/ifrs17/Export/ExportConfiguration.ipynb @@ -69,8 +69,7 @@ "\n => builder.WithTable( config => config .AtBeginning() ", "\n .WithName(Main) ", "\n .WithSource(source => args.RepeatOnce().AsQueryable()) ", - "\n .WithColumn(x => x.Id, x => x.Delete())", - "\n .WithColumn(x => x.Scenario, x => x.Delete()));" + "\n .WithColumn(x => x.Id, x => x.Delete()));" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index c6572abc..2553e0d1 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -174,8 +174,8 @@ "\n await workspace.Partition.SetAsync(TargetPartition);", "\n ", "\n //Get data from Workspace (result of parsing)", - "\n var parsedRawVariables = await workspace.Query().ToArrayAsync();", - "\n var parsedIfrsVariables = await workspace.Query().ToArrayAsync();", + "\n var parsedRawVariables = await workspace.LoadVariablesRelaxedAsync(querySource, TargetPartition, DefaultPartition);", + "\n var parsedIfrsVariables = await workspace.LoadVariablesRelaxedAsync(querySource, TargetPartition, DefaultPartition);", "\n ", "\n //DataNodes", "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 3cd1de4a..06e97288 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -309,7 +309,7 @@ "source": [ "## Parse Main Tab and return Args", "\n", - "\nThe main table of our custom import formats contains the information which are required to identify the data partition. These information are temporarily stored in [Args](../DataModel/DataStructure#args) and used in the next methods. " + "\nThe main table of our custom import formats contains the information which are required to identify the data partition. These information are temporarily stored in [Args](../DataModel/DataStructure#args) and used in the next methods." ], "metadata": {}, "execution_count": 0, @@ -329,7 +329,6 @@ "\n var main = mainTab.Rows.First();", "\n var reportingNode = (string)main[nameof(ReportingNode)];", "\n var scenario = mainTab.Columns.Where(x => x.ColumnName == nameof(Scenario)).Count()>0? (string)main[nameof(Scenario)] : default(string);", - "\n", "\n ImportArgs args;", "\n switch(typeof(IPartition).Name) {", "\n case nameof(PartitionByReportingNode) : {", @@ -341,8 +340,7 @@ "\n default(string));", "\n await DataSource.UpdateAsync( new[] { new PartitionByReportingNode { ", "\n Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(args)),", - "\n ReportingNode = reportingNode, ", - "\n Scenario = scenario } } );", + "\n ReportingNode = reportingNode } } );", "\n break;", "\n }", "\n case nameof(PartitionByReportingNodeAndPeriod) : {", @@ -377,6 +375,34 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "public async Task CalculateAndUploadIfrsVariablesAsync(ImportArgs args, IWorkspace workspace)", + "\n{", + "\n Activity.Start();", + "\n var storage = new ImportStorage(args, DataSource, workspace);", + "\n await storage.InitializeAsync();", + "\n if(Activity.HasErrors()) return Activity.Finish();", + "\n ", + "\n var universe = Scopes.ForStorage(storage).ToScope();", + "\n var identities = universe.GetScopes(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);", + "\n var ivs = universe.GetScopes(identities).SelectMany(x => x.CalculatedIfrsVariables);", + "\n if(Activity.HasErrors()) return Activity.Finish();", + "\n ", + "\n await workspace.UpdateAsync(ivs);", + "\n await CommitToDatabase(workspace,", + "\n storage.TargetPartition, ", + "\n snapshot : true, ", + "\n filter : x => storage.EstimateTypesByImportFormat[args.ImportFormat].Contains(x.EstimateType) && ", + "\n storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n return Activity.Finish();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -391,27 +417,23 @@ "source": [ "public async Task DataNodeFactoryAsync(IDataSet dataSet, string tableName, ImportArgs args)", "\n{", - "\n var partition = (await DataSource.Query().Where(p => p.ReportingNode == args.ReportingNode && p.Scenario == null).ToArrayAsync()).SingleOrDefault();", + "\n var partition = (await DataSource.Query().Where(p => p.ReportingNode == args.ReportingNode).ToArrayAsync()).SingleOrDefault();", "\n if(partition == null) { ApplicationMessage.Log(Error.ParsedPartitionNotFound); return; }", - "\n", + "\n ", "\n var table = dataSet.Tables[tableName];", - "\n", + "\n ", "\n var dataNodesImported = table.Rows.Select(x => x.Field(nameof(RawVariable.DataNode))).ToHashSet();", "\n var dataNodesDefined = await DataSource.Query().Where(x => dataNodesImported.Contains(x.SystemName)).ToArrayAsync();", "\n var dataNodeStatesDefined = await DataSource.Query().Select(x => x.DataNode).ToArrayAsync();", "\n var dataNodeParametersDefined = await DataSource.Query().Select(x => x.DataNode).ToArrayAsync(); ", - "\n", "\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Contains(x)).ToHashSet();", "\n var dataNodeSingleParametersUndefined = dataNodesImported.Where(x => x != null &&", "\n !dataNodeParametersDefined.Contains(x) && ", "\n dataNodesDefined.SingleOrDefault(y => y.SystemName == x) is GroupOfInsuranceContract).ToHashSet();", - "\n", "\n await DataSource.UpdateAsync( dataNodeStatesUndefined.Select(x => ", "\n new DataNodeState {DataNode = x, Year = args.Year, Month = DefaultDataNodeActivationMonth, State = State.Active, Partition = partition.Id}).ToArray() );", - "\n", "\n await DataSource.UpdateAsync( dataNodeSingleParametersUndefined.Select(x => ", "\n new SingleDataNodeParameter {DataNode = x, Year = args.Year, Month = DefaultDataNodeActivationMonth, PremiumAllocation = DefaultPremiumExperienceAdjustmentFactor, Partition = partition.Id}).ToArray() );", - "\n", "\n await DataSource.CommitAsync();", "\n}" ], @@ -432,11 +454,12 @@ "cell_type": "code", "source": [ "public async Task ValidateForDataNodeStateActiveAsync(IWorkspace workspace, Dictionary dataNodes) where T : BaseDataRecord", - "\n{", + "\n{ ", "\n foreach(var item in (await workspace.Query().ToArrayAsync()).GroupBy(x => x.DataNode))", "\n if(!dataNodes.ContainsKey(item.First().DataNode))", "\n ApplicationMessage.Log(Error.InactiveDataNodeState, item.First().DataNode);", - "\n}" + "\n}", + "\n" ], "metadata": {}, "execution_count": 0, @@ -454,7 +477,7 @@ { "cell_type": "markdown", "source": [ - "The [Analysis of Change configuration](../DataModel/DataStructure#aoc-step-configuration) is parsed from the input file and complemented with defaults to allow for an easy insertion of new AoC steps. ", + "The [Analysis of Change configuration](../DataModel/DataStructure#aoc-step-configuration) is parsed from the input file and complemented with defaults to allow for an easy insertion of new AoC Steps.", "\n", "\nAfter having checked that the [AocTypes](../DataModel/DataStructure#aoc-variable-type) loaded in the target DataSource are including all the compulsory ones, default configurations are generated on the basis of the AocTypes ordering. ", "\n", @@ -558,7 +581,76 @@ { "cell_type": "markdown", "source": [ - "# Data Nodes", + "# Yield Curves" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Import.DefineFormat(ImportFormats.YieldCurve, async (options, dataSet) => {", + "\n Activity.Start();", + "\n var mainTab = dataSet.Tables[Main];", + "\n if(mainTab == null) ApplicationMessage.Log(Error.NoMainTab);", + "\n if(mainTab.Rows.Count() == 0) ApplicationMessage.Log(Error.IncompleteMainTab);", + "\n if(mainTab.Columns.Where(x => x.ColumnName == nameof(PartitionByReportingNodeAndPeriod.Year)).Count()!=1) ApplicationMessage.Log(Error.YearInMainNotFound);", + "\n if(mainTab.Columns.Where(x => x.ColumnName == nameof(PartitionByReportingNodeAndPeriod.Month)).Count()!=1) ApplicationMessage.Log(Error.MonthInMainNotFound);", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", + "\n ", + "\n var main = mainTab.Rows.First();", + "\n var scenario = mainTab.Columns.Where(x => x.ColumnName == nameof(Scenario)).Count()>0? (string)main[nameof(Scenario)] : default(string);", + "\n var year = (int)Convert.ChangeType(main[nameof(PartitionByReportingNodeAndPeriod.Year)], typeof(int));", + "\n var month = (int)Convert.ChangeType(main[nameof(PartitionByReportingNodeAndPeriod.Year)], typeof(int));", + "\n var workspace = Workspace.CreateNew();", + "\n workspace.Initialize(x => x.FromSource(DataSource).DisableInitialization().DisableInitialization());", + "\n ", + "\n var oldYieldCurves = await workspace.Query().ToArrayAsync();", + "\n var parsingLog = await Import.FromDataSet(dataSet).WithType().WithTarget(workspace).ExecuteAsync(); ", + "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog); ", + "\n var newYieldCurves = await workspace.Query().ToArrayAsync();", + "\n ", + "\n newYieldCurves = newYieldCurves.Except(oldYieldCurves, YieldCurveComparer.Instance()).ToArray();", + "\n if (!newYieldCurves.Any()){", + "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", + "\n return Activity.Finish().Merge(parsingLog);", + "\n }", + "\n ", + "\n await DataSource.UpdateAsync(newYieldCurves);", + "\n await DataSource.CommitAsync();", + "\n", + "\n var targetArgs = (await DataSource.Query().ToArrayAsync())", + "\n .Where(x => x.Year == year && x.Month == month && x.Scenario == scenario)", + "\n .Select(x => new ImportArgs( x.ReportingNode,", + "\n x.Year, ", + "\n x.Month,", + "\n Periodicity.Quarterly,", + "\n x.Scenario,", + "\n ImportFormats.Cashflow)).ToArray();", + "\n", + "\n //var calculationLog = await CalculationYieldCurvesAsync(targetArgs);", + "\n", + "\n return Activity.Finish().Merge(parsingLog);//.Merge(calculationLog);", + "\n});" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Nodes" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "", "\n", "\n[Portfolios](../DataModel/DataStructure#portfolios) and [Group of Contracts](../DataModel/DataStructure#group-of-contracts) are imported in the same file. " ], @@ -596,7 +688,8 @@ "\n FunctionalCurrency = storage.ReportingNode.Currency,", "\n LineOfBusiness = datarow.Field(nameof(DataNode.LineOfBusiness)),", "\n ValuationApproach = datarow.Field(nameof(DataNode.ValuationApproach)),", - "\n OciType = datarow.Field(nameof(DataNode.OciType))", + "\n OciType = datarow.Field(nameof(DataNode.OciType)),", + "\n Scenario = datarow.Field(nameof(DataNode.Scenario))", "\n })", "\n .WithType((dataset, datarow) =>new ReinsurancePortfolio {", "\n SystemName = datarow.Field(nameof(DataNode.SystemName)),", @@ -606,7 +699,8 @@ "\n FunctionalCurrency = storage.ReportingNode.Currency,", "\n LineOfBusiness = datarow.Field(nameof(DataNode.LineOfBusiness)),", "\n ValuationApproach = datarow.Field(nameof(DataNode.ValuationApproach)),", - "\n OciType = datarow.Field(nameof(DataNode.OciType))", + "\n OciType = datarow.Field(nameof(DataNode.OciType)),", + "\n Scenario = datarow.Field(nameof(DataNode.Scenario))", "\n })", "\n .WithTarget(workspace)", "\n .ExecuteAsync();", @@ -733,7 +827,6 @@ "\n .DisableInitialization()", "\n .DisableInitialization()", "\n .DisableInitialization());", - "\n ", "\n Activity.Start();", "\n var args = await GetArgsFromMainAsync(dataSet);", "\n if(Activity.HasErrors()) return Activity.Finish();", @@ -793,7 +886,6 @@ "\n .DisableInitialization()", "\n .DisableInitialization()", "\n .DisableInitialization());", - "\n ", "\n Activity.Start();", "\n var args = await GetArgsFromMainAsync(dataSet) with {ImportFormat = ImportFormats.DataNodeParameter};", "\n if(Activity.HasErrors()) return Activity.Finish();", @@ -881,6 +973,7 @@ "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, partitionId, workspace);", "\n await CommitToDatabase(workspace, partitionId, snapshot: false);", "\n await CommitToDatabase(workspace, partitionId, snapshot: false); ", + "\n ", "\n return log;", "\n});" ], @@ -978,35 +1071,31 @@ "source": [ "Import.DefineFormat(ImportFormats.Cashflow, async (options, dataSet) => {", "\n Activity.Start();", - "\n var args = (await GetArgsFromMainAsync(dataSet)) with {ImportFormat = ImportFormats.Cashflow};", - "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Cashflow, args);", + "\n var mainArgs = (await GetArgsFromMainAsync(dataSet)) with {ImportFormat = ImportFormats.Cashflow};", + "\n if(Activity.HasErrors()) return Activity.Finish();", + "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Cashflow, mainArgs);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n ", "\n var workspace = Workspace.CreateNew();", - "\n var parsingLog = await ParseCashflowsToWorkspaceAsync(dataSet, args, workspace);", - "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", + "\n var log = await ParseCashflowsToWorkspaceAsync(dataSet, mainArgs, workspace);", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n", + "\n var targetArgs = mainArgs.Scenario == null ", + "\n ? mainArgs.RepeatOnce().Concat(await DataSource.Query() // TODO: check that concat is adding at the end of the list", + "\n .Where(x => x.ReportingNode == mainArgs.ReportingNode && x.Year == mainArgs.Year && x.Month == mainArgs.Month && x.Scenario != null)", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, Periodicity.Quarterly, x.Scenario, ImportFormats.Cashflow)).ToArrayAsync())", + "\n : mainArgs.RepeatOnce();", "\n ", - "\n var storage = new ImportStorage(args, DataSource, workspace);", - "\n await storage.InitializeAsync();", - "\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);", - "\n ", - "\n var universe = Scopes.ForStorage(storage).ToScope();", - "\n var identities = universe.GetScopes(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);", - "\n var ivs = universe.GetScopes(identities).SelectMany(x => x.CalculatedIfrsVariables);", - "\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);", - "\n ", - "\n await workspace.UpdateAsync(ivs);", - "\n await CommitToDatabase(workspace,", - "\n storage.TargetPartition, ", - "\n snapshot : true, ", - "\n filter : x => storage.EstimateTypesByImportFormat[ImportFormats.Cashflow].Contains(x.EstimateType) && ", - "\n storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", - "\n await CommitToDatabase(workspace, ", - "\n storage.TargetPartition, ", - "\n snapshot : true,", - "\n filter : x => storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n foreach (var args in targetArgs) {", + "\n log = log.Merge(await CalculateAndUploadIfrsVariablesAsync(args, workspace));", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n await workspace.Partition.SetAsync(mainArgs);", + "\n await DataSource.Partition.SetAsync(mainArgs);", "\n", - "\n return Activity.Finish().Merge(parsingLog); ", + "\n await CommitToDatabase(workspace, (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(mainArgs)), snapshot : true);", + "\n return Activity.Finish().Merge(log); ", "\n});" ], "metadata": {}, @@ -1100,31 +1189,29 @@ "source": [ "Import.DefineFormat(ImportFormats.Actual, async (options, dataSet) => {", "\n Activity.Start();", - "\n var args = (await GetArgsFromMainAsync(dataSet)) with {ImportFormat = ImportFormats.Actual};", - "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Actual, args);", + "\n var mainArgs = (await GetArgsFromMainAsync(dataSet)) with {ImportFormat = ImportFormats.Actual};", "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n", + "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Actual, mainArgs);", + "\n if(Activity.HasErrors()) return Activity.Finish();", + "\n ", "\n var workspace = Workspace.CreateNew();", - "\n var parsingLog = await ParseActualsToWorkspaceAsync(dataSet, args, workspace);", - "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", + "\n var log = await ParseActualsToWorkspaceAsync(dataSet, mainArgs, workspace);", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n", - "\n var storage = new ImportStorage(args, DataSource, workspace);", - "\n await storage.InitializeAsync();", - "\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);", - "\n", - "\n var universe = Scopes.ForStorage(storage).ToScope();", - "\n var identities = universe.GetScopes(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);", - "\n var ivs = universe.GetScopes(identities).SelectMany(x => x.CalculatedIfrsVariables);", - "\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);", - "\n", - "\n await workspace.UpdateAsync(ivs);", - "\n await CommitToDatabase(workspace, ", - "\n storage.TargetPartition, ", - "\n snapshot : true, ", - "\n filter : x => storage.EstimateTypesByImportFormat[ImportFormats.Actual].Contains(x.EstimateType) && ", - "\n storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n var targetArgs = mainArgs.Scenario == null ? ", + "\n mainArgs.RepeatOnce() :", + "\n mainArgs.RepeatOnce().Concat(await DataSource.Query() // TODO: check that concat is adding at the end of the list", + "\n .Where(x => x.ReportingNode == mainArgs.ReportingNode && x.Year == mainArgs.Year && x.Month == mainArgs.Month && x.Scenario != null)", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, Periodicity.Quarterly, x.Scenario, ImportFormats.Actual)).ToArrayAsync());", + "\n ", + "\n foreach (var args in targetArgs) {", + "\n log = log.Merge(await CalculateAndUploadIfrsVariablesAsync(args, workspace)); // TODO THERE IS A BUG HERE", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", "\n", - "\n return Activity.Finish().Merge(parsingLog);", + "\n await workspace.Partition.SetAsync(mainArgs);", + "\n await DataSource.Partition.SetAsync(mainArgs);", + "\n return Activity.Finish().Merge(log);", "\n});" ], "metadata": {}, diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb index c8cde44b..77184199 100644 --- a/ifrs17/Utils/EqualityComparers.ipynb +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -18,7 +18,7 @@ { "cell_type": "markdown", "source": [ - "

Equality Comparers

" + "

Equality Comparers

" ], "metadata": {}, "execution_count": 0, @@ -27,7 +27,8 @@ { "cell_type": "code", "source": [ - "#!import \"../DataModel/DataStructure\"" + "#!import \"../DataModel/DataStructure\"", + "\nusing System;" ], "metadata": {}, "execution_count": 0, @@ -91,6 +92,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "class YieldCurveComparer: IEqualityComparer", + "\n{", + "\n private YieldCurveComparer(){}", + "\n", + "\n\tpublic bool Equals(YieldCurve x, YieldCurve y) => ", + "\n x.Year == y.Year && x.Month == y.Month && x.Scenario == y.Scenario && x.Currency == y.Currency && x.Id == y.Id && x.Values.SequenceEqual(y.Values); // TODO: enable Precision", + "\n\t", + "\n\tpublic int GetHashCode (YieldCurve x) => 0;", + "\n", + "\n public static YieldCurveComparer Instance() => new YieldCurveComparer();", + "\n}", + "\n" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index c783cc39..6e459aba 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -273,4 +273,4 @@ "outputs": [] } ] -} +} \ No newline at end of file diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 47f4597b..ae4534b6 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,7 +189,7 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario};", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency));", "\n ", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", @@ -290,6 +290,7 @@ "\n LiabilityType = dn.LiabilityType,", "\n Profitability = dn.Profitability,", "\n Partner = dn.Partner,", + "\n Scenario = dn.Scenario, ", "\n IsReinsurance = dn.GetType() == typeof(GroupOfReinsuranceContract),", "\n };", "\n }", @@ -399,6 +400,67 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Raw and Ifrs Variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task LoadVariablesAsync(this IDataSource querySource, Guid partition) where T : BaseDataRecord", + "\n{", + "\n await querySource.Partition.SetAsync(partition);", + "\n return (await querySource.Query().ToArrayAsync());", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task LoadVariablesRelaxedAsync(this IWorkspace workspace, IDataSource dataSource, Guid targetPartition, Guid defaultPartition)", + "\n where T : BaseDataRecord", + "\n{", + "\n var variables = await workspace.LoadVariablesAsync(targetPartition);", + "\n // For scenario re-calculation", + "\n if (!variables.Any()) variables = await dataSource.LoadVariablesAsync(targetPartition); ", + "\n // For scenarios related to parameters solely", + "\n if(!variables.Any() && targetPartition != defaultPartition) variables = await dataSource.LoadVariablesAsync(defaultPartition);", + "\n ", + "\n await workspace.Partition.SetAsync(targetPartition);", + "\n await dataSource.Partition.SetAsync(targetPartition);", + "\n return variables;", + "\n}" + ], + "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