diff --git a/full-ifrs17-template/Files/Dimensions.csv b/full-ifrs17-template/Files/Dimensions.csv index c6729913..d0a29c98 100644 --- a/full-ifrs17-template/Files/Dimensions.csv +++ b/full-ifrs17-template/Files/Dimensions.csv @@ -214,7 +214,22 @@ Default,Default,,,,,,,,,, ,,,,,,,,,,, @@Scenario,,,,,,,,,,, SystemName,DisplayName,,,,,,,,,, -BE,Best Estimate,,,,,,,,,, +YCUP1.0pct,Yield Curve Up 1.0pct,,,,,,,,,, +YCDW1.0pct,Yield Curve Down 1.0pct,,,,,,,,,, +SRUP1.0pct,Spread Rate Up 1.0pct,,,,,,,,,, +SRDW1.0pct,Spread Rate Down 1.0pct,,,,,,,,,, +EUP1.0pct,Equity Up 1.0pct,,,,,,,,,, +EDW1.0pct,Equity Down 1.0pct,,,,,,,,,, +FXUP1.0pct,Exchange Rate Up 1.0pct,,,,,,,,,, +FXDW1.0pct,Exchange Rate Down 1.0pct,,,,,,,,,, +MTUP10pct,Mortality Up 10pct,,,,,,,,,, +MTDW10pct,Mortality Down 10pct,,,,,,,,,, +LUP10pct,Longevity Up 10pct,,,,,,,,,, +LDW10pct,Longevity Down 10pct,,,,,,,,,, +DUP10pct,Disability Up 10pct,,,,,,,,,, +DDW10pct,Disability Down 10pct,,,,,,,,,, +LICUP10pct,Lic Up 10pct,,,,,,,,,, +LICDW10pct,Lic Down 10pct,,,,,,,,,, ,,,,,,,,,,, @@ValuationApproach,,,,,,,,,,, SystemName,DisplayName,,,,,,,,,, diff --git a/full-ifrs17-template/Files/TransactionalData/Actuals_CH_2020_12_MTUP10pct.csv b/full-ifrs17-template/Files/TransactionalData/Actuals_CH_2020_12_MTUP10pct.csv new file mode 100644 index 00000000..eb8fb4c5 --- /dev/null +++ b/full-ifrs17-template/Files/TransactionalData/Actuals_CH_2020_12_MTUP10pct.csv @@ -0,0 +1,12 @@ +@@Main,,,, +ReportingNode,Year,Month,Scenario, +CH,2020,12,MTUP10pct, +@@Actual,,,, +DataNode,AocType,ValueType,AccidentYear,Value +DT1.1,CF,NIC,,-310 +DT1.2,CF,NIC,2020,-310 +DT2.1,CF,NIC,,-310 +DT1.3,CF,NIC,,-310 +DT2.2,CF,NIC,2020,-310 +DTR1.1,CF,NIC,,170 +DTR1.2,CF,NIC,2020,170 diff --git a/full-ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_MTUP10pct.csv b/full-ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_MTUP10pct.csv new file mode 100644 index 00000000..3e08a787 --- /dev/null +++ b/full-ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_MTUP10pct.csv @@ -0,0 +1,13 @@ +@@Main,,,,,,,,,,,,,,,,,,,,,,,,,,,, +ReportingNode,Year,Month,Scenario,,,,,,,,,,,,,,,,,,,,,,,,, +CH,2020,12,MTUP10pct,,,,,,,,,,,,,,,,,,,,,,,,, +@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,,, +DataNode,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 +DT1.1,NIC,BOP,N,,-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 +DT1.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 +DT1.2,NIC,BOP,N,2020,-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 +DT1.2,NIC,CL,C,2020,-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 +DTR1.1,NIC,BOP,N,,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75 +DTR1.1,NIC,CL,C,,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75 +DTR1.2,NIC,BOP,N,2020,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75 +DTR1.2,NIC,CL,C,2020,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75,13.75 diff --git a/full-ifrs17-template/Import/CloseImportTemplate.ipynb b/full-ifrs17-template/Import/CloseImportTemplate.ipynb index eae574bf..bfdfe090 100644 --- a/full-ifrs17-template/Import/CloseImportTemplate.ipynb +++ b/full-ifrs17-template/Import/CloseImportTemplate.ipynb @@ -118,7 +118,9 @@ { "cell_type": "code", "source": [ - "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());" + "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nawait DataSource.Partition.SetAsync(null);", + "\nawait DataSource.Partition.SetAsync(null);" ] } ] diff --git a/full-ifrs17-template/Initialization/InitSystemorphToMemory.ipynb b/full-ifrs17-template/Initialization/InitSystemorphToMemory.ipynb index a96f6a66..37489f3f 100644 --- a/full-ifrs17-template/Initialization/InitSystemorphToMemory.ipynb +++ b/full-ifrs17-template/Initialization/InitSystemorphToMemory.ipynb @@ -85,6 +85,18 @@ "await Import.FromFile(\"../Files/TransactionalData/SimpleValue_CH_2020_12.csv\").WithFormat(ImportFormats.SimpleValue ).WithTarget(DataSource).ExecuteAsync()" ] }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12_MTUP10pct.csv\").WithFormat(ImportFormats.Cashflow).WithTarget(DataSource).ExecuteAsync()" + ] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/Actuals_CH_2020_12_MTUP10pct.csv\").WithFormat(ImportFormats.Actual).WithTarget(DataSource).ExecuteAsync()" + ] + }, { "cell_type": "markdown", "source": [ diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv new file mode 100644 index 00000000..6a49b39f --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_A.csv @@ -0,0 +1,14 @@ +@@Main +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 +,NIC,CF,DT1.3,,A,C,-310 +2020,NIC,CF,DT2.2,,A,C,-310 +,NIC,CF,DTR1.1,,A,C,170 +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/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv new file mode 100644 index 00000000..9d548fcb --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BE.csv @@ -0,0 +1,69 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@BE +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,NIC,BOP,DT1.1,L,BE,N,658.6282390585294 +,PR,BOP,DT1.1,L,BE,N,-798.536731161375 +,NIC,BOP,DT1.1,C,BE,N,658.6282390585294 +,PR,BOP,DT1.1,C,BE,N,-798.536731161375 +,NIC,EOP,DT1.1,L,BE,C,329.6431046636596 +,PR,EOP,DT1.1,L,BE,C,-399.63392949885525 +,NIC,EOP,DT1.1,C,BE,C,329.6431046636596 +,PR,EOP,DT1.1,C,BE,C,-399.63392949885525 +,NIC,IA,DT1.1,L,BE,N,1.0148656051304286 +,PR,IA,DT1.1,L,BE,N,-1.0971983374806105 +,NIC,IA,DT1.1,C,BE,N,1.0148656051304286 +,PR,IA,DT1.1,C,BE,N,-1.0971983374806105 +,NIC,CF,DT1.1,L,BE,N,-330 +,PR,CF,DT1.1,L,BE,N,400 +,NIC,CF,DT1.1,C,BE,N,-330 +,PR,CF,DT1.1,C,BE,N,400 +2020,NIC,BOP,DT1.2,L,BE,N,658.6282390585294 +2020,NIC,BOP,DT1.2,C,BE,N,658.6282390585294 +2020,NIC,EOP,DT1.2,L,BE,C,329.6431046636596 +2020,NIC,EOP,DT1.2,C,BE,C,329.6431046636596 +2020,NIC,IA,DT1.2,L,BE,N,1.0148656051304286 +2020,NIC,IA,DT1.2,C,BE,N,1.0148656051304286 +2020,NIC,CF,DT1.2,L,BE,N,-330 +2020,NIC,CF,DT1.2,C,BE,N,-330 +,NIC,BOP,DTR1.1,L,BE,N,-329.3141195292647 +,PR,BOP,DTR1.1,L,BE,N,399.2683655806875 +,CDR,BOP,DTR1.1,L,BE,N,0.5292475300191577 +,NIC,BOP,DTR1.1,C,BE,N,-329.3141195292647 +,PR,BOP,DTR1.1,C,BE,N,399.2683655806875 +,CDR,BOP,DTR1.1,C,BE,N,0.5292475300191577 +,NIC,EOP,DTR1.1,L,BE,C,-164.8215523318298 +,PR,EOP,DTR1.1,L,BE,C,199.81696474942763 +,CDR,EOP,DTR1.1,L,BE,C,0.12679876434718015 +,NIC,EOP,DTR1.1,C,BE,C,-164.8215523318298 +,PR,EOP,DTR1.1,C,BE,C,199.81696474942763 +,CDR,EOP,DTR1.1,C,BE,C,0.12679876434718015 +,NIC,IA,DTR1.1,L,BE,N,-0.5074328025652143 +,PR,IA,DTR1.1,L,BE,N,0.5485991687403052 +,CDR,IA,DTR1.1,L,BE,N,0.001287210150087148 +,NIC,IA,DTR1.1,C,BE,N,-0.5074328025652143 +,PR,IA,DTR1.1,C,BE,N,0.5485991687403052 +,CDR,IA,DTR1.1,C,BE,N,0.001287210150087148 +,NIC,CF,DTR1.1,L,BE,N,165 +,PR,CF,DTR1.1,L,BE,N,-200 +,CDR,CF,DTR1.1,L,BE,N,-0.40373597582193455 +,NIC,CF,DTR1.1,C,BE,N,165 +,PR,CF,DTR1.1,C,BE,N,-200 +,CDR,CF,DTR1.1,C,BE,N,-0.40373597582193455 +2020,NIC,BOP,DTR1.2,L,BE,N,-329.3141195292647 +2020,CDR,BOP,DTR1.2,L,BE,N,0.5292475300191577 +2020,NIC,BOP,DTR1.2,C,BE,N,-329.3141195292647 +2020,CDR,BOP,DTR1.2,C,BE,N,0.5292475300191577 +2020,NIC,EOP,DTR1.2,L,BE,C,-164.8215523318298 +2020,CDR,EOP,DTR1.2,L,BE,C,0.12679876434718015 +2020,NIC,EOP,DTR1.2,C,BE,C,-164.8215523318298 +2020,CDR,EOP,DTR1.2,C,BE,C,0.12679876434718015 +2020,NIC,IA,DTR1.2,L,BE,N,-0.5074328025652143 +2020,CDR,IA,DTR1.2,L,BE,N,0.001287210150087148 +2020,NIC,IA,DTR1.2,C,BE,N,-0.5074328025652143 +2020,CDR,IA,DTR1.2,C,BE,N,0.001287210150087148 +2020,NIC,CF,DTR1.2,L,BE,N,165 +2020,CDR,CF,DTR1.2,L,BE,N,-0.40373597582193455 +2020,NIC,CF,DTR1.2,C,BE,N,165 +2020,CDR,CF,DTR1.2,C,BE,N,-0.40373597582193455 \ No newline at end of file diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv new file mode 100644 index 00000000..4674e6db --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_BEPA.csv @@ -0,0 +1,6 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@BEPA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,PR,CF,DT1.1,L,BEPA,N,320 \ No newline at end of file diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv new file mode 100644 index 00000000..5b4b8afc --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_C.csv @@ -0,0 +1,22 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@C +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,,EA,DT2.1,,C,C,-139.99082483519595 +,,EA,DT1.1,,C,C,-80.02326986577215 +,,BOP,DT1.1,,C,N,80.03319764297927 +,,IA,DT1.1,,C,N,-0.009927777207129784 +,,BOP,DT2.1,,C,N,139.90849210284577 +,,IA,DT2.1,,C,N,0.08233273235018213 +,,EA,DT1.3,,C,C,-139.99082483519595 +,,BOP,DT1.3,,C,N,139.90849210284577 +,,IA,DT1.3,,C,N,0.08233273235018213 +,,AM,DTR1.1,,C,C,26.60498224366728 +,,EOP,DTR1.1,,C,C,-13.93718742938804 +,,BOP,DTR1.1,,C,N,-40.5458463515088 +,,IA,DTR1.1,,C,N,0.003676678453477744 +,,AM,DTR2.1,,C,C,46.24958203305145 +,,EOP,DTR2.1,,C,C,-24.22813469379126 +,,BOP,DTR2.1,,C,N,-70.43538016962212 +,,IA,DTR2.1,,C,N,-0.04233655722058882 \ No newline at end of file diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv new file mode 100644 index 00000000..a3a224c1 --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_F.csv @@ -0,0 +1,9 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@F +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,,AM,DT1.1,L,F,C,0.6562298579039588 +,,AM,DT1.2,L,F,C,1 +,,AM,DTR1.1,L,F,C,0.6562298579039588 +,,AM,DTR1.2,L,F,C,1 \ No newline at end of file diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv new file mode 100644 index 00000000..4f72f891 --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_L.csv @@ -0,0 +1,14 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@L +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,,AM,DT2.1,,L,C,-118.1273954398082 +,,EA,DT2.1,,L,C,180.00917516480405 +,,EA,DT1.1,,L,C,239.97673013422786 +,,AM,DT1.1,,L,C,-157.47989551624102 +,,EOP,DT1.1,,L,C,82.49683461798685 +,,EOP,DT2.1,,L,C,61.88177972499585 +,,EA,DT1.3,,L,C,260.00917516480405 +,,AM,DT1.3,,L,C,-170.6257840721249 +,,EOP,DT1.3,,L,C,89.38339109267915 \ No newline at end of file diff --git a/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv new file mode 100644 index 00000000..fdff21b6 --- /dev/null +++ b/full-ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12_MTUP10pct_RA.csv @@ -0,0 +1,37 @@ +@@Main +Month,ReportingNode,Scenario,Year +12,CH,MTUP10pct,2020 +@@RA +AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Value +,,BOP,DT1.1,C,RA,N,59.8752944598663 +,,BOP,DT1.1,L,RA,N,59.8752944598663 +,,EOP,DT1.1,C,RA,C,29.967554969423595 +,,EOP,DT1.1,L,RA,C,29.967554969423595 +,,IA,DT1.1,C,RA,N,0.09226050955731169 +,,IA,DT1.1,L,RA,N,0.09226050955731169 +,,CF,DT1.1,C,RA,N,-30 +,,CF,DT1.1,L,RA,N,-30 +2020,,BOP,DT1.2,C,RA,N,59.8752944598663 +2020,,BOP,DT1.2,L,RA,N,59.8752944598663 +2020,,EOP,DT1.2,C,RA,C,29.967554969423595 +2020,,EOP,DT1.2,L,RA,C,29.967554969423595 +2020,,IA,DT1.2,C,RA,N,0.09226050955731169 +2020,,IA,DT1.2,L,RA,N,0.09226050955731169 +2020,,CF,DT1.2,C,RA,N,-30 +2020,,CF,DT1.2,L,RA,N,-30 +,,BOP,DTR1.1,C,RA,N,-29.93764722993315 +,,BOP,DTR1.1,L,RA,N,-29.93764722993315 +,,EOP,DTR1.1,C,RA,C,-14.983777484711798 +,,EOP,DTR1.1,L,RA,C,-14.983777484711798 +,,IA,DTR1.1,C,RA,N,-0.046130254778655844 +,,IA,DTR1.1,L,RA,N,-0.046130254778655844 +,,CF,DTR1.1,C,RA,N,15 +,,CF,DTR1.1,L,RA,N,15 +2020,,BOP,DTR1.2,C,RA,N,-29.93764722993315 +2020,,BOP,DTR1.2,L,RA,N,-29.93764722993315 +2020,,EOP,DTR1.2,C,RA,C,-14.983777484711798 +2020,,EOP,DTR1.2,L,RA,C,-14.983777484711798 +2020,,IA,DTR1.2,C,RA,N,-0.046130254778655844 +2020,,IA,DTR1.2,L,RA,N,-0.046130254778655844 +2020,,CF,DTR1.2,C,RA,N,15 +2020,,CF,DTR1.2,L,RA,N,15 \ No newline at end of file diff --git a/full-ifrs17-template/Test/ExportIfrsVariable.ipynb b/full-ifrs17-template/Test/ExportIfrsVariable.ipynb index 9d21556c..f844924b 100644 --- a/full-ifrs17-template/Test/ExportIfrsVariable.ipynb +++ b/full-ifrs17-template/Test/ExportIfrsVariable.ipynb @@ -53,14 +53,28 @@ { "cell_type": "code", "source": [ - "public async Task ExportBenchmarks(ImportArgs args)", - "\n{", - "\n await DataSource.Partition.SetAsync(new {ReportingNode = args.ReportingNode, Year= args.Year, Month = args.Month, Scenario = args.Scenario});", - "\n var computedVariables = (await DataSource.Query().ToArrayAsync()).ToDictionaryGrouped(x => x.EstimateType, x => x.ToArray());", - "\n", - "\n foreach (var estimateType in computedVariables.Keys)", - "\n {", - "\n await Export.ToCsv(pathToBm+\"BM_\"+args.ReportingNode+\"_\"+args.Year.ToString()+\"_\"+args.Month.ToString()+\"_\"+estimateType)", + "var scenario = \"MTUP10pct\";" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new ImportArgs (\"CH\", 2020, 12, Periodicity.Quarterly, scenario, null);", + "\nawait DataSource.Partition.SetAsync(new {ReportingNode = args.ReportingNode, Year= args.Year, Month = args.Month, Scenario = args.Scenario});", + "\nvar computedVariables = (await DataSource.Query().ToArrayAsync()).ToDictionaryGrouped(x => x.EstimateType, x => x.ToArray());" + ] + }, + { + "cell_type": "code", + "source": [ + "(0, computedVariables.Keys)" + ] + }, + { + "cell_type": "code", + "source": [ + "var estimateType = \"BEPA\";", + "\nawait Export.ToCsv(\"BM_\"+args.ReportingNode+\"_\"+args.Year.ToString()+\"_\"+args.Month.ToString()+\"_\"+scenario+\"_\"+estimateType)", "\n .WithTable(tableConfig => tableConfig", "\n .AtBeginning()", "\n .WithName(Main)", @@ -74,16 +88,8 @@ "\n .WithColumn(x => x.Partition, x => x.Delete())", "\n .WithColumn(x => x.Id, x => x.Delete())", "\n )", - "\n .ExecuteAsync();", - "\n }", - "\n}" - ] - }, - { - "cell_type": "code", - "source": [ - "foreach (var args in argsArray)", - "\n await ExportBenchmarks(args);" + "\n .WithSource(DataSource)", + "\n .ExecuteAsync()" ] }, { diff --git a/full-ifrs17-template/Test/IfrsVariablesTest.ipynb b/full-ifrs17-template/Test/IfrsVariablesTest.ipynb index 6e90aee1..78347e9c 100644 --- a/full-ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/full-ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -44,14 +44,14 @@ { "cell_type": "code", "source": [ - "public record BenchmarkMetadata(string FileName, string ReportingNode, int Year, int Month){} " + "public record BenchmarkMetadata(string FileName, string ReportingNode, int Year, int Month, string Scenario = null){} " ] }, { "cell_type": "code", "source": [ "var bmFiles = new BenchmarkMetadata[]{", - "\n //2020 Q4", + "\n // 2020 Q4", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_A.csv\" , \"CH\", 2020, 12),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_AA.csv\" , \"CH\", 2020, 12),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_APA.csv\" , \"CH\", 2020, 12),", @@ -62,7 +62,7 @@ "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_F.csv\" , \"CH\", 2020, 12),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_OA.csv\" , \"CH\", 2020, 12),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2020_12_RA.csv\" , \"CH\", 2020, 12),", - "\n //2021 Q1", + "\n // 2021 Q1", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_A.csv\" , \"CH\", 2021, 3),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_AA.csv\" , \"CH\", 2021, 3),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_AAPA.csv\" , \"CH\", 2021, 3),", @@ -77,6 +77,14 @@ "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_OA.csv\" , \"CH\", 2021, 3),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_OAPA.csv\" , \"CH\", 2021, 3),", "\n new BenchmarkMetadata(pathToBm+\"BM_CH_2021_3_RA.csv\" , \"CH\", 2021, 3),", + "\n // 2020 Q4", + "\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_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};" ] }, @@ -208,16 +216,16 @@ "cell_type": "code", "source": [ "var errorList = new List();", - "\nforeach (var g in bmFiles.GroupBy(x => (ReportingNode: x.ReportingNode, Year: x.Year, Month: x.Month)))", + "\nforeach (var g in bmFiles.GroupBy(x => (ReportingNode: x.ReportingNode, Year: x.Year, Month: x.Month, Scenario : x.Scenario)))", "\n{", "\n var reportingNode = g.Key.ReportingNode;", "\n var year = g.Key.Year;", "\n var month = g.Key.Month;", - "\n string scenario = null;", + "\n string scenario = g.Key.Scenario;", "\n ", "\n //Set up Args and storage", "\n await DataSource.Partition.SetAsync(new {ReportingNode = reportingNode, ", - "\n Year= year, ", + "\n Year = year, ", "\n Month = month, ", "\n Scenario = scenario});", "\n var partition = (await DataSource.Query().ToArrayAsync())", @@ -245,14 +253,13 @@ "\n //Get the computed Data", "\n var computedVariables = computedVariablesByEstimateType.TryGetValue(bmTableName, out var ret) ? ret : Enumerable.Empty();", "\n", - "\n if(!computedVariables.Any()) ", + "\n if(!computedVariables.Any())", "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName, 0, 0));", "\n //CompareAgainstBm", "\n if (bmVariables.Any() && computedVariables.Any()) //TODO we are adding duplicates here", - "\n errorList = errorList.Concat(CompareAgainstBm(errorList, bmVariables, computedVariables)).ToList();", + "\n errorList = errorList.Concat(CompareAgainstBm(errorList, bmVariables, computedVariables)).Distinct().ToList();", "\n }", - "\n}", - "\nerrorList = errorList.Distinct().ToList();" + "\n}" ] }, { diff --git a/full-ifrs17-template/Test/ScenarioTest.ipynb b/full-ifrs17-template/Test/ScenarioTest.ipynb new file mode 100644 index 00000000..c86a432b --- /dev/null +++ b/full-ifrs17-template/Test/ScenarioTest.ipynb @@ -0,0 +1,195 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Context" + ] + }, + { + "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" + ] + }, + { + "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" + ] + }, + { + "cell_type": "code", + "source": [ + "var defaultVarsBE = Workspace.Query().ToArray();" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Scenario Cashflows" + ] + }, + { + "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\";" + ] + }, + { + "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\";" + ] + }, + { + "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" + ] + }, + { + "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);" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Scenario Actuals" + ] + }, + { + "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\";" + ] + }, + { + "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\";" + ] + }, + { + "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" + ] + }, + { + "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);" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Robustness: back to Best Estimate" + ] + }, + { + "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" + ] + }, + { + "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" + ] + }, + { + "cell_type": "code", + "source": [ + "Workspace.Query().Except(defaultVarsBE, IfrsVariableComparer.Instance()).ToArray().Length.Should().Be(0);" + ] + }, + { + "cell_type": "code", + "source": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/full-ifrs17-template/Test/SequenceImportTest.ipynb b/full-ifrs17-template/Test/SequenceImportTest.ipynb new file mode 100644 index 00000000..cfbc24c3 --- /dev/null +++ b/full-ifrs17-template/Test/SequenceImportTest.ipynb @@ -0,0 +1,121 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Cashflow -> Actuals" + ] + }, + { + "cell_type": "code", + "source": [ + "var ws1 = Workspace.CreateNew();", + "\nws1.InitializeFrom(DataSource);" + ] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12.csv\").WithFormat(ImportFormats.Cashflow).WithTarget(ws1).ExecuteAsync()" + ] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/Actuals_CH_2020_12.csv\").WithFormat(ImportFormats.Actual).WithTarget(ws1).ExecuteAsync()" + ] + }, + { + "cell_type": "code", + "source": [ + "ws1.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nws1.Initialize(x => x.FromSource(DataSource));" + ] + }, + { + "cell_type": "code", + "source": [ + "var ifrsVars1 = await ws1.Query().ToArrayAsync();", + "\nifrsVars1.Count()" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Actuals -> Cashflow" + ] + }, + { + "cell_type": "code", + "source": [ + "var ws2 = Workspace.CreateNew();", + "\nws2.InitializeFrom(DataSource);" + ] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/Actuals_CH_2020_12.csv\").WithFormat(ImportFormats.Actual).WithTarget(ws2).ExecuteAsync()" + ] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12.csv\").WithFormat(ImportFormats.Cashflow).WithTarget(ws2).ExecuteAsync()" + ] + }, + { + "cell_type": "code", + "source": [ + "ws2.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", + "\nws2.Initialize(x => x.FromSource(DataSource));" + ] + }, + { + "cell_type": "code", + "source": [ + "var ifrsVars2 = await ws2.Query().ToArrayAsync();", + "\nifrsVars2.Count()" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Test" + ] + }, + { + "cell_type": "code", + "source": [ + "ifrsVars1.Except(ifrsVars2, IfrsVariableComparer.Instance()).Count().Should().Be(0);" + ] + }, + { + "cell_type": "code", + "source": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/full-ifrs17-template/Test/Tests.ipynb b/full-ifrs17-template/Test/Tests.ipynb index 06b5b7d7..2b7fefcb 100644 --- a/full-ifrs17-template/Test/Tests.ipynb +++ b/full-ifrs17-template/Test/Tests.ipynb @@ -53,6 +53,18 @@ "#!eval-notebook \"TechnicalMarginTest\"" ] }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"SequenceImportTest\"" + ] + }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"ScenarioTest\"" + ] + }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17/CalculationEngine.ipynb b/ifrs17/CalculationEngine.ipynb index 0936fa66..13b87df7 100644 --- a/ifrs17/CalculationEngine.ipynb +++ b/ifrs17/CalculationEngine.ipynb @@ -22,8 +22,7 @@ "\n#!import \"Report/ReportMutableScopes\"", "\n#!import \"Import/Importers\"", "\n#!import \"Export/ExportConfiguration\"", - "\n#!import \"Utils/TestHelper\"", - "\n#!import \"Utils/ImportCalculationMethods\"" + "\n#!import \"Utils/TestHelper\"" ] }, { diff --git a/ifrs17/Constants/Consts.ipynb b/ifrs17/Constants/Consts.ipynb index 06a89425..9d54b276 100644 --- a/ifrs17/Constants/Consts.ipynb +++ b/ifrs17/Constants/Consts.ipynb @@ -245,18 +245,41 @@ "cell_type": "code", "source": [ "public static class AmountTypes{", - "\n public const string ACA = nameof(ACA); //Attributable Commissions Acquisition", - "\n public const string AEA = nameof(AEA); //Attributable Expenses Acquisition", - "\n public const string CDR = nameof(CDR); //Credit Default Risk", - "\n public const string CL = nameof(CL); //Claims", - "\n public const string PR = nameof(PR); //Premiums", - "\n public const string NIC = nameof(NIC); //Claims Non-Investment component", - "\n public const string ICO = nameof(ICO); //Claims Investment component", - "\n public const string NE = nameof(NE); //Non Attributable Expenses", - "\n public const string ACM = nameof(ACM); //Attributable Commissions Maintenance", - "\n public const string AEM = nameof(AEM); //Attributable Expenses Maintenance", - "\n public const string AC = nameof(AC); //Attributable Commissions", - "\n public const string AE = nameof(AE); //Attributable Expenses", + "\n public const string ACA = nameof(ACA); // Attributable Commissions Acquisition", + "\n public const string AEA = nameof(AEA); // Attributable Expenses Acquisition", + "\n public const string CDR = nameof(CDR); // Credit Default Risk", + "\n public const string CL = nameof(CL); // Claims", + "\n public const string PR = nameof(PR); // Premiums", + "\n public const string NIC = nameof(NIC); // Claims Non-Investment component", + "\n public const string ICO = nameof(ICO); // Claims Investment component", + "\n public const string NE = nameof(NE); // Non Attributable Expenses", + "\n public const string ACM = nameof(ACM); // Attributable Commissions Maintenance", + "\n public const string AEM = nameof(AEM); // Attributable Expenses Maintenance", + "\n public const string AC = nameof(AC); // Attributable Commissions", + "\n public const string AE = nameof(AE); // Attributable Expenses", + "\n}" + ] + }, + { + "cell_type": "code", + "source": [ + "public static class Scenarios{", + "\n public const string YCUP1pct = nameof(YCUP1pct); // Yield Curve Up 1.0pct", + "\n public const string YCDW1pct = nameof(YCDW1pct); // Yield Curve Down 1.0pct", + "\n public const string SRUP1pct = nameof(SRUP1pct); // Spread Rate Up 1.0pct", + "\n public const string SRDW1pct = nameof(SRDW1pct); // Spread Rate Down 1.0pct", + "\n public const string EUP1pct = nameof(EUP1pct); // Equity Up 1.0pct", + "\n public const string EDW1pct = nameof(EDW1pct); // Equity Down 1.0pct", + "\n public const string FXUP1pct = nameof(FXUP1pct); // Exchange Rate Up 1.0pct", + "\n public const string FXDW1pct = nameof(FXDW1pct); // Exchange Rate Down 1.0pct", + "\n public const string MTUP10pct = nameof(MTUP10pct); // Mortality Up 10pct", + "\n public const string MTDW10pct = nameof(MTDW10pct); // Mortality Down 10pct", + "\n public const string LUP10pct = nameof(LUP10pct); // Longevity Up 10pct", + "\n public const string LDW10pct = nameof(LDW10pct); // Longevity Down 10pct", + "\n public const string DUP10pct = nameof(DUP10pct); // Disability Up 10pct", + "\n public const string DDW10pct = nameof(DDW10pct); // Disability Down 10pct", + "\n public const string LICUP10pct = nameof(LICUP10pct); // Lic Up 10pct", + "\n public const string LICDW10pct = nameof(LICDW10pct); // Lic Down 10pct", "\n}" ] }, diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 18c2edbe..61e79c34 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -42,7 +42,7 @@ "source": [ "public enum Warning {", "\n // Import", - "\n ActiveDataNodeWithCashflowBOPI,", + "\n ActiveDataNodeWithCashflowBOPI, VariablesAlreadyImported, VariablesAlreadyCalculated,", "\n // Default", "\n Generic", "\n}; " @@ -174,4 +174,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 636e87a9..0755159b 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -43,8 +43,12 @@ { "cell_type": "code", "source": [ - "#r \"nuget:Systemorph.Arithmetics,1.5.5\"", + "#r \"nuget:Systemorph.Activities,1.5.5\"", + "\n#r \"nuget:Systemorph.Arithmetics,1.5.5\"", "\n#r \"nuget:Systemorph.Workspace,1.5.3\"", + "\n#r \"nuget:Systemorph.InteractiveObjects,1.5.5\"", + "\n#r \"nuget:Systemorph.SharePoint,1.5.6\"", + "\n#r \"nuget:Systemorph.OneDrive,1.5.6\"", "\n#r \"nuget:Systemorph.Scopes,1.5.5\"", "\n#r \"nuget:Systemorph.Import,1.5.1\"", "\n#r \"nuget:Systemorph.Test,1.5.5\"", @@ -52,9 +56,7 @@ "\n#r \"nuget:Systemorph.DataSetReader,1.5.1\"", "\n#r \"nuget:Systemorph.DataSource,1.5.3\"", "\n#r \"nuget:Systemorph.DataSource.Conversions,1.5.3\"", - "\n#r \"nuget:Systemorph.Reporting,1.5.5\"", - "\n#r \"nuget:Systemorph.DomainDesigner,1.5.1\"", - "\n#r \"nuget:Systemorph.SharePoint,1.5.6\"" + "\n#r \"nuget:Systemorph.Reporting,1.5.5\"" ] }, { @@ -174,6 +176,22 @@ "\n}" ] }, + { + "cell_type": "markdown", + "source": [ + "The interface IWithYearMonthAndScenario allows to identify the year, month and scenario associated to the data:", + "\n" + ] + }, + { + "cell_type": "code", + "source": [ + "public interface IWithYearMonthAndScenario : IWithYearAndMonth", + "\n{", + "\n public string Scenario { get; init; }", + "\n}" + ] + }, { "cell_type": "markdown", "source": [ @@ -795,7 +813,7 @@ { "cell_type": "code", "source": [ - "public record ExchangeRate : KeyedRecord", + "public record ExchangeRate : KeyedRecord, IWithYearMonthAndScenario", "\n{ ", "\n [Required]", "\n [IdentityProperty]", @@ -826,6 +844,11 @@ "\n", "\n [Display(Order = 50)]", "\n public double FxToGroupCurrency { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [Display(Order = 60)]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", "\n}" ] }, @@ -844,7 +867,7 @@ { "cell_type": "code", "source": [ - "public record CreditDefaultRate : KeyedRecord, IWithYearAndMonth", + "public record CreditDefaultRate : KeyedRecord, IWithYearMonthAndScenario", "\n{ ", "\n [Required]", "\n [IdentityProperty]", @@ -871,6 +894,11 @@ "\n [Conversion(typeof(PrimitiveArrayConverter))]", "\n [Display(Order = 40)]", "\n public double[] Values { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [Display(Order = 50)]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", "\n}" ] }, @@ -890,7 +918,7 @@ { "cell_type": "code", "source": [ - "public record YieldCurve : KeyedRecord, IWithYearAndMonth", + "public record YieldCurve : KeyedRecord, IWithYearMonthAndScenario", "\n{ ", "\n [Required]", "\n [IdentityProperty]", @@ -916,6 +944,7 @@ "\n", "\n [IdentityProperty]", "\n [Display(Order = 35)]", + "\n [Dimension(typeof(Scenario))]", "\n public string Scenario { get; init; }", "\n", "\n [Conversion(typeof(PrimitiveArrayConverter))]", @@ -935,7 +964,7 @@ { "cell_type": "code", "source": [ - "public record PartnerRating : KeyedRecord, IWithYearAndMonth", + "public record PartnerRating : KeyedRecord, IWithYearMonthAndScenario", "\n{ ", "\n [Required]", "\n [IdentityProperty]", @@ -963,6 +992,11 @@ "\n [Range(1, 12, ErrorMessage = \"Value for {0} must be between {1} and {2}.\")]", "\n [Display(Order = 40)]", "\n public int Month { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [Display(Order = 50)]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", "\n}" ] }, @@ -1202,7 +1236,7 @@ { "cell_type": "code", "source": [ - "public record DataNodeState : KeyedRecord, IPartitioned, IWithYearAndMonth", + "public record DataNodeState : KeyedRecord, IPartitioned, IWithYearMonthAndScenario", "\n{", "\n [NotVisible]", "\n [PartitionKey(typeof(PartitionByReportingNode))]", @@ -1235,6 +1269,11 @@ "\n [Display(Order = 40)]", "\n [DefaultValue(State.Active)]", "\n public State State { get; init; } = State.Active;", + "\n", + "\n [IdentityProperty]", + "\n [Display(Order = 50)]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", "\n}" ] }, @@ -1254,7 +1293,7 @@ { "cell_type": "code", "source": [ - "public record DataNodeParameter : KeyedRecord, IPartitioned, IWithYearAndMonth", + "public record DataNodeParameter : KeyedRecord, IPartitioned, IWithYearMonthAndScenario", "\n{", "\n [NotVisible]", "\n [PartitionKey(typeof(PartitionByReportingNode))]", @@ -1282,6 +1321,11 @@ "\n [Display(Order = 10)]", "\n [Dimension(typeof(GroupOfContract))]", "\n public string DataNode { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [Display(Order = 40)]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", "\n}" ] }, @@ -1340,7 +1384,7 @@ "\n public State PreviousState { get; init; }", "\n ", "\n public bool IsReinsurance { get; init; }", - "\n ", + "\n public string Scenario { get; init; }", "\n public DataNodeData(){}", "\n}" ] diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 8dc36adc..00ccbba0 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -44,7 +44,8 @@ { "cell_type": "code", "source": [ - "#!import \"../Utils/ImportCalculationMethods\"", + "#!import \"../Utils/EqualityComparers\"", + "\n#!import \"../Utils/ImportCalculationMethods\"", "\n#!import \"../Utils/Queries\"" ] }, @@ -250,18 +251,34 @@ "\n //Variables", "\n var rawVariables = parsedRawVariables.Concat(openingRawVariables)", "\n .Concat(await querySource.Query()", - "\n .Where(rv => rv.Partition == TargetPartition)", - "\n .Where(rv => primaryScopeFromLinkedReinsurance.Contains(rv.DataNode))", - "\n .ToArrayAsync());", - "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", + "\n .Where(rv => rv.Partition == TargetPartition)", + "\n .Where(rv => primaryScopeFromLinkedReinsurance.Contains(rv.DataNode)).ToArrayAsync()); ", "\n ", "\n var ifrsVariables = parsedIfrsVariables.Concat(openingIfrsVariables)", - "\n .Concat(await querySource.Query()", - "\n .Where(iv => iv.Partition == TargetPartition && !(iv.AocType == AocTypes.BOP && iv.Novelty == Novelties.I))", - "\n .Where(iv => primaryScopeFromParsedVariables.Contains(iv.DataNode) && !EstimateTypesByImportFormat[ImportFormat].Contains(iv.EstimateType) ", - "\n || primaryScopeFromLinkedReinsurance.Contains(iv.DataNode) ", - "\n || secondaryScope.Contains(iv.DataNode))", - "\n .ToArrayAsync());", + "\n .Concat(await querySource.Query()", + "\n .Where(iv => iv.Partition == TargetPartition && !(iv.AocType == AocTypes.BOP && iv.Novelty == Novelties.I))", + "\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", + "\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 rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", + "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n }", + "\n", + "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", "\n IfrsVariablesByImportIdentity = (IDictionary>)ifrsVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", "\n }", "\n ", @@ -301,6 +318,7 @@ "\n ? ct.PeriodType : PeriodType.EndOfPeriod;", "\n", "\n //Variables and Cashflows", + "\n ", "\n public IEnumerable GetRawVariables(string dataNode) => RawVariablesByImportIdentity.TryGetValue(dataNode, out var variableCollection) ? variableCollection : Enumerable.Empty();", "\n public IEnumerable GetIfrsVariables(string dataNode) => IfrsVariablesByImportIdentity.TryGetValue(dataNode, out var variableCollection) ? variableCollection : Enumerable.Empty();", "\n ", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index d8c0a918..d115059d 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -331,18 +331,6 @@ "\nThe new Aoc Configurations are created with the same order of the Aoc Types. " ] }, - { - "cell_type": "code", - "source": [ - "" - ] - }, - { - "cell_type": "code", - "source": [ - "" - ] - }, { "cell_type": "code", "source": [ @@ -914,7 +902,7 @@ "\n ", "\n var parsingLog = await ParseCashflowsToWorkspaceAsync(dataSet, args);", "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", - "\n ", + "\n ", "\n var storage = new ImportStorage(args, DataSource, Workspace);", "\n await storage.InitializeAsync();", "\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);", diff --git a/ifrs17/Report/ReportConfigurationAndUtils.ipynb b/ifrs17/Report/ReportConfigurationAndUtils.ipynb index 6b2cbab2..28b0acd6 100644 --- a/ifrs17/Report/ReportConfigurationAndUtils.ipynb +++ b/ifrs17/Report/ReportConfigurationAndUtils.ipynb @@ -26,7 +26,8 @@ { "cell_type": "code", "source": [ - "#!import \"../Utils/Queries\"" + "#!import \"../Utils/EqualityComparers\"", + "\n#!import \"../Utils/Queries\"" ] }, { @@ -91,11 +92,12 @@ { "cell_type": "code", "source": [ - "public static async Task> QueryReportVariablesAsync(this IWorkspace workspace, (int Year, int Month, string ReportingNode, string Scenario) args ) {", - "\n ", + "public static async Task QueryReportVariablesSingleScenarioAsync(this IWorkspace workspace, (int Year, int Month, string ReportingNode, string Scenario) args ) {", + "\n", + "\n await workspace.Partition.SetAsync(new { ReportingNode = args.ReportingNode, Scenario = (string)null}); // TODO: Scenario from args + relaxed query ", "\n await workspace.Partition.SetAsync(new { ReportingNode = args.ReportingNode, Scenario = args.Scenario, Year = args.Year, Month = args.Month });", "\n ", - "\n return await workspace.Query()", + "\n var reportVariables = await workspace.Query()", "\n .Join(workspace.Query(),", "\n dn => dn.SystemName,", "\n iv => iv.DataNode,", @@ -134,6 +136,22 @@ "\n ", "\n Value = iv.Value })", "\n .ToArrayAsync();", + "\n", + "\n await workspace.Partition.SetAsync(null);", + "\n await workspace.Partition.SetAsync(null);", + "\n return reportVariables;", + "\n}" + ] + }, + { + "cell_type": "code", + "source": [ + "public static async Task> QueryReportVariablesAsync(this IWorkspace workspace, (int Year, int Month, string ReportingNode, string Scenario) args ) {", + "\n ReportVariable[] reportVariables = new ReportVariable[0];", + "\n if(args.Scenario != null) ", + "\n reportVariables = (await workspace.QueryReportVariablesSingleScenarioAsync((args.Year, args.Month, args.ReportingNode, null)));", + "\n return (await workspace.QueryReportVariablesSingleScenarioAsync((args.Year, args.Month, args.ReportingNode, args.Scenario)))", + "\n .Union(reportVariables.Select(x => x with {Scenario = args.Scenario}), EqualityComparer.Instance).ToArray();", "\n}" ] }, diff --git a/ifrs17/Report/ReportStorage.ipynb b/ifrs17/Report/ReportStorage.ipynb index 0c61fe1a..13525d14 100644 --- a/ifrs17/Report/ReportStorage.ipynb +++ b/ifrs17/Report/ReportStorage.ipynb @@ -141,7 +141,7 @@ "\n }", "\n ", "\n // Variables", - "\n foreach(var rn in GetLeaves(reportingNode)) { ", + "\n foreach(var rn in GetLeaves(reportingNode)) {", "\n if(!variablesDictionary.TryGetValue((period, rn, scenario), out var variablesByIdentity)) {", "\n variablesByIdentity = (await workspace.QueryReportVariablesAsync((period.year, period.month, rn, scenario)))", "\n .ToDictionaryGrouped(x => new ReportIdentity {", @@ -159,7 +159,7 @@ "\n x => x.ToDictionaryGrouped(y => y.EstimateType,", "\n y => y.ToArray().ToDataCube()));", "\n ", - "\n variablesDictionary.Add((period, rn, scenario), variablesByIdentity);", + "\n variablesDictionary.Add((period, rn, scenario), variablesByIdentity);", "\n }", "\n }", "\n }", diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 07990aa7..6b91461e 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -26,7 +26,8 @@ { "cell_type": "code", "source": [ - "var gic = \"DT1.1\";" + "var gic = \"DT1.1\";", + "\nvar scenario = \"MTUP\";" ] }, { @@ -45,8 +46,8 @@ "cell_type": "code", "source": [ "public async Task CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int Year, int Month) expectedCurrentPeriod, ", - "\n (int Year, int Month) expectedPreviousPeriod)", + "\n (int Year, int Month, string Scenario) expectedCurrentPeriod, ", + "\n (int Year, int Month, string Scenario) expectedPreviousPeriod)", "\n{", "\n await Workspace.UpdateAsync(testData);", "\n var eurCurrentAndPreviousYieldCurve = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Currency))[\"EUR\"];", @@ -54,10 +55,12 @@ "\n //Check Current Period", "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Year.Should().Be(expectedCurrentPeriod.Year);", "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Month.Should().Be(expectedCurrentPeriod.Month);", + "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Scenario.Should().Be(expectedCurrentPeriod.Scenario);", "\n ", "\n //Check Previous Period", "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Year.Should().Be(expectedPreviousPeriod.Year);", "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Month.Should().Be(expectedPreviousPeriod.Month);", + "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Scenario.Should().Be(expectedPreviousPeriod.Scenario);", "\n ", "\n await Workspace.DeleteAsync(Workspace.Query().ToArray());", "\n}" @@ -68,93 +71,150 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9),(2020, 9));" + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9, null),(2020, 9, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new[] { new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9 } };", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario),(2020, 9, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12), (2019, 12));" + "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12, null), (2019, 12, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6), (2020, 6));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2019, 3, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9), (2020, 9));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2020, 9, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9), (2019, 9));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2019, 9, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"EUR\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12), (2019, 12));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 9}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12), (2019, 12));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 9, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6), (2019, 6));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));" + ] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly, scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2015, Month = 9},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3}};", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6), (2016, 3));" + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2015, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));" ] }, { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3}};", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", "\n", - "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6), (2016, 3));" + "\nawait CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));" ] }, { diff --git a/ifrs17/Utils/ApplicationMessage.ipynb b/ifrs17/Utils/ApplicationMessage.ipynb index e55e688c..b826668d 100644 --- a/ifrs17/Utils/ApplicationMessage.ipynb +++ b/ifrs17/Utils/ApplicationMessage.ipynb @@ -27,13 +27,8 @@ { "cell_type": "code", "source": [ - "#r \"nuget:Systemorph.Activities,1.5.5\"" - ] - }, - { - "cell_type": "code", - "source": [ - "#!import \"../Constants/Validations\"" + "#!import \"../Constants/Validations\"", + "\n#!import \"../DataModel/DataStructure\"" ] }, { @@ -115,4 +110,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/ifrs17/Utils/EqualityComparers.ipynb b/ifrs17/Utils/EqualityComparers.ipynb new file mode 100644 index 00000000..bd3021eb --- /dev/null +++ b/ifrs17/Utils/EqualityComparers.ipynb @@ -0,0 +1,139 @@ +{ + "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": [ + "

Equality Comparers

" + ] + }, + { + "cell_type": "code", + "source": [ + "#!import \"../DataModel/DataStructure\"" + ] + }, + { + "cell_type": "code", + "source": [ + "class RawVariableComparer: IEqualityComparer", + "\n{", + "\n private bool IgnoreValues;", + "\n private RawVariableComparer(bool ignoreValues)", + "\n {", + "\n IgnoreValues = ignoreValues;", + "\n }", + "\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", + "\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", + "\n public static RawVariableComparer Instance(bool ignoreValues = false)", + "\n { ", + "\n return new RawVariableComparer(ignoreValues);", + "\n }", + "\n}" + ] + }, + { + "cell_type": "code", + "source": [ + "class IfrsVariableComparer: IEqualityComparer", + "\n{", + "\n private bool IgnoreValue;", + "\n private IfrsVariableComparer(bool ignoreValue)", + "\n {", + "\n IgnoreValue = ignoreValue;", + "\n }", + "\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", + "\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", + "\n public static IfrsVariableComparer Instance(bool ignoreValue = false)", + "\n { ", + "\n return new IfrsVariableComparer(ignoreValue);", + "\n }", + "\n}" + ] + }, + { + "cell_type": "code", + "source": [ + "using System;", + "\nusing System.Collections.Generic;", + "\nusing System.Diagnostics; ", + "\nusing System.Linq;", + "\nusing System.Linq.Expressions;", + "\nusing System.Reflection;", + "\nusing System.Threading;", + "\n//using Systemorph.Domain;", + "\n//using Systemorph.Utils.Reflection;", + "\nusing static Systemorph.Vertex.Equality.IdentityPropertyExtensions;" + ] + }, + { + "cell_type": "code", + "source": [ + "class EqualityComparer : IEqualityComparer", + "\n{", + "\n private static readonly System.Reflection.PropertyInfo[] IdentityProperties = typeof(T).GetIdentityProperties().ToArray();", + "\n private static Func compiledEqualityFunction;", + "\n", + "\n private EqualityComparer() {", + "\n compiledEqualityFunction = GetEqualityFunction();", + "\n }", + "\n", + "\n public static readonly EqualityComparer Instance = new EqualityComparer();", + "\n", + "\n public bool Equals(T x, T y) => compiledEqualityFunction(x, y);", + "\n public int GetHashCode(T obj) => 0;", + "\n", + "\n private static Func GetEqualityFunction()", + "\n {", + "\n var prm1 = Expression.Parameter(typeof(T));", + "\n var prm2 = Expression.Parameter(typeof(T));", + "\n", + "\n // r1 == null && r2 == null", + "\n var nullConditionExpression = Expression.AndAlso(Expression.Equal(prm1, Expression.Constant(null, typeof(T))), Expression.Equal(prm2, Expression.Constant(null, typeof(T))));", + "\n // r1 != null && r2 != null", + "\n var nonNullConditionExpression = Expression.AndAlso(Expression.NotEqual(prm1, Expression.Constant(null, typeof(T))), Expression.NotEqual(prm2, Expression.Constant(null, typeof(T))));", + "\n // r1.prop1 == r2.prop1 && r1.prop2 == r2.prop2...... ", + "\n var allPropertiesEqualExpression = IdentityProperties.Select(propertyInfo => Expression.Equal(Expression.Property(prm1, propertyInfo), Expression.Property(prm2, propertyInfo))).Aggregate(Expression.AndAlso);", + "\n", + "\n var equalityExpr = Expression.OrElse(nullConditionExpression, Expression.AndAlso(nonNullConditionExpression, allPropertiesEqualExpression));", + "\n return Expression.Lambda>(equalityExpr, prm1, prm2).Compile();", + "\n }", + "\n}" + ] + }, + { + "cell_type": "code", + "source": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 88b5c1c3..83b6c1ef 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -90,14 +90,16 @@ "\n Args args,", "\n Func identityExpression,", "\n Expression> filterExpression = null ) ", - "\n where T : IWithYearAndMonth", + "\n where T : IWithYearMonthAndScenario", "\n{", "\n return (await querySource.LoadParameterAsync(args.Year, args.Month, filterExpression))", - "\n .GroupBy(identityExpression)", - "\n .Select(y => y.OrderByDescending(x => x.Year)", - "\n .ThenByDescending(x => x.Month)", - "\n .FirstOrDefault())", - "\n .ToDictionary(identityExpression);", + "\n .Where(x => x.Scenario == args.Scenario || x.Scenario == null)", + "\n .GroupBy(x => identityExpression)", + "\n .Select(x => x.OrderByDescending(y => y.Year)", + "\n .ThenByDescending(y => y.Month)", + "\n .ThenByDescending(y => y.Scenario)", + "\n .FirstOrDefault())", + "\n .ToDictionary(identityExpression);", "\n}" ] }, @@ -109,20 +111,24 @@ "\n Args args,", "\n Func identityExpression,", "\n Expression> filterExpression = null ) ", - "\n where T : IWithYearAndMonth", + "\n where T : IWithYearMonthAndScenario", "\n{", - "\n var parameters = (await querySource.LoadParameterAsync(args.Year, args.Month, filterExpression)).GroupBy(identityExpression);", + "\n var parameters = (await querySource.LoadParameterAsync(args.Year, args.Month, filterExpression))", + "\n .Where(yc => yc.Scenario == args.Scenario || yc.Scenario == null)", + "\n .GroupBy(identityExpression);", "\n ", "\n var ret = new Dictionary>();", "\n foreach(var p in parameters)", "\n {", "\n var inner = ret.GetOrAdd(p.Key, _ => new Dictionary());", "\n", - "\n var currentCandidate = p.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).FirstOrDefault();", - "\n var previousCandidate = p.Where(x => x.Year < args.Year).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", + "\n var currentCandidate = p.Where(x => x.Year == args.Year).OrderByDescending(x => x.Month).ThenByDescending(x => x.Scenario).FirstOrDefault();", + "\n var previousCandidate = p.Where(x => x.Year < args.Year && x.Scenario == null).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", + "\n var currentCandidateBE = p.Where(x => x.Year <= args.Year && x.Scenario == null).OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault();", "\n ", "\n inner.Add(CurrentPeriod, currentCandidate != null ? currentCandidate : previousCandidate);", - "\n inner.Add(PreviousPeriod, previousCandidate != null ? previousCandidate : currentCandidate);", + "\n inner.Add(PreviousPeriod, previousCandidate != null ? previousCandidate : (currentCandidateBE != null ? currentCandidateBE : currentCandidate));", + "\n // TODO: log error if currentCandidate is null", "\n }", "\n return ret;", "\n}" @@ -150,7 +156,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};", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.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))", @@ -315,12 +321,6 @@ "\n => (await querySource.LoadAocStepConfigurationAsync(year, month))", "\n .ToDictionary(x => new AocStep(x.AocType, x.Novelty)); " ] - }, - { - "cell_type": "code", - "source": [ - "" - ] } ] } \ No newline at end of file