diff --git a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb index 3cb7ebd8..7eb4f123 100644 --- a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb +++ b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb @@ -46,8 +46,8 @@ { "cell_type": "code", "source": [ - "//#!eval-notebook \"InitSystemorphToMemoryForTesting\"", - "\n#!eval-notebook \"../../PracticalUseCases/SingleVsMultipleCsmSwitch/CsmSwitchDataImport\"" + "#!eval-notebook \"InitSystemorphToMemoryForTesting\"", + "\n//#!eval-notebook \"../../PracticalUseCases/SingleVsMultipleCsmSwitch/CsmSwitchDataImport\"" ], "metadata": {}, "execution_count": 0, @@ -103,7 +103,8 @@ "source": [ "var exportScope = new ImportArgs[]{", "\n new ImportArgs (\"CH\", 2020, 12, (Periodicity)default, null, null),", - "\n new ImportArgs (\"CH\", 2021, 3, (Periodicity)default, null, null)", + "\n new ImportArgs (\"CH\", 2021, 3, (Periodicity)default, null, null),", + "\n new ImportArgs (\"CH\", 2020, 12, (Periodicity)default, \"MTUP10pct\", null)", "\n };" ], "metadata": {}, @@ -122,7 +123,7 @@ { "cell_type": "code", "source": [ - "var args = exportScope[0];", + "var args = exportScope[2];", "\nargs" ], "metadata": {}, @@ -215,7 +216,7 @@ { "cell_type": "code", "source": [ - "var estimateType = \"BE\";" + "var estimateType = \"RA\";" ], "metadata": {}, "execution_count": 0, @@ -244,6 +245,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv index b950aba6..016b5edf 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv @@ -4,21 +4,9 @@ Month,ReportingNode,Scenario,Year @@A AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value ,NIC,CF,DT1.1,,A,C,-310 -,PR,CF,DT1.1,,A,C,400 -,ACA,CF,DT1.1,,A,C,-10 -,AEA,CF,DT1.1,,A,C,-5 2020,NIC,CF,DT1.2,,A,C,-310 -,NIC,CF,DT2.1,,A,C,-310 -,PR,CF,DT2.1,,A,C,400 -,ACA,CF,DT2.1,,A,C,-10 -,AEA,CF,DT2.1,,A,C,-5 ,NIC,CF,DT1.3,,A,C,-310 -,PR,CF,DT1.3,,A,C,400 -,ACA,CF,DT1.3,,A,C,-10 -,AEA,CF,DT1.3,,A,C,-5 +,NIC,CF,DT2.1,,A,C,-310 2020,NIC,CF,DT2.2,,A,C,-310 ,NIC,CF,DTR1.1,,A,C,170 -,PR,CF,DTR1.1,,A,C,-200 -2020,NIC,CF,DTR1.2,,A,C,170 -,PR,CF,DTR2.1,,A,C,-200 -,NIC,CF,DTR2.1,,A,C,140 \ No newline at end of file +2020,NIC,CF,DTR1.2,,A,C,170 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv new file mode 100644 index 00000000..da193d4d --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_AA.csv @@ -0,0 +1,5 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@AA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv index 98071041..fcfb044a 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv @@ -2,7 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@APA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,PR,CF,DT1.1,,APA,C,320 -,PR,CF,DT2.1,,APA,C,320 -,PR,CF,DT1.3,,APA,C,400 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv index 97f1efee..c40053de 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv @@ -3,67 +3,60 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@BE AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,NIC,BOP,DT1.1,L,BE,N,658.62824 -,PR,BOP,DT1.1,L,BE,N,-798.53673 -,NIC,BOP,DT1.1,C,BE,N,658.62824 -,PR,BOP,DT1.1,C,BE,N,-798.53673 -,NIC,EOP,DT1.1,L,BE,C,329.6431 -,PR,EOP,DT1.1,L,BE,C,-399.63393 ,NIC,EOP,DT1.1,C,BE,C,329.6431 -,PR,EOP,DT1.1,C,BE,C,-399.63393 -,NIC,IA,DT1.1,L,BE,N,1.01487 -,PR,IA,DT1.1,L,BE,N,-1.0972 +,NIC,BOP,DT1.1,C,BE,N,658.62824 +,NIC,CF,DT1.1,C,BE,N,-330 ,NIC,IA,DT1.1,C,BE,N,1.01487 -,PR,IA,DT1.1,C,BE,N,-1.0972 +,NIC,EOP,DT1.1,L,BE,C,329.6431 +,NIC,BOP,DT1.1,L,BE,N,658.62824 ,NIC,CF,DT1.1,L,BE,N,-330 -,PR,CF,DT1.1,L,BE,N,400 -,NIC,CF,DT1.1,C,BE,N,-330 -,PR,CF,DT1.1,C,BE,N,400 -2020,NIC,BOP,DT1.2,L,BE,N,658.62824 -2020,NIC,BOP,DT1.2,C,BE,N,658.62824 -2020,NIC,EOP,DT1.2,L,BE,C,329.6431 +,NIC,IA,DT1.1,L,BE,N,1.01487 2020,NIC,EOP,DT1.2,C,BE,C,329.6431 -2020,NIC,IA,DT1.2,L,BE,N,1.01487 +2020,NIC,BOP,DT1.2,C,BE,N,658.62824 +2020,NIC,CF,DT1.2,C,BE,N,-330 2020,NIC,IA,DT1.2,C,BE,N,1.01487 +2020,NIC,EOP,DT1.2,L,BE,C,329.6431 +2020,NIC,BOP,DT1.2,L,BE,N,658.62824 2020,NIC,CF,DT1.2,L,BE,N,-330 -2020,NIC,CF,DT1.2,C,BE,N,-330 -,NIC,BOP,DTR1.1,L,BE,N,-329.31412 -,PR,BOP,DTR1.1,L,BE,N,399.26837 -,CDR,BOP,DTR1.1,L,BE,N,0.52925 -,NIC,BOP,DTR1.1,C,BE,N,-329.31412 -,PR,BOP,DTR1.1,C,BE,N,399.26837 +2020,NIC,IA,DT1.2,L,BE,N,1.01487 +,CDR,EOP,DTR1.1,C,BE,C,0.1268 ,CDR,BOP,DTR1.1,C,BE,N,0.52925 -,NIC,EOP,DTR1.1,L,BE,C,-164.82155 -,PR,EOP,DTR1.1,L,BE,C,199.81696 -,CDR,EOP,DTR1.1,L,BE,C,0.1268 +,CDR,CF,DTR1.1,C,BE,N,-0.40374 +,CDR,IA,DTR1.1,C,BE,N,0.00129 ,NIC,EOP,DTR1.1,C,BE,C,-164.82155 -,PR,EOP,DTR1.1,C,BE,C,199.81696 -,CDR,EOP,DTR1.1,C,BE,C,0.1268 -,NIC,IA,DTR1.1,L,BE,N,-0.50743 -,PR,IA,DTR1.1,L,BE,N,0.5486 -,CDR,IA,DTR1.1,L,BE,N,0.00129 +,NIC,BOP,DTR1.1,C,BE,N,-329.31412 +,NIC,CF,DTR1.1,C,BE,N,165 ,NIC,IA,DTR1.1,C,BE,N,-0.50743 -,PR,IA,DTR1.1,C,BE,N,0.5486 -,CDR,IA,DTR1.1,C,BE,N,0.00129 -,NIC,CF,DTR1.1,L,BE,N,165 -,PR,CF,DTR1.1,L,BE,N,-200 +,CDR,EOP,DTR1.1,L,BE,C,0.1268 +,CDR,BOP,DTR1.1,L,BE,N,0.52925 ,CDR,CF,DTR1.1,L,BE,N,-0.40374 -,NIC,CF,DTR1.1,C,BE,N,165 -,PR,CF,DTR1.1,C,BE,N,-200 -,CDR,CF,DTR1.1,C,BE,N,-0.40374 -2020,NIC,BOP,DTR1.2,L,BE,N,-329.31412 -2020,CDR,BOP,DTR1.2,L,BE,N,0.52925 -2020,NIC,BOP,DTR1.2,C,BE,N,-329.31412 +,CDR,IA,DTR1.1,L,BE,N,0.00129 +,NIC,EOP,DTR1.1,L,BE,C,-164.82155 +,NIC,BOP,DTR1.1,L,BE,N,-329.31412 +,NIC,CF,DTR1.1,L,BE,N,165 +,NIC,IA,DTR1.1,L,BE,N,-0.50743 +2020,CDR,EOP,DTR1.2,C,BE,C,0.1268 2020,CDR,BOP,DTR1.2,C,BE,N,0.52925 -2020,NIC,EOP,DTR1.2,L,BE,C,-164.82155 -2020,CDR,EOP,DTR1.2,L,BE,C,0.1268 +2020,CDR,CF,DTR1.2,C,BE,N,-0.40374 +2020,CDR,IA,DTR1.2,C,BE,N,0.00129 2020,NIC,EOP,DTR1.2,C,BE,C,-164.82155 -2020,CDR,EOP,DTR1.2,C,BE,C,0.1268 -2020,NIC,IA,DTR1.2,L,BE,N,-0.50743 -2020,CDR,IA,DTR1.2,L,BE,N,0.00129 +2020,NIC,BOP,DTR1.2,C,BE,N,-329.31412 +2020,NIC,CF,DTR1.2,C,BE,N,165 2020,NIC,IA,DTR1.2,C,BE,N,-0.50743 -2020,CDR,IA,DTR1.2,C,BE,N,0.00129 -2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,CDR,EOP,DTR1.2,L,BE,C,0.1268 +2020,CDR,BOP,DTR1.2,L,BE,N,0.52925 2020,CDR,CF,DTR1.2,L,BE,N,-0.40374 -2020,NIC,CF,DTR1.2,C,BE,N,165 -2020,CDR,CF,DTR1.2,C,BE,N,-0.40374 \ No newline at end of file +2020,CDR,IA,DTR1.2,L,BE,N,0.00129 +2020,NIC,EOP,DTR1.2,L,BE,C,-164.82155 +2020,NIC,BOP,DTR1.2,L,BE,N,-329.31412 +2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,NIC,IA,DTR1.2,L,BE,N,-0.50743,N,165 +2020,NIC,IA,DTR1.2,C,BE,N,-0.5074328025652143 +2020,CDR,EOP,DTR1.2,L,BE,C,0.12679876434718015 +2020,CDR,BOP,DTR1.2,L,BE,N,0.5292475300191577 +2020,CDR,CF,DTR1.2,L,BE,N,-0.40373597582193455 +2020,CDR,IA,DTR1.2,L,BE,N,0.001287210150087148 +2020,NIC,EOP,DTR1.2,L,BE,C,-164.8215523318298 +2020,NIC,BOP,DTR1.2,L,BE,N,-329.3141195292647 +2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,NIC,IA,DTR1.2,L,BE,N,-0.5074328025652143 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv index 4674e6db..afd6e7c6 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv @@ -2,5 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@BEPA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,PR,CF,DT1.1,L,BEPA,N,320 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv index dcfc1f10..b9f6ed7f 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv @@ -3,26 +3,13 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@C AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,BOP,DT1.1,,C,N,80.0332 -,,EOP,DT1.1,,C,C,22.35306 ,,AM,DT1.1,,C,C,-42.67021 -,,EA,DT1.1,,C,C,-15 +,,EOP,DT1.1,,C,C,22.35306 +,,BOP,DT1.1,,C,N,80.0332 ,,IA,DT1.1,,C,N,-0.00993 -,,EA,DT2.1,,C,C,-15 -,,AM,DT2.1,,C,C,-82.02271 -,,EOP,DT2.1,,C,C,42.96811 -,,BOP,DT2.1,,C,N,139.90849 -,,IA,DT2.1,,C,N,0.08233 -,,EA,DT1.3,,C,C,-15 -,,AM,DT1.3,,C,C,-82.02271 -,,EOP,DT1.3,,C,C,42.96811 -,,BOP,DT1.3,,C,N,139.90849 -,,IA,DT1.3,,C,N,0.08233 ,,AM,DTR1.1,,C,C,26.60498 ,,EOP,DTR1.1,,C,C,-13.93719 ,,BOP,DTR1.1,,C,N,-40.54585 -,,IA,DTR1.1,,C,N,0.00368 -,,AM,DTR2.1,,C,C,46.24958 -,,EOP,DTR2.1,,C,C,-24.22813 -,,BOP,DTR2.1,,C,N,-70.43538 -,,IA,DTR2.1,,C,N,-0.04234 \ No newline at end of file +,,IA,DTR1.1,,C,N,0.0036888043 +,,BOP,DTR1.1,,C,N,-40.545846351508814 +,,IA,DTR1.1,,C,N,0.003676678453477744 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv index 4ad94e50..60cc80c2 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv @@ -2,13 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@DA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,EOP,DT1.1,,DA,C,-5.15655 -,,AM,DT1.1,,DA,C,9.84345 -,,CF,DT1.1,,DA,C,-15 -,,CF,DT2.1,,DA,C,-15 -,,AM,DT2.1,,DA,C,9.84345 -,,EOP,DT2.1,,DA,C,-5.15655 -,,CF,DT1.3,,DA,C,-15 -,,AM,DT1.3,,DA,C,9.84345 -,,EOP,DT1.3,,DA,C,-5.15655 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv index 20a47c21..ffe034ac 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv @@ -2,8 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@F -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,AM,DT1.1,L,F,C,0.65623 -,,AM,DT1.2,L,F,C,1 -,,AM,DTR1.1,L,F,C,0.65623 -,,AM,DTR1.2,L,F,C,1 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv new file mode 100644 index 00000000..6ebb2b89 --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_OA.csv @@ -0,0 +1,5 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@OA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv index 9b1cb78e..cf55d925 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv @@ -2,36 +2,4 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@RA -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,BOP,DT1.1,C,RA,N,59.87529 -,,BOP,DT1.1,L,RA,N,59.87529 -,,EOP,DT1.1,C,RA,C,29.96755 -,,EOP,DT1.1,L,RA,C,29.96755 -,,IA,DT1.1,C,RA,N,0.09226 -,,IA,DT1.1,L,RA,N,0.09226 -,,CF,DT1.1,C,RA,N,-30 -,,CF,DT1.1,L,RA,N,-30 -2020,,BOP,DT1.2,C,RA,N,59.87529 -2020,,BOP,DT1.2,L,RA,N,59.87529 -2020,,EOP,DT1.2,C,RA,C,29.96755 -2020,,EOP,DT1.2,L,RA,C,29.96755 -2020,,IA,DT1.2,C,RA,N,0.09226 -2020,,IA,DT1.2,L,RA,N,0.09226 -2020,,CF,DT1.2,C,RA,N,-30 -2020,,CF,DT1.2,L,RA,N,-30 -,,BOP,DTR1.1,C,RA,N,-29.93765 -,,BOP,DTR1.1,L,RA,N,-29.93765 -,,EOP,DTR1.1,C,RA,C,-14.98378 -,,EOP,DTR1.1,L,RA,C,-14.98378 -,,IA,DTR1.1,C,RA,N,-0.04613 -,,IA,DTR1.1,L,RA,N,-0.04613 -,,CF,DTR1.1,C,RA,N,15 -,,CF,DTR1.1,L,RA,N,15 -2020,,BOP,DTR1.2,C,RA,N,-29.93765 -2020,,BOP,DTR1.2,L,RA,N,-29.93765 -2020,,EOP,DTR1.2,C,RA,C,-14.98378 -2020,,EOP,DTR1.2,L,RA,C,-14.98378 -2020,,IA,DTR1.2,C,RA,N,-0.04613 -2020,,IA,DTR1.2,L,RA,N,-0.04613 -2020,,CF,DTR1.2,C,RA,N,15 -2020,,CF,DTR1.2,L,RA,N,15 \ No newline at end of file +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value \ No newline at end of file diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index f10996ee..fc9772ba 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -271,7 +271,7 @@ "\n //Get the computed Data", "\n var computedVariables = computedVariablesByEstimateType.TryGetValue(bmTableName, out var ret) ? ret : Enumerable.Empty();", "\n", - "\n if(!computedVariables.Any())", + "\n if(!computedVariables.Any() && bmVariables.Any())", "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName, 0, 0));", "\n //CompareAgainstBm", "\n if (bmVariables.Any() && computedVariables.Any()) //TODO we are adding duplicates here", @@ -291,6 +291,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17-template/Test/ScenarioDataImportTest.ipynb b/ifrs17-template/Test/ScenarioDataImportTest.ipynb index 3c558fcd..594b996c 100644 --- a/ifrs17-template/Test/ScenarioDataImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioDataImportTest.ipynb @@ -70,16 +70,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "var ws = Workspace.CreateNew();", - "\nws.InitializeFrom(DataSource);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -93,21 +83,12 @@ { "cell_type": "code", "source": [ - "var initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", - "\nawait initStorage.InitializeAsync();" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var actualETs = initStorage.EstimateTypesByImportFormat[ImportFormats.Actual];", - "\nvar cashflowETs = initStorage.EstimateTypesByImportFormat[ImportFormats.Cashflow];", - "\nvar actualOrCashflowETs = actualETs.Intersect(cashflowETs);", - "\nvar onlyActualETs = actualETs.Except(cashflowETs);", - "\nvar onlyCashflowETs = cashflowETs.Except(actualETs);" + "var estimateTypes = (await DataSource.Query().ToArrayAsync());", + "\nvar actualEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Actual)).Select(x => x.SystemName);", + "\nvar cashflowEstimateTypes = estimateTypes.Where(et => et.InputSource.Contains(InputSource.Cashflow)).Select(x => x.SystemName);", + "\nvar actualAndCashflowEstimateTypes = actualEstimateTypes.Intersect(cashflowEstimateTypes);", + "\nvar onlyActualEstimateTypes = actualEstimateTypes.Except(cashflowEstimateTypes);", + "\nvar onlyCashflowEstimateTypes = cashflowEstimateTypes.Except(actualEstimateTypes);" ], "metadata": {}, "execution_count": 0, @@ -233,9 +214,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioInitCashFlows = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioInitCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -246,7 +227,7 @@ "source": [ "actualVars.Length.Should().Be(0);", "\ncashflowVars.Length.Should().NotBe(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -291,9 +272,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioInitActuals = DataSource.Query().ToArray();", "\nvar diffs = ivsScenarioInitActuals.Except(ivsScenarioInitCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -304,7 +285,7 @@ "source": [ "actualVars.Length.Should().NotBe(0);", "\ncashflowVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -358,9 +339,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioCashflowUpdateCU = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioCashflowUpdateCU.Except(ivsScenarioInitActuals, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -370,8 +351,10 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.F).Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().NotBe(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -417,9 +400,9 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioActualUpdateACAAEA = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioActualUpdateACAAEA.Except(ivsScenarioCashflowUpdateCU, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -428,9 +411,10 @@ { "cell_type": "code", "source": [ - "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "cashflowVars.Count().Should().Be(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", "\ndiffs.Where(x => x.EstimateType == EstimateTypes.F).ToArray().Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -504,7 +488,7 @@ { "cell_type": "markdown", "source": [ - "# Robustness: back to Best Estimate" + "# Robustness: scenario back to Best Estimate" ], "metadata": {}, "execution_count": 0, @@ -577,7 +561,7 @@ { "cell_type": "code", "source": [ - "diffs.Count().Should().Be(0);" + "ivsScenarioReimportEqualToBestEstimate.Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -636,11 +620,11 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsBestEstimate);", - "\nvar ivsBestEstimateReimportCashFlows = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsBestEstimateReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar ivsBestEstimateReimportCashFlowsNoImpactScenario = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsBestEstimateReimportCashFlowsNoImpactScenario.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());", + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -651,7 +635,7 @@ "source": [ "diffs.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().NotBe(0);", "\nactualVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -661,8 +645,8 @@ "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsScenario);", - "\nvar ivsScenarioReimportCashFlows = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsScenarioReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + "\nvar ivsScenarioReimportCashFlowsNoImpactScenario = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioReimportCashFlowsNoImpactScenario.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" ], "metadata": {}, "execution_count": 0, @@ -671,8 +655,8 @@ { "cell_type": "code", "source": [ - "diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", - "\ndiffs.Where(x => onlyActualETs.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" + "diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType) && x.EstimateType != EstimateTypes.F && Math.Abs(x.Value) > Precision).Count().Should().Be(0);", + "\ndiffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType) && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -681,7 +665,7 @@ { "cell_type": "markdown", "source": [ - "# Reimport of Best Estimate Cashflow: impact on Scenario" + "# Reimport of Best Estimate Cashflow" ], "metadata": {}, "execution_count": 0, @@ -715,15 +699,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateReimportCashFlows = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsBestEstimateReimportCashFlows.Except(ivsBestEstimateReimportCashFlowsNoImpactScenario, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ "await DataSource.Partition.SetAsync(argsScenario);", - "\nvar ivsScenarioReimportCashFlowsImpact = await DataSource.Query().ToArrayAsync();", - "\nvar diffs = ivsScenarioReimportCashFlowsImpact.Except(ivsScenarioReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();", - "\nvar actualOrCashflowVars = diffs.Where(x => actualOrCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar ivsScenarioReimportCashFlows = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioReimportCashFlows.Except(ivsScenarioReimportCashFlowsNoImpactScenario, IfrsVariableComparer.Instance());", + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar actualAndCashflowVars = diffs.Where(x => actualAndCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -734,7 +738,7 @@ "source": [ "cashflowVars.Length.Should().NotBe(0);", "\nactualVars.Length.Should().Be(0);", - "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualAndCashflowVars)).ToArray().Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -759,7 +763,8 @@ "\n@@Actual", "\nDataNode,AocType,AmountType,EstimateType,AccidentYear,Value", "\nDT1.1,CF,NIC,A,,-2000", - "\nDT1.1,CF,PR,A,,-4000\";" + "\nDT1.1,CF,PR,A,,4000", + "\nDT1.1,CF,CL,A,,-3000\";" ], "metadata": {}, "execution_count": 0, @@ -780,8 +785,8 @@ "await DataSource.Partition.SetAsync(argsBestEstimate);", "\nvar ivsBestEstimateReimportActuals = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsBestEstimateReimportActuals.Except(ivsBestEstimateReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -791,8 +796,7 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().NotBe(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);" + "\ncashflowVars.Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -804,8 +808,8 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioReimportActuals = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioReimportActuals.Except(ivsScenarioReimportCashFlows, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -814,9 +818,9 @@ { "cell_type": "code", "source": [ - "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);", - "\ncashflowVars.Where(x => x.EstimateType == EstimateTypes.DA).Count().Should().Be(0);" + "diffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);", + "\nactualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().Be(0);" ], "metadata": {}, "execution_count": 0, @@ -840,16 +844,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "await DataSource.Partition.SetAsync(argsScenario);", - "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -878,13 +872,23 @@ "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", "\nDT1.1,PR,BE,CL,C,,200,0,0,200,0,0,200,0,0,200,0,0,0,200,0,0,200,0,0,200,0,0,200,0", "\nDT1.1,NIC,BE,CL,C,,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33,-33", - "\nDT1.1,,CU,CL,C,,-71,-71,-70,-70,-69,-69,-68,-68,-67,-67,-66,-66,-65,-65,-64,-64,-63,-63,-62,-62,-61,-61,-60,-60", + "\nDT1.1,,CU,CL,C,,-719,-71,-70,-70,-69,-69,-68,-68,-67,-67,-66,-66,-65,-65,-64,-64,-63,-63,-62,-62,-61,-61,-60,-60", "\nDT1.1,,RA,CL,C,,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45\";" ], "metadata": {}, "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -919,8 +923,8 @@ "await DataSource.Partition.SetAsync(argsScenario);", "\nvar ivsScenarioReimportCashFlowsWithCU = await DataSource.Query().ToArrayAsync();", "\nvar diffs = ivsScenarioReimportCashFlowsWithCU.Except(ivsScenarioReimportCashflowNoCU, IfrsVariableComparer.Instance());", - "\nvar actualVars = diffs.Where(x => onlyActualETs.Contains(x.EstimateType)).ToArray();", - "\nvar cashflowVars = diffs.Where(x => onlyCashflowETs.Contains(x.EstimateType)).ToArray();" + "\nvar actualVars = diffs.Where(x => onlyActualEstimateTypes.Contains(x.EstimateType)).ToArray();", + "\nvar cashflowVars = diffs.Where(x => onlyCashflowEstimateTypes.Contains(x.EstimateType)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -930,7 +934,7 @@ "cell_type": "code", "source": [ "actualVars.Length.Should().Be(0);", - "\ncashflowVars.Length.Should().NotBe(0);" + "\ndiffs.Count().Should().NotBe(0);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ScenarioParametersImportTest.ipynb b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb new file mode 100644 index 00000000..a65ecdd9 --- /dev/null +++ b/ifrs17-template/Test/ScenarioParametersImportTest.ipynb @@ -0,0 +1,503 @@ +{ + "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());" + ], + "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 argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenarioParameter = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"DUP10pct\", ImportFormats.Cashflow);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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);" + ], + "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": [ + "var actualsBestEstimateInit = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Actual", + "\nDataNode,AocType,AmountType,EstimateType,AccidentYear,Value", + "\nDT1.1,CF,ACA,A,,-10", + "\nDT1.1,CF,AEA,A,,-5", + "\nDT1.1,CF,NIC,A,,-280", + "\nDT1.1,CF,PR,A,,400", + "\nDTR1.1,CF,PR,A,,-200", + "\nDTR1.1,CF,NIC,A,,140\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsBestEstimateInit).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateInit = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Scenario parameters import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var parametersScenarios = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,DUP10pct", + "\n@@SingleDataNodeParameter", + "\nDataNode,PremiumAllocation", + "\nDT1.1,0.52", + "\n@@InterDataNodeParameter", + "\nDataNode,LinkedDataNode,ReinsuranceCoverage", + "\nDT1.1,DTR1.1,0.62\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(parametersScenarios).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameter = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameter.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance()).ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.C).Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Re-import of the same parameters should not trigger calculations " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var log = await Import.FromString(parametersScenarios).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync();", + "\nlog" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "((log.Warnings.FirstOrDefault()?.ToString().Remove(0,40).Remove(125,2)?? \"\") == Get(Warning.VariablesAlreadyImported)).Should().Be(true);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterSameReimport = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameterSameReimport.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Re-import of best estimate cashflow" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowBestEstimateReImport = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Cashflow", + "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", + "\nDT1.1,PR,BE,CL,C,,131,0,0,111,0,0,111,0,0,111,0,0,0,111,0,0,111,0,0,111,0,0,111,0", + "\nDT1.1,NIC,BE,CL,C,,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31,-31", + "\nDT1.1,,CU,CL,C,,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-11,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3", + "\nDT1.1,,RA,CL,C,,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6,-2.6", + "\nDTR1.1,PR,BE,CL,C,,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0,51,0,0", + "\nDTR1.1,NIC,BE,CL,C,,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13", + "\nDTR1.1,,CU,CL,C,,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5", + "\nDTR1.1,,RA,CL,C,,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31,1.31\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowBestEstimateReImport).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Best Estimate change" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsBestEstimate);", + "\nvar ivsBestEstimateReimport = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsBestEstimateReimport.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario should change" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterReimportBestEstimateCashflow = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameterReimportBestEstimateCashflow.Except(ivsScenarioParameter, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Re-import of scenario parameters" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var parametersScenariosReimport = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,DUP10pct", + "\n@@SingleDataNodeParameter", + "\nDataNode,PremiumAllocation", + "\nDT1.1,0.23", + "\n@@InterDataNodeParameter", + "\nDataNode,LinkedDataNode,ReinsuranceCoverage", + "\nDT1.1,DTR1.1,0.23\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(parametersScenariosReimport).WithFormat(ImportFormats.DataNodeParameter).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenarioParameter);", + "\nvar ivsScenarioParameterReimport = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var diffs = ivsScenarioParameterReimport.Except(ivsScenarioParameterReimportBestEstimateCashflow, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Restore constants" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "EnableScenario = EnableScenarioBackup;" + ], + "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 5e870b40..6fce00f2 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -269,7 +269,7 @@ { "cell_type": "markdown", "source": [ - "# Re-Import of the same yield curve should not trigger IFRS17 Calculations" + "# Re-import of the same yield curve should not trigger calculations" ], "metadata": {}, "execution_count": 0, @@ -278,7 +278,17 @@ { "cell_type": "code", "source": [ - "await Import.FromString(yieldCurveScenario).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync()" + "var log = await Import.FromString(yieldCurveScenario).WithFormat(ImportFormats.YieldCurve).WithTarget(DataSource).ExecuteAsync();", + "\nlog" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "((log.Warnings.FirstOrDefault()?.ToString().Remove(0,40).Remove(125,2)?? \"\") == Get(Warning.VariablesAlreadyImported)).Should().Be(true);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/Tests.ipynb b/ifrs17-template/Test/Tests.ipynb index 7cc5ce85..c70f9674 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/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 9c4db10f..a5b2932b 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -503,18 +503,33 @@ { "cell_type": "code", "source": [ - "public async Task GetAllArgsAsync(ImportArgs args, IDataSource dataSource, string format, IDataSource targetDataSource)", + "public async Task GetAllArgsAsync(ImportArgs args, IDataSource dataSource, string format)", "\n{", "\n ImportArgs[] allArgs;", "\n switch(format)", "\n {", - "\n case ImportFormats.YieldCurve : ", + "\n case ImportFormats.Cashflow:", + "\n case ImportFormats.Actual: ", + "\n case ImportFormats.Opening:", + "\n {", + "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", + "\n var secondaryArgs = await dataSource.Query() ", + "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", + "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, format)).ToArrayAsync();", + "\n ", + "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", + "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", + "\n break;", + "\n }", + "\n default: ", "\n {", "\n if(args.Scenario == null) {", - "\n var scenariosWithYieldCurves = await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => x.Scenario).Distinct().ToArrayAsync();", + "\n var scenarios = format switch {", + "\n ImportFormats.YieldCurve => await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).Distinct().ToArrayAsync(),", + "\n ImportFormats.DataNodeParameter => await dataSource.Query().Where(x => x.Year == args.Year && x.Month == args.Month && x.Scenario != null).Select(x => x.Scenario).Distinct().ToArrayAsync()", + "\n };", "\n var targetPartitions = await dataSource.Query()", - "\n .Where(x => x.Year == args.Year && x.Month == args.Month && !scenariosWithYieldCurves.Contains(x.Scenario)).OrderBy(x => x.Scenario).ToArrayAsync();", + "\n .Where(x => x.Year == args.Year && x.Month == args.Month && !scenarios.Contains(x.Scenario)).OrderBy(x => x.Scenario).ToArrayAsync();", "\n var targetScenarios = targetPartitions.Where(x => x.Scenario != null).Select(x => x.Scenario);", "\n if(targetScenarios.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", targetScenarios));", "\n allArgs = targetPartitions.Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArray();", @@ -526,17 +541,6 @@ "\n }", "\n break;", "\n }", - "\n default : ", - "\n {", - "\n if(args.Scenario != null) return args.RepeatOnce().ToArray();", - "\n var secondaryArgs = await targetDataSource.Query() ", - "\n .Where(x => x.ReportingNode == args.ReportingNode && x.Year == args.Year && x.Month == args.Month && x.Scenario != null)", - "\n .Select(x => new ImportArgs(x.ReportingNode, x.Year, x.Month, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArrayAsync();", - "\n ", - "\n if(secondaryArgs.Any()) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", secondaryArgs.Select(x => x.Scenario)));", - "\n allArgs = args.RepeatOnce().Concat(secondaryArgs).ToArray();", - "\n break;", - "\n }", "\n }", "\n return allArgs.Where(x => (!EnableScenario && x.Scenario == null) || EnableScenario).ToArray();", "\n}" @@ -560,10 +564,11 @@ "\n var ivs = universe.GetScopes(identities).SelectMany(x => x.CalculatedIfrsVariables);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n if(storage.DefaultPartition != storage.TargetPartition){", - "\n var bestEstimateIvs = await DataSource.LoadPartitionedDataAsync(storage.DefaultPartition);", - "\n ivs = ivs.Where(iv => Math.Abs(iv.Value) >= Precision).ToArray().Concat(", - "\n ivs.Where(iv => Math.Abs(iv.Value) < Precision).Intersect(bestEstimateIvs, EqualityComparer.Instance).Select(iv => iv with {Value = 0.0}).ToArray());", + "\n if(storage.DefaultPartition != storage.TargetPartition) {", + "\n var bestEstimateIvs = await workspaceToCompute.LoadPartitionedDataAsync(storage.DefaultPartition);", + "\n ivs = ivs.Where(iv => Math.Abs(iv.Value) >= Precision).ToArray()", + "\n .Except(bestEstimateIvs, IfrsVariableComparer.Instance(ignoreValue: false))", + "\n .Concat(ivs.Where(x => Math.Abs(x.Value) < Precision).Intersect(bestEstimateIvs, EqualityComparer.Instance).Select(x => x with {Value = 0.0}).ToArray());", "\n }", "\n", "\n workspace.Reset(x => x.ResetType());", @@ -837,7 +842,7 @@ "\n return Activity.Finish().Merge(importLog);", "\n }", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.YieldCurve, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.YieldCurve);", "\n var updatedCurrencies = toCommitYieldCurves.Select(x => x.Currency).Distinct();", "\n var dataNodesToUpdate = await workspace.Query().Where(x => updatedCurrencies.Contains(x.ContractualCurrency)).Select(x => x.SystemName).ToArrayAsync();", "\n var workspaceToCompute = Workspace.CreateNew();", @@ -846,8 +851,7 @@ "\n foreach (var args in allArgs) {", "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", - "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(", - "\n new ImportArgs(args.ReportingNode, args.Year, args.Month, default(Periodicity), null, ImportFormats.Cashflow) ));", + "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(importLog);", "\n ", "\n // Avoid starting the computation if no best estimate cash flow has ever been imported ", @@ -1091,21 +1095,12 @@ { "cell_type": "code", "source": [ - "public async Task UploadDataNodeParameterToWorkspaceAsync(IDataSet dataSet, Guid targetPartitionByReportingNodeId, IWorkspace workspace, IDataSource targetDataSource)", + "public async Task UploadDataNodeParameterToWorkspaceAsync(IDataSet dataSet, ImportArgs args, IWorkspace workspace, IDataSource targetDataSource)", "\n{", - "\n workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", - "\n workspace.Initialize(x => x.FromSource(targetDataSource)", - "\n .DisableInitialization()", - "\n .DisableInitialization()", - "\n .DisableInitialization());", "\n Activity.Start();", - "\n var args = await GetArgsAndCommitPartitionAsync(dataSet, targetDataSource) with {ImportFormat = ImportFormats.DataNodeParameter};", - "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n", "\n var storage = new ParsingStorage(args, targetDataSource, workspace);", "\n await storage.InitializeAsync();", "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n", "\n var singleDataNode = new List();", "\n var interDataNode = new List<(string,string)>();", "\n ", @@ -1124,8 +1119,8 @@ "\n return new SingleDataNodeParameter {", "\n Year = args.Year,", "\n Month = args.Month,", + "\n Scenario = args.Scenario,", "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n", "\n DataNode = dataNode,", "\n PremiumAllocation = (datarow.Field(nameof(SingleDataNodeParameter.PremiumAllocation)))", "\n .ToString().CheckStringForExponentialAndConvertToDouble(),", @@ -1159,6 +1154,7 @@ "\n return new InterDataNodeParameter {", "\n Year = args.Year,", "\n Month = args.Month,", + "\n Scenario = args.Scenario,", "\n Partition = storage.TargetPartitionByReportingNode.Id,", "\n DataNode = dataNodes[0],", "\n LinkedDataNode = dataNodes[1],", @@ -1168,7 +1164,6 @@ "\n .WithTarget(workspace)", "\n .ExecuteAsync();", "\n ", - "\n targetPartitionByReportingNodeId = storage.TargetPartitionByReportingNode.Id;", "\n return Activity.Finish().Merge(importLog);", "\n}" ], @@ -1180,13 +1175,53 @@ "cell_type": "code", "source": [ "Import.DefineFormat(ImportFormats.DataNodeParameter, async (options, dataSet) => {", - "\n Guid partitionId = new Guid();", + "\n Activity.Start();", + "\n var primaryArgs = GetArgsFromMain(dataSet) with {ImportFormat = ImportFormats.DataNodeParameter};", + "\n primaryArgs.ValidateArgsForPeriod();", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish();", "\n var workspace = Workspace.CreateNew();", - "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, partitionId, workspace, options.TargetDataSource);", - "\n await workspace.CommitToAsync(options.TargetDataSource, partitionId, snapshot: false);", - "\n await workspace.CommitToAsync(options.TargetDataSource, partitionId, snapshot: false); ", - "\n ", - "\n return log;", + "\n workspace.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization().DisableInitialization());", + "\n", + "\n var committedParameters = await options.TargetDataSource.Query().ToArrayAsync();", + "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, primaryArgs, workspace, options.TargetDataSource); ", + "\n", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log); ", + "\n var toCommitParameters = (await workspace.Query().ToArrayAsync()).Except(committedParameters, ParametersComparer.Instance());", + "\n if (!toCommitParameters.Any()) {", + "\n ApplicationMessage.Log(Warning.VariablesAlreadyImported); ", + "\n return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.DataNodeParameter);", + "\n var targetDataNodes = toCommitParameters.Select(x => x.DataNode)", + "\n .Concat(toCommitParameters.Where(x => x is InterDataNodeParameter).Select(x => ((InterDataNodeParameter)x).LinkedDataNode)).ToHashSet();", + "\n var workspaceToCompute = Workspace.CreateNew();", + "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource).DisableInitialization());", + "\n", + "\n foreach (var args in allArgs) { ", + "\n await CommitPartitionAsync(args, workspace, workspaceToCompute);", + "\n var targetPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args));", + "\n var defaultPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null}));", + "\n var previousPartition = (Guid)(await options.TargetDataSource.Partition.GetKeyForInstanceAsync(args with {Scenario = null, Year = args.Year-1, Month = 12}));", + "\n await options.TargetDataSource.Partition.SetAsync(null);", + "\n if(ApplicationMessage.HasErrors()) return Activity.Finish().Merge(log);", + "\n ", + "\n // Avoid starting the computation if no best estimate cash flow and actuals has ever been imported ", + "\n if(args.Scenario == null && !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any() &&", + "\n !(await options.TargetDataSource.Query().Where(x => x.Partition == targetPartition).Take(1).ToArrayAsync()).Any()) continue;", + "\n", + "\n // Only nominals corresponding to the target data nodes are added to the workspace", + "\n var nominals = await options.TargetDataSource.Query().Where(x => targetDataNodes.Contains(x.DataNode) && ", + "\n (x.Partition == targetPartition || x.Partition == defaultPartition || x.Partition == previousPartition)).ToArrayAsync();", + "\n if(nominals.Any()) await workspaceToCompute.UpdateAsync(nominals);", + "\n", + "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n", + "\n await workspaceToCompute.UpdateAsync(toCommitParameters);", + "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource);", + "\n return Activity.Finish().Merge(log);", "\n});" ], "metadata": {}, @@ -1288,7 +1323,7 @@ "\n var primaryArgs = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Cashflow};", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Cashflow, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Cashflow);", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Cashflow, primaryArgs, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n ", @@ -1389,7 +1424,7 @@ "\n var primaryArgs = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Actual};", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Actual, options.TargetDataSource);", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Actual);", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Actual, primaryArgs, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb index 98705583..95c8b455 100644 --- a/ifrs17/Utils/EqualityComparers.ipynb +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -140,6 +140,38 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "class ParametersComparer: IEqualityComparer", + "\n{", + "\n private ParametersComparer(){}", + "\n", + "\n public bool Equals(DataNodeParameter x, DataNodeParameter y) {", + "\n if (x == null && y == null) return true; ", + "\n if (x == null || y == null) return false; ", + "\n if (!(x.Year == y.Year && x.Month == y.Month && x.Scenario == y.Scenario)) return false; ", + "\n if (x is SingleDataNodeParameter && y is SingleDataNodeParameter && x.DataNode == y.DataNode &&", + "\n ((SingleDataNodeParameter)x).PremiumAllocation == ((SingleDataNodeParameter)y).PremiumAllocation) return true; ", + "\n if (x is InterDataNodeParameter && y is InterDataNodeParameter) {", + "\n var xi = (InterDataNodeParameter)x;", + "\n var yi = (InterDataNodeParameter)y;", + "\n if (xi.ReinsuranceCoverage != yi.ReinsuranceCoverage) return false;", + "\n if ((xi.LinkedDataNode == yi.LinkedDataNode && xi.DataNode == yi.DataNode) ||", + "\n (xi.LinkedDataNode == yi.DataNode && xi.DataNode == yi.LinkedDataNode)) return true;", + "\n }", + "\n return false;", + "\n }", + "\n\t", + "\n public int GetHashCode (DataNodeParameter x) => 0;", + "\n", + "\n public static ParametersComparer Instance() => new ParametersComparer();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index af7021f4..809fe695 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -372,8 +372,8 @@ "\n .GroupBy(x => x.DataNode != p.Key ? x.DataNode : x.LinkedDataNode)", "\n .Select(gg =>", "\n {", - "\n var currentCandidate = gg.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).FirstOrDefault();", - "\n var previousCandidate = gg.Where(x => x.Year < args.Year).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", + "\n var currentCandidate = gg.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).ThenByDescending(x => x.Scenario).FirstOrDefault();", + "\n var previousCandidate = gg.Where(x => x.Year < args.Year && x.Scenario == null).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", "\n return (key: p.Key,", "\n currentPeriod: currentCandidate != null ? currentCandidate : previousCandidate,", "\n previousPeriod: previousCandidate != null ? previousCandidate : currentCandidate);",