diff --git a/ifrs17-template/Files/Dimensions.csv b/ifrs17-template/Files/Dimensions.csv index 63f91bdb..71f22809 100644 --- a/ifrs17-template/Files/Dimensions.csv +++ b/ifrs17-template/Files/Dimensions.csv @@ -119,7 +119,7 @@ LR,Loss Recovery Component,40,AoC,7,NotApplicable,,,,,, PL,Profit and Loss,50,None,7,NotApplicable,,,,,, AA,Advance Actuals,60,AoC,3,NotApplicable,PayablePR,ReceivableNIC,ReceivableICO,RiReceivablePR,RiPayableNIC, OA,Overdue Actuals,70,AoC,3,NotApplicable,ReceivablePR,PayableNIC,PayableICO,RiPayablePR,RiReceivableNIC, -DA,Deferrable Actuals,80,AoC,3,NotApplicable,,,,,, +DA,Deferrable Actuals,80,AoC,7,NotApplicable,,,,,, A,Actuals,90,None,2,NotApplicable,,,,,, F,Factors,100,None,4,NotApplicable,,,,,, APA,Actuals,130,None,2,NotApplicable,,,,,, diff --git a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb index 5e7d141f..2b320b8d 100644 --- a/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb +++ b/ifrs17-template/Test/Data/ExportIfrsVariable.ipynb @@ -53,6 +53,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "int roundingDigits = - (int)Math.Log10(BenchmarkPrecision) + 1;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -97,7 +106,7 @@ { "cell_type": "code", "source": [ - "var estimateType = \"BEPA\";", + "var estimateType = \"APA\";", "\nawait Export.ToCsv(\"BM_\"+args.ReportingNode+\"_\"+args.Year.ToString()+\"_\"+args.Month.ToString()+\"_\"+scenario+\"_\"+estimateType)", "\n .WithTable(tableConfig => tableConfig", "\n .AtBeginning()", @@ -107,22 +116,13 @@ "\n .WithColumn(x => x.ImportFormat, x => x.Delete())", "\n )", "\n .WithTable(tableConfig => tableConfig", - "\n .WithSource(source => computedVariables[estimateType].AsQueryable())", + "\n .WithSource(source => computedVariables[estimateType].Select(x => x with {Value = Math.Round(x.Value, roundingDigits)}).AsQueryable())", "\n .WithName(estimateType)", "\n .WithColumn(x => x.Partition, x => x.Delete())", "\n .WithColumn(x => x.Id, x => x.Delete())", "\n )", "\n .WithSource(DataSource)", - "\n .ExecuteAsync()" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" + "\n .ExecuteAsync() " ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/Data/ExportReportVariables.ipynb b/ifrs17-template/Test/Data/ExportReportVariables.ipynb index b7fc2793..781c0299 100644 --- a/ifrs17-template/Test/Data/ExportReportVariables.ipynb +++ b/ifrs17-template/Test/Data/ExportReportVariables.ipynb @@ -174,7 +174,7 @@ { "cell_type": "code", "source": [ - "var scopesData = (await GetScopesDataAsync(args, reportStorage, Scopes)).Select(rv => rv with { Value = Math.Round(rv.Value, roundingDigits)});", + "var scopesData = (await GetScopesDataAsync(args, reportStorage, Scopes)).AggregateBy().Select(rv => rv with { Value = Math.Round(rv.Value, roundingDigits)});", "\nvar bmFileName = benchmarkFileNamePrefix + GetBenchmarkFileName(args) + \".csv\";" ], "metadata": {}, 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 6a49b39f..b950aba6 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 @@ -3,12 +3,22 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@A AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,NIC,CF,DT2.1,,A,C,-310 -2020,NIC,CF,DT1.2,,A,C,-310 ,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 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 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 new file mode 100644 index 00000000..98071041 --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_APA.csv @@ -0,0 +1,8 @@ +@@Main +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 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 c57d6d4b..dcfc1f10 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,13 +3,19 @@ Month,ReportingNode,Scenario,Year 12,CH,MTUP10pct,2020 @@C AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,EA,DT2.1,,C,C,-139.99082 -,,EA,DT1.1,,C,C,-80.02327 ,,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 ,,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,-139.99082 +,,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 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 new file mode 100644 index 00000000..4ad94e50 --- /dev/null +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_DA.csv @@ -0,0 +1,14 @@ +@@Main +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 diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv deleted file mode 100644 index c38e0f99..00000000 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv +++ /dev/null @@ -1,14 +0,0 @@ -@@Main -Month,ReportingNode,Scenario,Year -12,CH,MTUP10pct,2020 -@@L -AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value -,,AM,DT2.1,,L,C,-118.1274 -,,EA,DT2.1,,L,C,180.00918 -,,EA,DT1.1,,L,C,239.97673 -,,AM,DT1.1,,L,C,-157.4799 -,,EOP,DT1.1,,L,C,82.49683 -,,EOP,DT2.1,,L,C,61.88178 -,,EA,DT1.3,,L,C,260.00918 -,,AM,DT1.3,,L,C,-170.62578 -,,EOP,DT1.3,,L,C,89.38339 \ No newline at end of file diff --git a/ifrs17-template/Test/Data/ReportVariableBenchmarks/ReportVariableBenchmarks_2020_12_CH_MTUP10pct_Contractual.csv b/ifrs17-template/Test/Data/ReportVariableBenchmarks/ReportVariableBenchmarks_2020_12_CH_MTUP10pct_Contractual.csv index 6ab9b317..5c3c3747 100644 --- a/ifrs17-template/Test/Data/ReportVariableBenchmarks/ReportVariableBenchmarks_2020_12_CH_MTUP10pct_Contractual.csv +++ b/ifrs17-template/Test/Data/ReportVariableBenchmarks/ReportVariableBenchmarks_2020_12_CH_MTUP10pct_Contractual.csv @@ -157,25 +157,19 @@ AccidentYear,AmountType,AnnualCohort,ContractualCurrency,Currency,EconomicBasis, 0,PR,2020,USD,USD,L,BE,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,398.53673,IR5 0,PR,2020,USD,USD,L,BE,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-399.63393,OCI1 0,PR,2020,USD,USD,L,BEPA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,320,IR6 -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-82.02271,AM +0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-42.67021,AM 0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,80.0332,BOP -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,124.99082,CL -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-80.02327,EA -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,42.96811,EOP +0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-15,EA +0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,22.35306,EOP 0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,-0.00993,IA 0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,0.00993,IFIE1 -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,82.02271,IR3 -0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-125.00075,IR5 +0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,42.67021,IR3 +0,,2020,USD,USD,,C,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-65.0332,IR5 0,,2020,USD,USD,,DA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,9.84345,AM 0,,2020,USD,USD,,DA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-15,CF 0,,2020,USD,USD,,DA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-5.15655,EOP 0,,2020,USD,USD,,DA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,9.84345,IR4 0,,2020,USD,USD,,DA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-9.84345,ISE6 -0,,2020,USD,USD,,L,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-157.4799,AM -0,,2020,USD,USD,,L,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,239.97673,EA -0,,2020,USD,USD,,L,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,82.49683,EOP -0,,2020,USD,USD,,L,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-239.97673,ISE11 -0,,2020,USD,USD,,L,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,157.4799,ISE9 0,,2020,USD,USD,C,RA,CHF,DT1.1,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,59.87529,BOP 0,,2020,USD,USD,C,RA,CHF,DT1.1,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,-30,CF 0,,2020,USD,USD,C,RA,CHF,DT1.1,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,29.96755,EOP @@ -224,8 +218,7 @@ AccidentYear,AmountType,AnnualCohort,ContractualCurrency,Currency,EconomicBasis, 0,PR,2020,USD,USD,L,BEPA,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,400,IR6 0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-82.02271,AM 0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,139.90849,BOP -0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,124.99082,CL -0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-139.99082,EA +0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-15,EA 0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,42.96811,EOP 0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,0.08233,IA 0,,2020,USD,USD,,C,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-0.08233,IFIE1 @@ -236,11 +229,6 @@ AccidentYear,AmountType,AnnualCohort,ContractualCurrency,Currency,EconomicBasis, 0,,2020,USD,USD,,DA,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-5.15655,EOP 0,,2020,USD,USD,,DA,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,9.84345,IR4 0,,2020,USD,USD,,DA,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-9.84345,ISE6 -0,,2020,USD,USD,,L,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-170.62578,AM -0,,2020,USD,USD,,L,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,260.00918,EA -0,,2020,USD,USD,,L,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,89.38339,EOP -0,,2020,USD,USD,,L,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,-260.00918,ISE11 -0,,2020,USD,USD,,L,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,170.62578,ISE9 0,,2020,USD,USD,C,RA,CHF,DT1.3,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,59.87529,BOP 0,,2020,USD,USD,C,RA,CHF,DT1.3,P,False,LRC,ANN,N,Default,,DT1,0,CH,MTUP10pct,BBA,-30,CF 0,,2020,USD,USD,C,RA,CHF,DT1.3,P,False,LRC,ANN,C,Default,,DT1,0,CH,MTUP10pct,BBA,29.96755,EOP @@ -415,8 +403,7 @@ AccidentYear,AmountType,AnnualCohort,ContractualCurrency,Currency,EconomicBasis, 0,PR,2020,USD,USD,L,BEPA,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,320,IR6 0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-82.02271,AM 0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,N,,,DT2,0,CH,MTUP10pct,BBA,139.90849,BOP -0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,124.99082,CL -0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-139.99082,EA +0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-15,EA 0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,42.96811,EOP 0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,N,,,DT2,0,CH,MTUP10pct,BBA,0.08233,IA 0,,2020,USD,USD,,C,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-0.08233,IFIE1 @@ -427,11 +414,6 @@ AccidentYear,AmountType,AnnualCohort,ContractualCurrency,Currency,EconomicBasis, 0,,2020,USD,USD,,DA,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-5.15655,EOP 0,,2020,USD,USD,,DA,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,9.84345,IR4 0,,2020,USD,USD,,DA,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-9.84345,ISE6 -0,,2020,USD,USD,,L,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-118.1274,AM -0,,2020,USD,USD,,L,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,180.00918,EA -0,,2020,USD,USD,,L,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,61.88178,EOP -0,,2020,USD,USD,,L,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,-180.00918,ISE11 -0,,2020,USD,USD,,L,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,118.1274,ISE9 0,,2020,USD,USD,C,RA,CHF,DT2.1,P,False,LRC,ANN,N,,,DT2,0,CH,MTUP10pct,BBA,59.87529,BOP 0,,2020,USD,USD,C,RA,CHF,DT2.1,P,False,LRC,ANN,N,,,DT2,0,CH,MTUP10pct,BBA,-30,CF 0,,2020,USD,USD,C,RA,CHF,DT2.1,P,False,LRC,ANN,C,,,DT2,0,CH,MTUP10pct,BBA,29.96755,EOP diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index 30e66d22..860c13ee 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -94,9 +94,10 @@ "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_BE.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_BEPA.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_A.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", + "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_APA.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", + "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_DA.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_C.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_F.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", - "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_L.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_MTUP10pct_RA.csv\" , \"CH\", 2020, 12, \"MTUP10pct\"),", "\n};" ], @@ -134,7 +135,7 @@ { "cell_type": "code", "source": [ - "public IfrsVariable CreateVariable (IDataRow row, Guid partition)", + "public IfrsVariable CreateVariable(IDataRow row, Guid partition)", "\n{", "\n if (!double.TryParse(row[nameof(IfrsVariable.Value)]?.ToString(), AllowedNumberStyles, CultureInfo.InvariantCulture, out var doubleValue))", "\n throw new Exception(\"Value cannot be parsed.\");", @@ -147,8 +148,7 @@ "\n AmountType = row.Field(nameof(IfrsVariable.AmountType)),", "\n AccidentYear = Int32.TryParse((row.Field(nameof(IfrsVariable.AccidentYear))), out var accidentYear) ? accidentYear : (int?)null,", "\n EconomicBasis = row.Field(nameof(IfrsVariable.EconomicBasis)),", - "\n Value = (-1.0) * doubleValue,", - "\n };", + "\n Value = (-1.0) * doubleValue };", "\n}" ], "metadata": {}, @@ -182,42 +182,24 @@ { "cell_type": "code", "source": [ - "public List CompareAgainstBm (List errors, IEnumerable expected, IEnumerable computed)", + "public List CompareAgainstBm(List errors, IEnumerable expected, IEnumerable computed)", "\n{", - "\n var expectedNotComputed = expected.Where(x => Math.Abs(x.Value) > BenchmarkPrecision).Select(x => x.ToIdentityString()).Except(computed.Select(x => x.ToIdentityString()));", - "\n var computedNotExpected = computed.Where(x => Math.Abs(x.Value) > BenchmarkPrecision).Select(x => x.ToIdentityString()).Except(expected.Select(x => x.ToIdentityString()));", + "\n var expectedNotComputed = expected.Where(x => Math.Abs(x.Value) > BenchmarkPrecision).Except(computed, EqualityComparer.Instance);", + "\n var computedNotExpected = computed.Where(x => Math.Abs(x.Value) > BenchmarkPrecision).Except(expected, EqualityComparer.Instance);", "\n if (expectedNotComputed.Any())", - "\n foreach (var error in expectedNotComputed)", - "\n errors.Add(new BenchmarkTestResult(\"Extra expected variable for: \" + error));", + "\n foreach (var variable in expectedNotComputed)", + "\n errors.Add(new BenchmarkTestResult(\"Extra expected variable for: Partition \" + variable.Partition + \", \" + variable.ToIdentityString()));", "\n if (computedNotExpected.Any())", - "\n foreach (var error in computedNotExpected)", - "\n errors.Add(new BenchmarkTestResult(\"Extra computed variable for: \" + error));", - "\n ", - "\n var misMatchedVariables = expected.Concat(computed).AggregateOver().Where(x => Math.Abs(x.Value) > BenchmarkPrecision);", - "\n if (misMatchedVariables.Any())", - "\n {", - "\n foreach (var variable in misMatchedVariables)", - "\n {", - "\n var message = variable.ToIdentityString();", - "\n var bmValue = expected.FirstOrDefault(x => x.AocType == variable.AocType && ", - "\n x.Novelty == variable.Novelty &&", - "\n x.DataNode == variable.DataNode && ", - "\n x.EstimateType == variable.EstimateType && ", - "\n x.AmountType == variable.AmountType && ", - "\n x.EconomicBasis == variable.EconomicBasis && ", - "\n x.AccidentYear == variable.AccidentYear", - "\n )?.Value ?? 0.0d;", - "\n var computedValue = computed.FirstOrDefault(x => x.AocType == variable.AocType && ", - "\n x.Novelty == variable.Novelty &&", - "\n x.DataNode == variable.DataNode && ", - "\n x.EstimateType == variable.EstimateType && ", - "\n x.AmountType == variable.AmountType && ", - "\n x.EconomicBasis == variable.EconomicBasis && ", - "\n x.AccidentYear == variable.AccidentYear", - "\n )?.Value ?? 0.0d;", - "\n errors.Add(new BenchmarkTestResult(\"Value does not match for Variable: \" + message, -bmValue, computedValue));", - "\n }", + "\n foreach (var variable in computedNotExpected)", + "\n errors.Add(new BenchmarkTestResult(\"Extra computed variable for: Partition \" + variable.Partition + \", \" + variable.ToIdentityString()));", + "\n", + "\n var comparer = EqualityComparer.Instance; ", + "\n foreach (var benchmarkVariable in expected) {", + "\n var computedVariable = computed.FirstOrDefault(y => comparer.Equals(benchmarkVariable,y))?? null;", + "\n if(computedVariable == null || Math.Abs(benchmarkVariable.Value + computedVariable.Value) < BenchmarkPrecision) continue;", + "\n errors.Add(new BenchmarkTestResult(\"Value does not match for Variable: Partition \" + benchmarkVariable.Partition + \", \" + benchmarkVariable.ToIdentityString(), -benchmarkVariable.Value, computedVariable.Value));", "\n }", + "\n", "\n return errors;", "\n}" ], @@ -261,15 +243,12 @@ "\n var reportingNode = g.Key.ReportingNode;", "\n var year = g.Key.Year;", "\n var month = g.Key.Month;", - "\n string scenario = g.Key.Scenario;", + "\n var scenario = g.Key.Scenario;", "\n ", - "\n //Set up Args and storage", - "\n await DataSource.Partition.SetAsync(new {ReportingNode = reportingNode, ", - "\n Year = year, ", - "\n Month = month, ", - "\n Scenario = scenario});", + "\n await DataSource.Partition.SetAsync(new {ReportingNode = reportingNode, Year = year, Month = month, Scenario = scenario});", "\n var partition = (await DataSource.Query().ToArrayAsync())", - "\n .SingleOrDefault(x => x.ReportingNode == reportingNode && x.Year== year && x.Month == month && x.Scenario == scenario)?.Id ?? new Guid();", + "\n .SingleOrDefault(x => x.ReportingNode == reportingNode && x.Year== year && x.Month == month && x.Scenario == scenario)?.Id ?? ", + "\n throw new Exception(\"Partition not found.\");", "\n ", "\n var computedVariablesByEstimateType = (await DataSource.Query()", "\n .Where(v => !excludedDataNodes.Contains(v.DataNode))", @@ -313,24 +292,6 @@ "metadata": {}, "execution_count": 0, "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "errorList" - ], - "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/ImportStorageTest.ipynb b/ifrs17-template/Test/ImportStorageTest.ipynb index 19b809b5..11c212dd 100644 --- a/ifrs17-template/Test/ImportStorageTest.ipynb +++ b/ifrs17-template/Test/ImportStorageTest.ipynb @@ -406,7 +406,7 @@ "//Define partition", "\nvar args = new ImportArgs(\"CH\", 2021, 3, Periodicity.Quarterly, null, ImportFormats.Cashflow);", "\n", - "\nvar reportingNodePartition = DataSource.Query().FirstOrDefault(x => x.ReportingNode == args.ReportingNode && x.Scenario == args.Scenario);", + "\nvar reportingNodePartition = DataSource.Query().FirstOrDefault(x => x.ReportingNode == args.ReportingNode);", "\nif(reportingNodePartition == null) ApplicationMessage.Log(Error.PartitionNotFound);", "\n", "\n", diff --git a/ifrs17-template/Test/ReportVariablesTest.ipynb b/ifrs17-template/Test/ReportVariablesTest.ipynb index 1ed77b94..d68c8116 100644 --- a/ifrs17-template/Test/ReportVariablesTest.ipynb +++ b/ifrs17-template/Test/ReportVariablesTest.ipynb @@ -137,15 +137,16 @@ "\n scopesData = await GetScopesDataAsync(args, reportStorage, Scopes);", "\n benchmarkData = await GetBenchmarkDataAsync(args, path, Workspace, Import);", "\n", - "\n scopesData.Should().BeEquivalentTo(benchmarkData,", - "\n options => options", - "\n //.ComparingRecordsByValue()", - "\n .ComparingRecordsByMembers() ", - "\n //.ComparingByMembers()", - "\n //.ComparingByValue()", - "\n //.Excluding(o => o.Value)", - "\n .Using(ctx => ctx.Subject.Should().BeApproximately(ctx.Expectation, BenchmarkPrecision))", - "\n .WhenTypeIs() );", + "\n scopesData.AggregateBy().Should().BeEquivalentTo(", + "\n benchmarkData,", + "\n options => options", + "\n //.ComparingRecordsByValue()", + "\n .ComparingRecordsByMembers() ", + "\n //.ComparingByMembers()", + "\n //.ComparingByValue()", + "\n //.Excluding(o => o.Value)", + "\n .Using(ctx => ctx.Subject.Should().BeApproximately(ctx.Expectation, BenchmarkPrecision))", + "\n .WhenTypeIs() );", "\n return Activity.Finish();", "\n}" ], diff --git a/ifrs17-template/Test/ScenarioDataImportTest.ipynb b/ifrs17-template/Test/ScenarioDataImportTest.ipynb new file mode 100644 index 00000000..193197c6 --- /dev/null +++ b/ifrs17-template/Test/ScenarioDataImportTest.ipynb @@ -0,0 +1,888 @@ +{ + "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": [ + "

Scenario Transactional Data 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": "code", + "source": [ + "var ws = Workspace.CreateNew();", + "\nws.InitializeFrom(DataSource);", + "\nvar argsBestEstimate = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, null, ImportFormats.Cashflow);", + "\nvar argsScenario = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, \"Test\", ImportFormats.Cashflow);", + "\nvar initStorage = new ImportStorage(argsBestEstimate, DataSource, ws);", + "\nawait initStorage.InitializeAsync();", + "\nvar 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);" + ], + "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,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,,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,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,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,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,ValueType,AccidentYear,Value", + "\nDT1.1,CF,ACA,,-10", + "\nDT1.1,CF,AEA,,-5", + "\nDT1.1,CF,NIC,,-280", + "\nDT1.1,CF,PR,,400", + "\nDTR1.1,CF,PR,,-200", + "\nDTR1.1,CF,NIC,,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": [ + "var ivsBestEstimateInit = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Scenario Init Cash flows" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowsScenario = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\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,-53.5,-52.5,-31.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": [ + "await Import.FromString(cashflowsScenario).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Scenario Init Actuals" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actualsScenario = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,NIC,,-308\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsScenario).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "actualVars.Length.Should().NotBe(0);", + "\ncashflowVars.Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Update of Deferrable Actuals with a Scenario Coverage Units Import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Update CU cashflow for scenario and check that the Amortization Factor (and hence the Deferrable Actual) is updated" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowsScenarioUpdateCU = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\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,CU,CL,C,,-17,-17,-17,-17,-17,-17,-17,-17,-17,-17,-17,-17,-17,-6.5,-6.5,-6.5,-6.5,-6.5,-6.5,-6.5,-6.5,-6.5,-7.5,-8.5\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowsScenarioUpdateCU).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Update of Deferrable Actuals with a Scenario ACA/AEA Import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actualsScenarioUpdateACAAEA = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,ACA,,-555", + "\nDT1.1,CF,AEA,,-777\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsScenarioUpdateACAAEA).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "\ndiffs.Where(x => x.EstimateType == EstimateTypes.F).ToArray().Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Removal of Deferrable Actuals with a Actual Scenario Import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Set ACA and AEA to zero and check that DA is removed" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actualsScenarioNoACAAEA = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,ACA,,0", + "\nDT1.1,CF,AEA,,0\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsScenarioNoACAAEA).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nvar ivsScenarioActualNoACAAEA = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioActualNoACAAEA.Except(ivsScenarioActualUpdateACAAEA, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Where(x => x.EstimateType == EstimateTypes.DA).ToArray().Length.Should().NotBe(0);", + "\nivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.F).Count().Should().NotBe(0);", + "\nivsScenarioActualNoACAAEA.Where(x => x.EstimateType == EstimateTypes.DA && Math.Abs(x.Value) > Precision).Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Robustness: back to Best Estimate" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowsScenarioEqualToBestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\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,,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,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\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var actualsScenarioEqualToBestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,ACA,,-10", + "\nDT1.1,CF,AEA,,-5", + "\nDT1.1,CF,NIC,,-280\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(actualsScenarioEqualToBestEstimate).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowsScenarioEqualToBestEstimate).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nvar ivsScenarioReimportEqualToBestEstimate = await DataSource.Query().ToArrayAsync(); ", + "\nvar diffs = ivsScenarioReimportEqualToBestEstimate.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance()).Where(x => Math.Abs(x.Value) > Precision);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "diffs.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reimport of Best Estimate Cashflow: zero impact on Scenario" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Reimport of best estimate with different gross cash flow, whereas reinsurance business is the same of the initialization. This causes an update of the best estimate IFRS variables but it must have no impact on Scenario variables because gross cash flow contains only a combination of AocType, Novelty and AmoutType that have already been imported for Scenario (see above the variable cashflowsScenarioEqualToBestEstimate). " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowsBestEstimateNoImpact = @\"", + "\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", + "\nDTR1.1,PR,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,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(cashflowsBestEstimateNoImpact).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nvar ivsScenarioReimportCashFlows = await DataSource.Query().ToArrayAsync();", + "\nvar diffs = ivsScenarioReimportCashFlows.Except(ivsBestEstimateInit, IfrsVariableComparer.Instance());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reimport of Best Estimate Cashflow: impact on Scenario" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var cashflowsBestEstimateImpact = @\"", + "\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,ICO,CL,C,,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3", + "\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 Import.FromString(cashflowsBestEstimateImpact).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "cashflowVars.Length.Should().NotBe(0);", + "\nactualVars.Length.Should().Be(0);", + "\ndiffs.Except(actualVars.Union(cashflowVars).Union(actualOrCashflowVars)).ToArray().Length.Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reimport of Best Estimate Actuals" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var newActualsBestEstimate = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,", + "\n@@Actual", + "\nDataNode,AocType,ValueType,AccidentYear,Value", + "\nDT1.1,CF,NIC,,-2000", + "\nDT1.1,CF,PR,,-4000\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(newActualsBestEstimate).WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "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);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Update of Deferrable Actuals with a Best Estimate Coverage Units Import" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Reset Coverage Units for Scenario so that they are taken from Best Estimate. Then, test that a re-import of Best Estimate Coverage Units changes the Scenario Deferrable Actuals. " + ], + "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": [ + "var cashflowsScenarioNoCU = @\"", + "\n@@Main", + "\nReportingNode,Year,Month,Scenario", + "\nCH,2020,12,Test", + "\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,,-274.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,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 cashflowsBestEstimateUpdatedCU = @\"", + "\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,,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,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,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 Import.FromString(cashflowsScenarioNoCU).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.Partition.SetAsync(argsScenario);", + "\nvar ivsScenarioReimportCashflowNoCU = await DataSource.Query().ToArrayAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(cashflowsBestEstimateUpdatedCU).WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "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();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "actualVars.Length.Should().Be(0);", + "\ncashflowVars.Length.Should().NotBe(0);" + ], + "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 deleted file mode 100644 index 8effcfa3..00000000 --- a/ifrs17-template/Test/ScenarioTest.ipynb +++ /dev/null @@ -1,264 +0,0 @@ -{ - "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": [ - "

Scenario Import Test

" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Context" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var defaultVarsBE = Workspace.Query().ToArray();" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Scenario Cash flows" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var cashflows_scenarioTest = @\"", - "\n@@Main", - "\nReportingNode,Year,Month,Scenario", - "\nCH,2020,12,Test", - "\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 cashflows_scenarioTest_equalTo_BestEstimate = @\"", - "\n@@Main", - "\nReportingNode,Year,Month,Scenario", - "\nCH,2020,12,Test", - "\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,,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,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\";" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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});", - "\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);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Scenario Actuals" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var actuals_scenarioTest = @\"", - "\n@@Main", - "\nReportingNode,Year,Month,Scenario", - "\nCH,2020,12,Test", - "\n@@Actual", - "\nDataNode,AocType,ValueType,AccidentYear,Value", - "\nDT1.1,CF,NIC,,-308\";" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var actuals_scenarioTest_equalTo_BestEstimate = @\"", - "\n@@Main", - "\nReportingNode,Year,Month,Scenario", - "\nCH,2020,12,Test", - "\n@@Actual", - "\nDataNode,AocType,ValueType,AccidentYear,Value", - "\nDT1.1,CF,NIC,,-280\";" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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});", - "\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 => x.EstimateType == \"CU\").ToArray().Length.Should().Be(0);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Robustness: back to Best Estimate" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "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" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance()).ToArray().Length.Should().Be(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-template/Test/Tests.ipynb b/ifrs17-template/Test/Tests.ipynb index d7608993..d4442366 100644 --- a/ifrs17-template/Test/Tests.ipynb +++ b/ifrs17-template/Test/Tests.ipynb @@ -93,7 +93,7 @@ { "cell_type": "code", "source": [ - "#!eval-notebook \"ScenarioTest\"" + "#!eval-notebook \"ScenarioDataImportTest\"" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index e4db9b6c..64a58f8c 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -51,7 +51,7 @@ "source": [ "public enum Warning {", "\n // Import", - "\n ActiveDataNodeWithCashflowBOPI, VariablesAlreadyImported, VariablesAlreadyCalculated,", + "\n ActiveDataNodeWithCashflowBOPI, VariablesAlreadyImported, VariablesAlreadyCalculated, ScenarioReCalculations,", "\n // Default", "\n Generic", "\n}; " @@ -66,7 +66,7 @@ "public enum Error { ", "\n // Import", "\n NoMainTab, IncompleteMainTab, ParsingScientificNotation, ValueTypeNotFound, ValueTypeNotValid, ", - "\n ReportingNodeInMainNotFound, YearInMainNotFound, MonthInMainNotFound,", + "\n ReportingNodeInMainNotFound, YearInMainNotFound, MonthInMainNotFound, ScenarioInMainNotAvailable,", "\n AocTypeNotValid, AocTypeCompulsoryNotFound, AocTypePositionNotSupported, AocConfigurationOrderNotUnique,", "\n // Partition", "\n PartitionNotFound, ParsedPartitionNotFound, PartititionNameNotFound, PartitionTypeNotFound,", @@ -117,6 +117,7 @@ "\n (Error.ReportingNodeInMainNotFound , _) => $\"Reporting Node missing from the Main tab.\",", "\n (Error.YearInMainNotFound , _) => $\"Year missing from the Main tab.\",", "\n (Error.MonthInMainNotFound , _) => $\"Month missing from the Main tab.\",", + "\n (Error.ScenarioInMainNotAvailable , 1) => $\"Scenario {s[0]} has not been defined.\",", "\n (Error.AocTypeNotValid , 1) => $\"The parsed AoC Type {s[0]} is invalid.\",", "\n (Error.AocTypeCompulsoryNotFound , _) => $\"Not all compulsory AoC Types have been imported.\",", "\n (Error.AocTypePositionNotSupported , 1) => $\"The position of the AoC Type {s[0]} is not supported.\",", @@ -182,6 +183,7 @@ "public static string Get (Warning w, params string[] s) => (w, s.Length) switch {", "\n // Import", "\n (Warning.ActiveDataNodeWithCashflowBOPI , 1) => $\"Cash flow with AoC Type: {AocTypes.BOP} and Novelty: {Novelties.I} for Group of Contract {s[0]} is not allowed because previous period data are available.\",", + "\n (Warning.ScenarioReCalculations , 1) => $\"The import of the current file for the Best Estimate scenario makes the result of dependent Scenarios out of date. Hence, the following Scenarios are recalculated: {s[0]}.\", ", "\n // Default", "\n (Warning.Generic , _) => $\"{s[0]}\",", "\n (_ , _) => $\"Warning not found.\"", diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 92cf5634..a9275444 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -1257,10 +1257,6 @@ "\n [Dimension(typeof(ReportingNode))]", "\n [IdentityProperty]", "\n public string ReportingNode { get; init; }", - "\n", - "\n [Dimension(typeof(Scenario))]", - "\n [IdentityProperty]", - "\n public string Scenario { get; init; }", "\n}" ], "metadata": {}, @@ -1305,6 +1301,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": {}, @@ -1680,7 +1681,6 @@ "\n public State PreviousState { get; init; }", "\n ", "\n public bool IsReinsurance { get; init; }", - "\n public string Scenario { get; init; }", "\n public DataNodeData(){}", "\n}" ], @@ -2072,7 +2072,43 @@ { "cell_type": "code", "source": [ - "public record Args(string ReportingNode, int Year, int Month, Periodicity Periodicity, string Scenario){}" + "public record Args", + "\n{", + "\n [Required]", + "\n [IdentityProperty]", + "\n [Dimension(typeof(ReportingNode))]", + "\n public string ReportingNode { get; init; }", + "\n", + "\n [Required]", + "\n [IdentityProperty]", + "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [Dimension(typeof(int), nameof(Year))]", + "\n [Range(1900, 2100, ErrorMessage = \"Value for {0} must be between {1} and {2}.\")]", + "\n public int Year { get; init; }", + "\n", + "\n [Required]", + "\n [IdentityProperty]", + "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [Dimension(typeof(int), nameof(Month))]", + "\n [Range(1, 12, ErrorMessage = \"Value for {0} must be between {1} and {2}.\")]", + "\n public int Month { get; init; } ", + "\n ", + "\n [IdentityProperty]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n public Periodicity Periodicity{ get; init; }", + "\n", + "\n public Args(string reportingNode, int year, int month, Periodicity periodicity, string scenario)", + "\n {", + "\n ReportingNode = reportingNode;", + "\n Year = year;", + "\n Month = month;", + "\n Periodicity = periodicity;", + "\n Scenario = scenario;", + "\n }", + "\n}" ], "metadata": {}, "execution_count": 0, 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/ImportScopeCalculation.ipynb b/ifrs17/Import/ImportScopeCalculation.ipynb index 3d155e93..5ea716a5 100644 --- a/ifrs17/Import/ImportScopeCalculation.ipynb +++ b/ifrs17/Import/ImportScopeCalculation.ipynb @@ -238,7 +238,7 @@ "\n ", "\n ", "\n IEnumerable ActualAmountTypes => GetStorage().GetIfrsVariables(Identity)", - "\n .Where(iv => GetStorage().EstimateTypesByImportFormat[ImportFormats.Actual].Contains(iv.EstimateType))", + "\n .Where(iv => GetStorage().ImportActualEstimateTypes.Contains(iv.EstimateType))", "\n .Select(x => x.AmountType)", "\n .ToHashSet();", "\n}", @@ -1192,7 +1192,7 @@ "\n builder.ForScope(s => ", "\n s.WithApplicability(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow", "\n || x.GetStorage().IsSecondaryScope(x.Identity.DataNode)));", - "\n ", + "\n", "\n private int shift => GetStorage().GetShift(0);//Identity.ProjectionPeriod", "\n private int timeStep => GetStorage().GetTimeStep(0);//Identity.ProjectionPeriod", "\n private double amortizedFactor => GetScope(Identity)", @@ -1201,7 +1201,7 @@ "\n .Take(timeStep)", "\n .Aggregate(1d, (x, y) => x * y);", "\n [NotVisible] string EconomicBasis => GetContext();", - "\n ", + "\n", "\n string EstimateType => EstimateTypes.F;", "\n double Value => Math.Abs(amortizedFactor - 1d) > Precision", "\n ? 1d - amortizedFactor", @@ -2066,26 +2066,27 @@ "source": [ "public interface PvToIfrsVariable: IScope", "\n{", - "\n IEnumerable PvLocked => GetScope(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", - "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable PvLocked => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", + "\n", + "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", "\n}" ], "metadata": {}, @@ -2097,26 +2098,27 @@ "source": [ "public interface RaToIfrsVariable: IScope", "\n{", - "\n IEnumerable RaCurrent => GetScope(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", - "\n IEnumerable RaLocked => GetScope(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable RaCurrent => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = null,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", + "\n ", + "\n IEnumerable RaLocked => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = null,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", "\n}" ], "metadata": {}, @@ -2128,33 +2130,35 @@ "source": [ "public interface ActualToIfrsVariable: IScope", "\n{", - "\n IEnumerable Actual => GetScope(Identity).Actuals.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.Identity.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", - "\n IEnumerable AdvanceActual => GetScope(Identity).Actuals.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.Identity.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", - "\n IEnumerable OverdueActual => GetScope(Identity).Actuals.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.Identity.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable Actual => GetScope(Identity).Actuals.Select(x => ", + "\n new IfrsVariable{ EstimateType = x.Identity.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", + "\n ", + "\n IEnumerable AdvanceActual => GetScope(Identity).Actuals.Select(x => ", + "\n new IfrsVariable{ EstimateType = x.Identity.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", + "\n", + "\n IEnumerable OverdueActual => GetScope(Identity).Actuals.Select(x => ", + "\n new IfrsVariable{ EstimateType = x.Identity.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", "\n}" ], "metadata": {}, @@ -2166,14 +2170,14 @@ "source": [ "public interface DeferrableToIfrsVariable: IScope", "\n{", - "\n IEnumerable DeferrableActual => GetScope(Identity).RepeatOnce().Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n AccidentYear = null,", - "\n Value = x.Value,", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable DeferrableActual => GetScope(Identity).RepeatOnce().Select(x => ", + "\n new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n AccidentYear = null,", + "\n Value = x.Value,", + "\n Partition = GetStorage().TargetPartition });", "\n}" ], "metadata": {}, @@ -2190,7 +2194,6 @@ "\n ? Enumerable.Empty()", "\n : GetScope(Identity)", "\n .ByAmountType", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(sc => new IfrsVariable{ EstimateType = GetScope(Identity).EstimateType, ", "\n DataNode = sc.Identity.Id.DataNode, ", "\n AocType = sc.Identity.Id.AocType, ", @@ -2206,7 +2209,6 @@ "\n ? Enumerable.Empty()", "\n : GetScope(Identity)", "\n .ByAmountTypeAndEstimateType", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(sc => new IfrsVariable{ EstimateType = GetStorage().ExperienceAdjustEstimateTypeMapping[sc.Identity.EstimateType], ", "\n DataNode = sc.Identity.Id.DataNode, ", "\n AocType = sc.Identity.Id.AocType, ", @@ -2231,7 +2233,6 @@ "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM", "\n ? GetScope(Identity, o => o.WithContext(EconomicBasis))", "\n .RepeatOnce()", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", "\n DataNode = x.Identity.DataNode,", "\n AocType = x.Identity.AocType,", @@ -2244,7 +2245,6 @@ "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC", "\n ? Enumerable.Empty()", "\n : GetScope(Identity).RepeatOnce()", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", "\n DataNode = x.Identity.DataNode,", "\n AocType = x.Identity.AocType,", @@ -2257,7 +2257,6 @@ "\n ? Enumerable.Empty()", "\n : Identity.IsReinsurance ", "\n ? GetScope(Identity).RepeatOnce()", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", "\n DataNode = x.Identity.DataNode,", "\n AocType = x.Identity.AocType,", @@ -2266,7 +2265,6 @@ "\n Partition = GetStorage().TargetPartition", "\n })", "\n : GetScope(Identity).RepeatOnce()", - "\n .Where(x => Math.Abs(x.Value) >= Precision)", "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", "\n DataNode = x.Identity.DataNode,", "\n AocType = x.Identity.AocType,", @@ -2325,7 +2323,23 @@ "\n .Concat(DeferrableActual)", "\n .Concat(Csms)", "\n .Concat(Loss);", - "\n} " + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface ComputeAllScopes: IScope", + "\n{", + "\n IEnumerable CalculatedIfrsVariables => GetStorage().ImportFormat switch {", + "\n ImportFormats.Actual => GetScope(Identity).CalculatedIfrsVariables,", + "\n ImportFormats.Cashflow => GetScope(Identity).CalculatedIfrsVariables,", + "\n ImportFormats.Opening => GetScope(Identity).CalculatedIfrsVariables,", + "\n };", + "\n}" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index c6572abc..8f2303c0 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -118,7 +118,8 @@ "\n public Dictionary EstimateTypeDimension { get; private set; }", "\n public Dictionary> EstimateTypesByImportFormat { get; private set; }", "\n public Dictionary ExperienceAdjustEstimateTypeMapping { get; private set; } ", - "\n ", + "\n public HashSet ImportActualEstimateTypes => GetImportActualEstimateType();", + "\n", "\n //Constructor", "\n public ImportStorage(ImportArgs args, IDataSource querySource, IWorkspace workspace)", "\n {", @@ -174,8 +175,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.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", + "\n var parsedIfrsVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", "\n ", "\n //DataNodes", "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", @@ -273,15 +274,8 @@ "\n", "\n if(DefaultPartition != TargetPartition) {", "\n await querySource.Partition.SetAsync(DefaultPartition);", - "\n var defaultRawVariables = await querySource.Query()", - "\n .Where(rv => rv.Partition == DefaultPartition)", - "\n .Where(rv => primaryScope.Contains(rv.DataNode)).ToArrayAsync();", - "\n var defaultIfrsVariables = await querySource.Query()", - "\n .Where(iv => iv.Partition == DefaultPartition)", - "\n .Where(iv => primaryScopeFromParsedVariables.Contains(iv.DataNode)", - "\n && !EstimateTypesByImportFormat[ImportFormat].Contains(iv.EstimateType) ", - "\n || primaryScopeFromLinkedReinsurance.Contains(iv.DataNode) ", - "\n || secondaryScope.Contains(iv.DataNode)).ToArrayAsync();", + "\n var defaultRawVariables = await querySource.Query().Where(rv => rv.Partition == DefaultPartition && primaryScope.Contains(rv.DataNode)).ToArrayAsync();", + "\n var defaultIfrsVariables = await querySource.Query().Where(iv => iv.Partition == DefaultPartition && allImportScopes.Contains(iv.DataNode)).ToArrayAsync(); ", "\n rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", "\n await querySource.Partition.SetAsync(TargetPartition);", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 3ec5a6aa..118b8dbc 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -258,20 +258,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "public async Task CleanDatabaseFromPartitionAsync (Guid partitionId, Func filter = null) where T : class, IPartitioned", - "\n{", - "\n var loadData = (await DataSource.Query().Where(x => x.Partition == partitionId).ToArrayAsync())", - "\n .Where(filter?? (Func)(x => true)).ToList();", - "\n await DataSource.DeleteAsync(loadData);", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -284,10 +270,16 @@ { "cell_type": "code", "source": [ - "public async Task CommitToDatabase (IWorkspace workspace, Guid partitionId, bool snapshot = true, Func filter = null) where T : class, IPartitioned", + "public async Task CommitToDatabase (IWorkspace workspace, Guid partitionId = new Guid(), bool snapshot = true, Expression> filter = null) ", + "\nwhere TData : class, IPartitioned", + "\nwhere TPartition : IfrsPartition", "\n{", - "\n if(snapshot) await CleanDatabaseFromPartitionAsync(partitionId, filter);", - "\n await DataSource.UpdateAsync( await workspace.Query().ToArrayAsync() );", + "\n if(partitionId != new Guid()) {", + "\n await workspace.Partition.SetAsync(partitionId);", + "\n await DataSource.Partition.SetAsync(partitionId);", + "\n }", + "\n if(snapshot) await CleanDatabaseAsync(filter);", + "\n await DataSource.UpdateAsync( await workspace.Query().ToArrayAsync() );", "\n await DataSource.CommitAsync();", "\n}" ], @@ -309,7 +301,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,6 +321,8 @@ "\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 if(ApplicationMessage.HasErrors()) return null;", "\n", "\n ImportArgs args;", "\n switch(typeof(IPartition).Name) {", @@ -341,8 +335,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) : {", @@ -391,27 +384,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()).FirstOrDefault();", "\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,10 +421,88 @@ "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" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Get Target Args" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task GetTargetArgsAsync(ImportArgs mainArgs)", + "\n{", + "\n var scenarioArgs = await DataSource.Query() ", + "\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, default(Periodicity), x.Scenario, ImportFormats.Cashflow)).ToArrayAsync();", + "\n var isMultipleArg = mainArgs.Scenario == null && scenarioArgs.Any();", + "\n var targetArgs = isMultipleArg", + "\n ? mainArgs.RepeatOnce().Concat(scenarioArgs)", + "\n : mainArgs.RepeatOnce();", + "\n", + "\n if (isMultipleArg) ApplicationMessage.Log(Warning.ScenarioReCalculations, String.Join(\", \", scenarioArgs.Select(x => x.Scenario)));", + "\n return targetArgs.ToArray();", + "\n} " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Calculate and Upload IFRS Variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CalculateAndUploadVariablesAsync(ImportArgs args, IWorkspace workspace, bool saveRawVariables)", + "\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 if(storage.DefaultPartition != storage.TargetPartition){", + "\n var bestEstimateIvs = await DataSource.LoadPartitionedDataAsync(storage.DefaultPartition, storage.TargetPartition);", + "\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 }", + "\n", + "\n", + "\n await workspace.UpdateAsync(ivs.Where(x => storage.DefaultPartition != storage.TargetPartition || Math.Abs(x.Value) >= Precision));", + "\n await CommitToDatabase(workspace, storage.TargetPartition, snapshot : true, ", + "\n filter : x => storage.EstimateTypesByImportFormat[args.ImportFormat].Contains(x.EstimateType) ", + "\n && storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n if(saveRawVariables) {", + "\n if(args.Scenario == null) await workspace.DeleteAsync(await workspace.Query().Where(rv => rv.Values.Sum(x => Math.Abs(x)) < Precision).ToArrayAsync());", + "\n await CommitToDatabase(workspace, storage.TargetPartition, snapshot : true, ", + "\n filter : x => storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n }", + "\n return Activity.Finish();", "\n}" ], "metadata": {}, @@ -454,7 +521,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 +625,16 @@ { "cell_type": "markdown", "source": [ - "# Data Nodes", + "# 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. " ], @@ -586,88 +662,82 @@ "\n await storage.InitializeAsync();", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n ", - "\n var errors = new List();", "\n var importLogPortfolios = await Import.FromDataSet(dataSet)", - "\n .WithType((dataset, datarow) => new InsurancePortfolio {", - "\n SystemName = datarow.Field(nameof(DataNode.SystemName)),", - "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", - "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n ContractualCurrency = datarow.Field(nameof(DataNode.ContractualCurrency)),", - "\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 })", - "\n .WithType((dataset, datarow) =>new ReinsurancePortfolio {", - "\n SystemName = datarow.Field(nameof(DataNode.SystemName)),", - "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", - "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n ContractualCurrency = datarow.Field(nameof(DataNode.ContractualCurrency)),", - "\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 })", + "\n .WithType((dataset, datarow) => ", + "\n new InsurancePortfolio { SystemName = datarow.Field(nameof(DataNode.SystemName)),", + "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", + "\n Partition = storage.TargetPartitionByReportingNode.Id,", + "\n ContractualCurrency = datarow.Field(nameof(DataNode.ContractualCurrency)),", + "\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 .WithType((dataset, datarow) =>", + "\n new ReinsurancePortfolio { SystemName = datarow.Field(nameof(DataNode.SystemName)),", + "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", + "\n Partition = storage.TargetPartitionByReportingNode.Id,", + "\n ContractualCurrency = datarow.Field(nameof(DataNode.ContractualCurrency)),", + "\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 .WithTarget(workspace)", "\n .ExecuteAsync();", "\n ", "\n var portfolios = await workspace.Query().ToDictionaryAsync(x => x.SystemName);", + "\n var yieldCurveColumnGroupOfInsuranceContract = dataSet.Tables[nameof(GroupOfInsuranceContract)].Columns.Any(x => x.ColumnName == nameof(GroupOfInsuranceContract.YieldCurveName));", + "\n var yieldCurveColumnGroupOfReinsuranceContract = dataSet.Tables[nameof(GroupOfReinsuranceContract)].Columns.Any(x => x.ColumnName == nameof(GroupOfReinsuranceContract.YieldCurveName));", + "\n", "\n var importLogGroupOfContracts = await Import.FromDataSet(dataSet)", "\n .WithType((dataset, datarow) => {", - "\n var gicSystemName = datarow.Field(nameof(DataNode.SystemName));", - "\n var pf = datarow.Field(nameof(InsurancePortfolio));", - "\n if(!portfolios.TryGetValue(pf, out var portfolioData))", - "\n {", - "\n ApplicationMessage.Log(Error.PortfolioGicNotFound, pf, gicSystemName);", - "\n return null;", - "\n }", - "\n var gic = new GroupOfInsuranceContract {", - "\n SystemName = gicSystemName,", - "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", - "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n ContractualCurrency = portfolioData.ContractualCurrency,", - "\n FunctionalCurrency = portfolioData.FunctionalCurrency,", - "\n LineOfBusiness = portfolioData.LineOfBusiness,", - "\n ValuationApproach = portfolioData.ValuationApproach,", - "\n OciType = portfolioData.OciType,", - "\n AnnualCohort = Convert.ToInt32(datarow.Field(nameof(GroupOfContract.AnnualCohort))),", - "\n LiabilityType = datarow.Field(nameof(GroupOfContract.LiabilityType)),", - "\n Profitability = datarow.Field(nameof(GroupOfContract.Profitability)),", - "\n Portfolio = pf,", - "\n YieldCurveName = dataset.Tables[nameof(GroupOfInsuranceContract)].Columns.Any(x => x.ColumnName == nameof(GroupOfContract.YieldCurveName)) ", - "\n ? datarow.Field(nameof(GroupOfContract.YieldCurveName)) ", - "\n : (string)null,", - "\n };", - "\n return ExtendGroupOfContract(gic, datarow);", - "\n })", + "\n var gicSystemName = datarow.Field(nameof(DataNode.SystemName));", + "\n var pf = datarow.Field(nameof(InsurancePortfolio));", + "\n if(!portfolios.TryGetValue(pf, out var portfolioData)) {", + "\n ApplicationMessage.Log(Error.PortfolioGicNotFound, pf, gicSystemName);", + "\n return null;", + "\n }", + "\n var gic = new GroupOfInsuranceContract { SystemName = gicSystemName,", + "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", + "\n Partition = storage.TargetPartitionByReportingNode.Id,", + "\n ContractualCurrency = portfolioData.ContractualCurrency,", + "\n FunctionalCurrency = portfolioData.FunctionalCurrency,", + "\n LineOfBusiness = portfolioData.LineOfBusiness,", + "\n ValuationApproach = portfolioData.ValuationApproach,", + "\n OciType = portfolioData.OciType,", + "\n AnnualCohort = Convert.ToInt32(datarow.Field(nameof(GroupOfContract.AnnualCohort))),", + "\n LiabilityType = datarow.Field(nameof(GroupOfContract.LiabilityType)),", + "\n Profitability = datarow.Field(nameof(GroupOfContract.Profitability)),", + "\n Portfolio = pf,", + "\n YieldCurveName = yieldCurveColumnGroupOfInsuranceContract", + "\n ? datarow.Field(nameof(GroupOfContract.YieldCurveName)) ", + "\n : (string)null };", + "\n return ExtendGroupOfContract(gic, datarow);", + "\n })", "\n .WithType((dataset, datarow) => {", - "\n var gricSystemName = datarow.Field(nameof(DataNode.SystemName));", - "\n var pf = datarow.Field(nameof(ReinsurancePortfolio));", - "\n if(!portfolios.TryGetValue(pf, out var portfolioData))", - "\n {", - "\n ApplicationMessage.Log(Error.PortfolioGicNotFound, pf, gricSystemName);", - "\n return null;", - "\n }", - "\n var gric = new GroupOfReinsuranceContract {", - "\n SystemName = gricSystemName,", - "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", - "\n Partition = storage.TargetPartitionByReportingNode.Id,", - "\n ContractualCurrency = portfolioData.ContractualCurrency,", - "\n FunctionalCurrency = portfolioData.FunctionalCurrency,", - "\n LineOfBusiness = portfolioData.LineOfBusiness,", - "\n ValuationApproach = portfolioData.ValuationApproach,", - "\n OciType = portfolioData.OciType,", - "\n AnnualCohort = Convert.ToInt32(datarow.Field(nameof(GroupOfContract.AnnualCohort))),", - "\n LiabilityType = datarow.Field(nameof(GroupOfContract.LiabilityType)),", - "\n Profitability = datarow.Field(nameof(GroupOfContract.Profitability)),", - "\n Portfolio = pf,", - "\n Partner = datarow.Field(nameof(GroupOfContract.Partner)),", - "\n YieldCurveName = dataset.Tables[nameof(GroupOfReinsuranceContract)].Columns.Any(x => x.ColumnName == nameof(GroupOfContract.YieldCurveName)) ", - "\n ? datarow.Field(nameof(GroupOfContract.YieldCurveName)) ", - "\n : (string)null,", - "\n };", - "\n return ExtendGroupOfContract(gric, datarow);", - "\n })", + "\n var gricSystemName = datarow.Field(nameof(DataNode.SystemName));", + "\n var pf = datarow.Field(nameof(ReinsurancePortfolio));", + "\n if(!portfolios.TryGetValue(pf, out var portfolioData)) {", + "\n ApplicationMessage.Log(Error.PortfolioGicNotFound, pf, gricSystemName);", + "\n return null;", + "\n }", + "\n var gric = new GroupOfReinsuranceContract { SystemName = gricSystemName,", + "\n DisplayName = datarow.Field(nameof(DataNode.DisplayName)),", + "\n Partition = storage.TargetPartitionByReportingNode.Id,", + "\n ContractualCurrency = portfolioData.ContractualCurrency,", + "\n FunctionalCurrency = portfolioData.FunctionalCurrency,", + "\n LineOfBusiness = portfolioData.LineOfBusiness,", + "\n ValuationApproach = portfolioData.ValuationApproach,", + "\n OciType = portfolioData.OciType,", + "\n AnnualCohort = Convert.ToInt32(datarow.Field(nameof(GroupOfContract.AnnualCohort))),", + "\n LiabilityType = datarow.Field(nameof(GroupOfContract.LiabilityType)),", + "\n Profitability = datarow.Field(nameof(GroupOfContract.Profitability)),", + "\n Portfolio = pf,", + "\n Partner = datarow.Field(nameof(GroupOfContract.Partner)),", + "\n YieldCurveName = yieldCurveColumnGroupOfReinsuranceContract", + "\n ? datarow.Field(nameof(GroupOfContract.YieldCurveName)) ", + "\n : (string)null };", + "\n return ExtendGroupOfContract(gric, datarow);", + "\n })", "\n .WithTarget(workspace)", "\n .ExecuteAsync();", "\n ", @@ -685,10 +755,10 @@ "\n var workspace = Workspace.CreateNew();", "\n var log = await UploadDataNodesToWorkspaceAsync(dataSet, workspace);", "\n var partition = (Guid)workspace.Partition.GetCurrent(nameof(PartitionByReportingNode));", - "\n await CommitToDatabase(workspace, partition);", - "\n await CommitToDatabase(workspace, partition);", - "\n await CommitToDatabase(workspace, partition);", - "\n await CommitToDatabase(workspace, partition);", + "\n await CommitToDatabase(workspace, partition);", + "\n await CommitToDatabase(workspace, partition);", + "\n await CommitToDatabase(workspace, partition);", + "\n await CommitToDatabase(workspace, partition);", "\n return log;", "\n});" ], @@ -739,7 +809,6 @@ "\n .DisableInitialization()", "\n .DisableInitialization()", "\n .DisableInitialization());", - "\n ", "\n Activity.Start();", "\n var args = await GetArgsFromMainAsync(dataSet);", "\n if(Activity.HasErrors()) return Activity.Finish();", @@ -772,7 +841,7 @@ "Import.DefineFormat(ImportFormats.DataNodeState, async (options, dataSet) => {", "\n var workspace = Workspace.CreateNew();", "\n var log = await UploadDataNodeStateToWorkspaceAsync(dataSet, workspace);", - "\n await CommitToDatabase(workspace, (Guid)workspace.Partition.GetCurrent(nameof(PartitionByReportingNode)), snapshot: false); ", + "\n await CommitToDatabase(workspace, (Guid)workspace.Partition.GetCurrent(nameof(PartitionByReportingNode)), snapshot: false); ", "\n return log;", "\n});" ], @@ -799,7 +868,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();", @@ -885,8 +953,9 @@ "\n Guid partitionId = new Guid();", "\n var workspace = Workspace.CreateNew();", "\n var log = await UploadDataNodeParameterToWorkspaceAsync(dataSet, partitionId, workspace);", - "\n await CommitToDatabase(workspace, partitionId, snapshot: false);", - "\n await CommitToDatabase(workspace, partitionId, snapshot: false); ", + "\n await CommitToDatabase(workspace, partitionId, snapshot: false);", + "\n await CommitToDatabase(workspace, partitionId, snapshot: false); ", + "\n ", "\n return log;", "\n});" ], @@ -922,6 +991,8 @@ "\n await parsingStorage.InitializeAsync();", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n ", + "\n var hasAccidentYearColumn = dataSet.Tables[ImportFormats.Cashflow].Columns.Where(x => x.ColumnName == nameof(RawVariable.AccidentYear)).Count() > 0; ", + "\n ", "\n var importLog = await Import.FromDataSet(dataSet)", "\n .WithType ( (dataset, datarow) => {", "\n var aocType = datarow.Field(nameof(RawVariable.AocType));", @@ -951,10 +1022,14 @@ "\n var estimateType = isEstimateType ? amountTypeFromFile : EstimateTypes.BE;", "\n ", "\n var values = datarow.Table.Columns.Where(c => c.ColumnName.StartsWith(nameof(RawVariable.Values))).OrderBy(c => c.ColumnName.Length).ThenBy(c => c.ColumnName)", - "\n .Select(x => datarow.Field(x.ColumnName).CheckStringForExponentialAndConvertToDouble()).Prune();", + "\n .Select(x => datarow.Field(x.ColumnName).CheckStringForExponentialAndConvertToDouble()).ToArray();", "\n ", "\n // Filter out empty raw variables for AocType != CL", - "\n if(values.Length == 0 && aocType != AocTypes.CL) return null; //TODO: extend this check for all mandatory step and not just for CL", + "\n //TODO: extend this check for all mandatory step and not just for CL", + "\n if(args.Scenario == null) {", + "\n values = values.Prune();", + "\n if(values.Length == 0 && aocType != AocTypes.CL) return null;", + "\n }", "\n ", "\n var item = new RawVariable {", "\n DataNode = dataNode,", @@ -962,8 +1037,9 @@ "\n Novelty = novelty,", "\n AmountType = amountType,", "\n EstimateType = estimateType,", - "\n AccidentYear = dataset.Tables[ImportFormats.Cashflow].Columns.Where(x => x.ColumnName == nameof(RawVariable.AccidentYear)).Count()>0?", - "\n (Int32.TryParse((datarow.Field(nameof(RawVariable.AccidentYear))), out var accidentYear)? accidentYear : (int?)null) : (int?)null, ", + "\n AccidentYear = hasAccidentYearColumn && Int32.TryParse((datarow.Field(nameof(RawVariable.AccidentYear))), out var accidentYear)", + "\n ? accidentYear", + "\n : (int?)null,", "\n Partition = parsingStorage.TargetPartitionByReportingNodeAndPeriod.Id,", "\n Values = Multiply(GetSign((aocType, amountType, estimateType, dataNodeData.IsReinsurance), parsingStorage.HierarchyCache), values)", "\n };", @@ -984,35 +1060,22 @@ "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", + "\n var targetArgs = await GetTargetArgsAsync(mainArgs);", + "\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 ", - "\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 var log = await ParseCashflowsToWorkspaceAsync(dataSet, mainArgs, workspace);", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n", - "\n return Activity.Finish().Merge(parsingLog); ", + "\n foreach (var args in targetArgs) {", + "\n log = log.Merge(await CalculateAndUploadVariablesAsync(args, workspace, args == mainArgs));", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n return Activity.Finish().Merge(log); ", "\n});" ], "metadata": {}, @@ -1106,31 +1169,22 @@ "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 var workspace = Workspace.CreateNew();", - "\n var parsingLog = await ParseActualsToWorkspaceAsync(dataSet, args, workspace);", - "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", - "\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 var targetArgs = await GetTargetArgsAsync(mainArgs);", + "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Actual, mainArgs);", + "\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[ImportFormats.Actual].Contains(x.EstimateType) && ", - "\n storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode));", + "\n var workspace = Workspace.CreateNew();", + "\n var log = await ParseActualsToWorkspaceAsync(dataSet, mainArgs, workspace);", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n", - "\n return Activity.Finish().Merge(parsingLog);", + "\n foreach (var args in targetArgs) {", + "\n log = log.Merge(await CalculateAndUploadVariablesAsync(args, workspace, false)); ", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", + "\n return Activity.Finish().Merge(log);", "\n});" ], "metadata": {}, @@ -1232,11 +1286,9 @@ "\n ", "\n workspace.Query().Select(v => new {v.DataNode, v.AccidentYear}).Distinct();", "\n ", - "\n await CommitToDatabase(workspace, ", - "\n partitionId, ", - "\n snapshot : true,", - "\n filter : x => workspace.Query().Select(v => v.DataNode).Distinct().Contains(x.DataNode));", - "\n ", + "\n await CommitToDatabase(workspace, partitionId, snapshot : true,", + "\n filter : x => workspace.Query().Select(v => v.DataNode).Distinct().Contains(x.DataNode));", + "\n", "\n return Activity.Finish().Merge(parsingLog);", "\n});" ], @@ -1263,29 +1315,15 @@ "\n var args = (await GetArgsFromMainAsync(dataSet)) with {ImportFormat = ImportFormats.Opening};", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, args);", "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n ", + "\n", "\n Guid partitionId = new Guid();", "\n var workspace = Workspace.CreateNew();", "\n var parsingLog = await ParseSimpleValueToWorkspaceAsync(dataSet, args, partitionId, workspace);", "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", - "\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.Opening].Contains(x.EstimateType) && ", - "\n storage.DataNodesByImportScope[ImportScope.Primary].Contains(x.DataNode ));", - "\n", - "\n return Activity.Finish().Merge(parsingLog);", + "\n var calculationLog = await CalculateAndUploadVariablesAsync(args, workspace, false); ", + "\n if(calculationLog.Errors.Any()) return Activity.Finish().Merge(calculationLog);", + "\n return Activity.Finish().Merge(parsingLog).Merge(calculationLog);", "\n});" ], "metadata": {}, diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb index c8cde44b..243e73f9 100644 --- a/ifrs17/Utils/EqualityComparers.ipynb +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -27,7 +27,34 @@ { "cell_type": "code", "source": [ - "#!import \"../DataModel/DataStructure\"" + "#!import \"../DataModel/DataStructure\"", + "\nusing System;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "SequenceEqual static extension method is a utility for double arrays to enable comparison with a pre-defined precision." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static bool SequenceEqual(this double[] defaultArray, double[] testArray, double precision)", + "\n{", + "\n if ( defaultArray == null || testArray == null ) return false; ", + "\n if (defaultArray.Length != testArray.Length) return false;", + "\n for (int i = 0; i < defaultArray.Length; i++){", + "\n if(Math.Abs(defaultArray[i]-testArray[i]) >= precision) return false;", + "\n }", + "\n return true;", + "\n}" ], "metadata": {}, "execution_count": 0, @@ -46,16 +73,11 @@ "\n", "\n public bool Equals(RawVariable x, RawVariable y) =>", "\n x.AccidentYear == y.AccidentYear && x.AmountType == y.AmountType && x.DataNode == y.DataNode && x.AocType == y.AocType && ", - "\n x.Novelty == y.Novelty && x.EstimateType == y.EstimateType && (IgnoreValues ? true : x.Values.SequenceEqual(y.Values)); // TODO: enable Precision", + "\n x.Novelty == y.Novelty && x.EstimateType == y.EstimateType && (IgnoreValues ? true : x.Values.SequenceEqual(y.Values, Precision));", "\n", - "\n public int GetHashCode(RawVariable v) => IgnoreValues ", - "\n ? HashCode.Combine(v.AccidentYear, v.AmountType, v.DataNode, v.AocType, v.Novelty) ", - "\n : HashCode.Combine(v.AccidentYear, v.AmountType, v.DataNode, v.AocType, v.Novelty, v.Values);", + "\n public int GetHashCode(RawVariable v) => 0;", "\n", - "\n public static RawVariableComparer Instance(bool ignoreValues = false)", - "\n { ", - "\n return new RawVariableComparer(ignoreValues);", - "\n }", + "\n public static RawVariableComparer Instance(bool ignoreValues = false) => new RawVariableComparer(ignoreValues);", "\n}" ], "metadata": {}, @@ -75,22 +97,37 @@ "\n", "\n public bool Equals(IfrsVariable x, IfrsVariable y) =>", "\n x.AccidentYear == y.AccidentYear && x.AmountType == y.AmountType && x.DataNode == y.DataNode && x.AocType == y.AocType && ", - "\n x.Novelty == y.Novelty && x.EstimateType == y.EstimateType && (IgnoreValue ? true : Math.Abs(x.Value - y.Value) < Precision); ", + "\n x.Novelty == y.Novelty && x.EstimateType == y.EstimateType && x.EconomicBasis == y.EconomicBasis && (IgnoreValue ? true : Math.Abs(x.Value - y.Value) < Precision); ", "\n", - "\n public int GetHashCode(IfrsVariable v) => IgnoreValue ", - "\n ? HashCode.Combine(v.AccidentYear, v.AmountType, v.DataNode, v.AocType, v.Novelty) ", - "\n : HashCode.Combine(v.AccidentYear, v.AmountType, v.DataNode, v.AocType, v.Novelty, v.Value.ToString(\"F5\"));", + "\n public int GetHashCode(IfrsVariable v) => 0;", "\n", - "\n public static IfrsVariableComparer Instance(bool ignoreValue = false)", - "\n { ", - "\n return new IfrsVariableComparer(ignoreValue);", - "\n }", + "\n public static IfrsVariableComparer Instance(bool ignoreValue = false) => new IfrsVariableComparer(ignoreValue);", "\n}" ], "metadata": {}, "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, 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": [ @@ -146,15 +183,6 @@ "metadata": {}, "execution_count": 0, "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index c783cc39..e6a5a207 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -271,6 +271,27 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Import Actuals EstimateType" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static HashSet GetImportActualEstimateType()", + "\n{", + "\n return new []{EstimateTypes.A, EstimateTypes.AA, EstimateTypes.OA}.ToHashSet();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] -} +} \ No newline at end of file diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 47f4597b..e90d6921 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))", @@ -399,6 +399,69 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task LoadPartitionedDataAsync(this IDataSource querySource, Guid partition, Guid? partitionBackup = null)", + "\n where T : IPartitioned", + "\n where P : IPartition", + "\n", + "\n{", + "\n await querySource.Partition.SetAsync

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

(partitionBackup);", + "\n return data;", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task QueryPartitionedDataAsync(this IWorkspace workspace, IDataSource dataSource, Guid targetPartition, Guid defaultPartition, string format)", + "\n where T : IPartitioned", + "\n where P : IPartition", + "\n{", + "\n var isRelaxed = targetPartition != defaultPartition &&", + "\n ((format != ImportFormats.Cashflow && typeof(T).Name == nameof(IfrsVariable)) ||", + "\n (format == ImportFormats.Cashflow && typeof(T).Name == nameof(RawVariable)));", + "\n", + "\n var variablesFromWorkspace = await workspace.LoadPartitionedDataAsync(targetPartition);", + "\n if(!isRelaxed || variablesFromWorkspace.Any()) return variablesFromWorkspace;", + "\n", + "\n // For scenario re-calculation", + "\n var variablesFromDataSource = await dataSource.LoadPartitionedDataAsync(targetPartition);", + "\n if(variablesFromDataSource.Any()) return variablesFromDataSource;", + "\n", + "\n // For scenarios related to parameters solely", + "\n return await dataSource.LoadPartitionedDataAsync(defaultPartition, targetPartition);", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file