diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv index 2bbd39c7..db445632 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv @@ -4,14 +4,10 @@ Month,ReportingNode,Scenario,Year @@F AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Values0 ,CU,AM,DT1.1,L,F,C,0.65623 -,,AM,DT1.2,L,F,C,1 ,CU,AM,DT1.3,L,F,C,0.65623 ,CU,AM,DT2.1,L,F,C,0.65623 -,,AM,DT2.2,L,F,C,1 ,CU,AM,DTR1.1,L,F,C,0.65623 -,,AM,DTR1.2,L,F,C,1 ,CU,AM,DTR2.1,L,F,C,0.65623 -,,AM,DTR2.2,L,F,C,1 ,CU,AM,DT3.1,L,F,C,0.65623 ,CU,AM,DT4.1,L,F,C,0.65623 ,CU,AM,DT1.4,L,F,C,0.65623 diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv index e8653719..348f71d1 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv @@ -4,14 +4,10 @@ Month,ReportingNode,Scenario,Year @@F AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Values0 ,CU,AM,DT1.1,L,F,C,0.32249 -,,AM,DT1.2,L,F,C,1 ,CU,AM,DT1.3,L,F,C,0.32249 ,CU,AM,DT2.1,L,F,C,0.32249 -,,AM,DT2.2,L,F,C,1 ,CU,AM,DTR1.1,L,F,C,0.32249 -,,AM,DTR1.2,L,F,C,1 ,CU,AM,DTR2.1,L,F,C,0.32249 -,,AM,DTR2.2,L,F,C,1 ,,AM,DT3.1,L,F,C,1 ,CU,AM,DT4.1,L,F,C,0.32249 ,CU,AM,DT1.4,L,F,C,0.32249 diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index 5506bba7..2aa378b8 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -281,9 +281,9 @@ "\n", "\n //CompareAgainstBm", "\n if(!computedVariables.Any() && bmVariables.Any())", - "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName));", + "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for: \"+reportingNode+year+month+scenario+\" and EstimateType: \" + bmTableName));", "\n if(computedVariables.Any() && !bmVariables.Any())", - "\n errorList.Add(new BenchmarkTestResult(\"Empty benchmark provided for EstimateType: \" + bmTableName));", + "\n errorList.Add(new BenchmarkTestResult(\"Empty benchmark provided for: \"+reportingNode+year+month+scenario+\" and EstimateType: \" + bmTableName));", "\n if(computedVariables.Any() && bmVariables.Any())", "\n errorList = errorList.Concat(CompareAgainstBm(errorList, bmVariables, computedVariables)).Distinct().ToList();", "\n }", @@ -428,16 +428,17 @@ "cell_type": "code", "source": [ "ProjectionCount = 5;", - "\nawait Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12_Projection.csv\")", + "\nvar activity1 = await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12_Projection.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", "\n .ExecuteAsync();", - "\nawait Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2021_3_Projection.csv\")", + "\nvar activity2 = await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2021_3_Projection.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", - "\n .ExecuteAsync();" + "\n .ExecuteAsync();", + "\n(Activity1: activity1.Status, Errors1:activity1.Errors, Activity2:activity2.Status, Errors2:activity2.Errors)" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17-template/Test/ReimportTest.ipynb b/ifrs17-template/Test/ReimportTest.ipynb index 13952d0b..0a886ea3 100644 --- a/ifrs17-template/Test/ReimportTest.ipynb +++ b/ifrs17-template/Test/ReimportTest.ipynb @@ -308,6 +308,7 @@ "\n@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20", "\nDTR1.1,PR,BE,CL,C,,0,-57.5,0,0,-57.5,0,0,-57.5,0,0,-57.5,0,0,0,0,0,0,0,0,0,0", + "\nDTR1.1,CU,P,CL,C,,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0", "\nDTR1.1,NIC,BE,CL,C,,15,15,15,15,15,15,15,15,15,15,15,15,0,0,0,0,0,0,0,0,0", "\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,0,0,0,0,0,0,0,0,0\";" ], diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index f5f92327..c0c31c3f 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -634,8 +634,13 @@ "\n@@Cashflow", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", "\nDT1.1,PR,BE,CL,C,,80,0,0,80,0,0,80,0,0,80,0,0,0,80,0,0,80,0,0,80,0,0,80,0", + "\nDT1.1,CU,P,CL,C,,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0", "\nDT1.1,NIC,BE,CL,C,,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3", - "\nDT1.1,,RA,CL,C,,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40\";" + "\nDT1.1,,RA,CL,C,,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40", + "\nDTR1.1,PR,BE,CL,C,,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0", + "\nDTR1.1,NIC,BE,CL,C,,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5", + "\nDTR1.1,CU,P,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, diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index e759d396..70075269 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -80,7 +80,8 @@ "\n ReinsuranceCoverageDataNode, DuplicateInterDataNode, DuplicateSingleDataNode, InvalidDataNode, InvalidDataNodeForOpening, InvalidCashFlowPeriodicity, MissingInterpolationMethod, InvalidInterpolationMethod, InvalidEconomicBasisDriver, InvalidReleasePattern,", "\n // Storage", "\n DataNodeNotFound, PartnerNotFound, PeriodNotFound, RatingNotFound, CreditDefaultRateNotFound, MissingPremiumAllocation, ReinsuranceCoverage, ", - "\n YieldCurveNotFound, YieldCurvePeriodNotApplicable, EconomicBasisNotFound, AccountingVariableTypeNotFound, InvalidGric, InvalidGic, ", + "\n YieldCurveNotFound, YieldCurvePeriodNotApplicable, EconomicBasisNotFound, AccountingVariableTypeNotFound, InvalidGric, InvalidGic, ReleasePatternNotFound,", + "\n MissingPreviousPeriodData,", "\n // Scopes", "\n NotSupportedAocStepReference, MultipleEoP,", "\n // Data completeness", @@ -176,6 +177,8 @@ "\n (Error.AccountingVariableTypeNotFound , 1) => $\"AccountingVariableType {s[0]} not found.\",", "\n (Error.InvalidGric , 1) => $\"Invalid Group of Reinsurance Contract {s[0]} has been requested during calculation.\",", "\n (Error.InvalidGic , 1) => $\"Invalid Group of Insurance Contract {s[0]} has been requested during calculation.\",", + "\n (Error.ReleasePatternNotFound , 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found.\",", + "\n (Error.MissingPreviousPeriodData , 3) => $\"Data for previous period (Year: {s[0]}, Month: {s[1]}) is missing for Group of contracts: {s[2]}.\",", "\n // Scopes", "\n (Error.NotSupportedAocStepReference , 1) => $\"Unsupported reference AoC Step for AoC Type {s[0]}.\",", "\n (Error.MultipleEoP , 0) => $\"Closing Balance for both Csm and Lc are computed.\",", diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 52c9d4dd..7858b533 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -520,13 +520,13 @@ "public interface PresentValue : IWithGetValueFromValues { ", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", - "\n .WithApplicability(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))", - "\n .WithApplicability(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)", - "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", - "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.IA)", - "\n .WithApplicability(x => ComputationHelper.AocTypeWithNoPv.Contains(x.Identity.Id.AocType) ||", - "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) )", - "\n );", + "\n .WithApplicability(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))", + "\n .WithApplicability(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)", + "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", + "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.IA)", + "\n .WithApplicability(x => ComputationHelper.AocStepWithNoPv.Contains(new AocStep(x.Identity.Id.AocType, x.Identity.Id.Novelty)) ||", + "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) )", + "\n );", "\n ", "\n [NotVisible][IdentityProperty][Dimension(typeof(EconomicBasis))]", "\n string EconomicBasis => GetContext();", @@ -903,10 +903,16 @@ "\npublic interface AmfFromIfrsVariable : CurrentPeriodAmortizationFactor{", "\n private double amortizationFactorForAmountType => GetStorage().GetValue(Identity.Id, Identity.AmountType, EstimateType, EconomicBasis, ", "\n Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod); //TODO shift of 0 is a valid value", - "\n double CurrentPeriodAmortizationFactor.Value => Math.Abs(amortizationFactorForAmountType) >= Precision", - "\n ? amortizationFactorForAmountType ", - "\n : GetStorage().GetValue(Identity.Id, null, EstimateType, EconomicBasis, Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", - "\n string CurrentPeriodAmortizationFactor.EffectiveAmountType => Math.Abs(amortizationFactorForAmountType) >= Precision ? Identity.AmountType : null;", + "\n ", + "\n private double amortizationFactorFromPattern => GetStorage().GetValue(Identity.Id, null, EstimateType, EconomicBasis, Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", + "\n ", + "\n private double amortizationFactorForCu => GetStorage().GetValue(Identity.Id, AmountTypes.CU, EstimateType, EconomicBasis, ", + "\n Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", + "\n", + "\n double CurrentPeriodAmortizationFactor.Value => Math.Abs(amortizationFactorForAmountType) >= Precision ? amortizationFactorForAmountType ", + "\n : Math.Abs(amortizationFactorFromPattern) >= Precision ? amortizationFactorFromPattern : amortizationFactorForCu;", + "\n string CurrentPeriodAmortizationFactor.EffectiveAmountType => Math.Abs(amortizationFactorForAmountType) >= Precision ? Identity.AmountType ", + "\n : Math.Abs(amortizationFactorFromPattern) >= Precision ? null : AmountTypes.CU;", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/3ImportScope-Actuals.ipynb b/ifrs17/Import/3ImportScope-Actuals.ipynb index 3df31969..ed072c6a 100644 --- a/ifrs17/Import/3ImportScope-Actuals.ipynb +++ b/ifrs17/Import/3ImportScope-Actuals.ipynb @@ -348,7 +348,7 @@ "\n private double AmortizationFactor => GetScope(Identity, o => o.WithContext(EconomicBasis)).Value;", "\n private double AggregatedDeferrable => GetScope((Identity, InputSource.Actual)).Values", "\n .Sum(aocStep => GetScope(Identity with {AocType = aocStep.AocType, Novelty = aocStep.Novelty}).Value);", - "\n double DeferrableActual.Value => -1d * AggregatedDeferrable * AmortizationFactor;", + "\n double DeferrableActual.Value => Math.Abs(AggregatedDeferrable) > Precision ? -1d * AggregatedDeferrable * AmortizationFactor : default;", "\n}", "\n", "\npublic interface EndOfPeriodDeferrable : DeferrableActual{", @@ -450,7 +450,7 @@ "\n private double AmortizationFactor => GetScope(Identity, o => o.WithContext(EconomicBasis)).Value;", "\n private double AggregatedValue => GetScope((Identity, InputSource.Cashflow)).Values", "\n .Sum(aocStep => GetScope(Identity with {AocType = aocStep.AocType, Novelty = aocStep.Novelty}).Value);", - "\n double DiscountedDeferrable.Value => -1d * AggregatedValue * AmortizationFactor;", + "\n double DiscountedDeferrable.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * AmortizationFactor : default;", "\n}", "\n", "\npublic interface DeferrableEoP : DiscountedDeferrable {", @@ -558,7 +558,7 @@ "\n private IEnumerable referenceAocSteps => GetScope(Identity.Id).Values; //Reference step of AM,C is CL,C", "\n private double referenceCashflow => referenceAocSteps.Sum(refAocStep => GetScope((Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.MonthlyShift)).Value);", "\n", - "\n double NominalDeferrable.Value => -1d * referenceCashflow * GetScope((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value;", + "\n double NominalDeferrable.Value => Math.Abs(referenceCashflow) > Precision ? -1d * referenceCashflow * GetScope((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value : default;", "\n}", "\n", "\npublic interface EopDeferrable : NominalDeferrable{", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index b2ca659d..34f9f1a4 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -270,7 +270,7 @@ "\n ", "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", - "\n double Value => GetScope((Identity.DataNode, estimateType)).Values", + "\n double Value => GetScope((Identity.DataNode, estimateType)).Values ////TODO. PAA should use PR-Revenue and DAE-Allocated (allocated to the period)? ", "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +", "\n GetScope((Identity, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value;", "\n ", @@ -338,7 +338,7 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.ValuationApproach == ValuationApproaches.PAA)); ", "\n ", - "\n double TechnicalMargin.Value => -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value;", + "\n double TechnicalMargin.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value : default;", "\n}", "\n", "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", @@ -769,7 +769,7 @@ "\n", "\npublic interface LossRecoveryComponentForAm : LossRecoveryComponent{", "\n private string economicBasis => GetScope(Identity).EconomicBasis;", - "\n double LossRecoveryComponent.Value => -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value;", + "\n double LossRecoveryComponent.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value : default;", "\n}", "\n", "\npublic interface LossRecoveryComponentForEop : LossRecoveryComponent{", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 4b79c555..5045632c 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -97,28 +97,36 @@ "source": [ "public interface PvToIfrsVariable: IScope", "\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 Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", + "\n builder.ForScope(s => s.WithApplicability(x => ComputationHelper.AocStepWithNoPv.Contains(new AocStep(x.Identity.AocType, x.Identity.Novelty))));", "\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 Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\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 Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition });", + "\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 Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition });", + "\n}", + "\n", + "\npublic interface EmptyPvIfrsVariable: PvToIfrsVariable{", + "\n IEnumerable PvToIfrsVariable.PvLocked => Enumerable.Empty();", + "\n IEnumerable PvToIfrsVariable.PvCurrent => Enumerable.Empty();", + "\n}", + "\n" ], "metadata": {}, "execution_count": 0, @@ -358,9 +366,12 @@ "public interface DeferrableAmortizationFactorToIfrsVariable: IScope", "\n{", "\n private string EconomicBasis => GetStorage().GetEconomicBasisDriver(Identity.DataNode);", + "\n private bool hasAmortizationStep => GetStorage().DataNodeDataBySystemName[Identity.DataNode].ValuationApproach == ValuationApproaches.PAA", + "\n ? GetScope(Identity).Deferrable.Where(iv => iv.Values != null).Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n : GetScope(Identity).DeferrableActual.Where(iv => iv.Values != null).Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision);", "\n", - "\n IEnumerable DeferrableAmFactor => (GetStorage().GetEconomicBasisDriver(Identity.DataNode), Identity.AocType) switch {", - "\n (EconomicBases.N, AocTypes.AM) => GetScope(Identity).Deferrable", + "\n IEnumerable DeferrableAmFactor => (hasAmortizationStep, GetStorage().GetEconomicBasisDriver(Identity.DataNode), Identity.AocType, GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType) switch {", + "\n (true, EconomicBases.N, AocTypes.AM, LiabilityTypes.LRC) => GetScope(Identity).Deferrable", "\n .Where(x => x.Values != null && Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) >= Precision)", "\n .Select(x => x.AccidentYear.Value).SelectMany(shift => ", "\n GetScope((Identity, AmountTypes.DAE, shift), o => o.WithContext(EconomicBases.N)).RepeatOnce() //hardcoded AmountType: DAE for pattern", @@ -374,7 +385,7 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }", "\n )),", - "\n (_, AocTypes.AM) => GetScope(Identity, o => o.WithContext(EconomicBasis)).RepeatOnce()", + "\n (true, _, AocTypes.AM, LiabilityTypes.LRC) => GetScope(Identity, o => o.WithContext(EconomicBasis)).RepeatOnce()", "\n .Select(x => new IfrsVariable{ EstimateType = EstimateTypes.F,", "\n EconomicBasis = EconomicBasis,", "\n DataNode = x.Identity.DataNode,", @@ -384,7 +395,7 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }", "\n ),", - "\n (_, _) => Enumerable.Empty(),", + "\n (_) => Enumerable.Empty(),", "\n };", "\n}" ], @@ -455,59 +466,73 @@ "source": [ "public interface TmToIfrsVariable: IScope", "\n{", + "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", + "\n builder.ForScope(s => s.WithApplicability(x => ComputationHelper.AocStepWithNoCsm.Contains(new AocStep(x.Identity.AocType, x.Identity.Novelty))));", + "\n", "\n private string economicBasis => Identity.ValuationApproach == ValuationApproaches.VFA ? EconomicBases.C : EconomicBases.L;", "\n private IEnumerable amountTypesForTm =>GetScope((Identity.DataNode, EstimateTypes.C)).Values;", - "\n private bool hasTechnicalMargin => GetStorage().GetRawVariables(Identity.DataNode).Any(x => x.EstimateType == EstimateTypes.RA || ", - "\n (x.EstimateType == EstimateTypes.BE && amountTypesForTm.Contains(x.AmountType))) || ", - "\n GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => GetTechnicalMarginEstimateType().Contains(x.EstimateType));", + "\n private bool hasTechnicalMargin => GetStorage().ImportFormat switch {", + "\n ImportFormats.Cashflow => GetStorage().GetRawVariables(Identity.DataNode).Any(x => x.EstimateType == EstimateTypes.RA || ", + "\n (x.EstimateType == EstimateTypes.BE && amountTypesForTm.Contains(x.AmountType))),", + "\n _ => GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => !GetStorage().EstimateTypesByImportFormat[ImportFormats.Actual].Contains(x.EstimateType) && ", + "\n amountTypesForTm.Contains(x.AmountType))", + "\n };", "\n", - "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM", - "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis))", - "\n .RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AmountType = x.EffectiveAmountType, //??", - "\n EconomicBasis = x.EconomicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n })", - "\n : Enumerable.Empty();", - "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || ", - "\n (Identity.ValuationApproach == ValuationApproaches.PAA && !hasTechnicalMargin )", - "\n ? Enumerable.Empty()", - "\n : GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || Identity.ValuationApproach == ValuationApproaches.PAA", + "\n ? Enumerable.Empty()", + "\n : GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n });", + "\n", + "\n IEnumerable Loss => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC ||", + "\n (Identity.ValuationApproach == ValuationApproaches.PAA && !hasTechnicalMargin )", + "\n ? Enumerable.Empty()", + "\n : Identity.IsReinsurance ", + "\n ? GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n })", + "\n : GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n });", + "\n ", + "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM && Loss.Concat(Csms).Where(x => x.Values != null).Any(x => Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n && GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LRC && ", + "\n (Identity.ValuationApproach != ValuationApproaches.PAA || hasTechnicalMargin )", + "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AmountType = x.EffectiveAmountType,", + "\n EconomicBasis = x.EconomicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n })", + "\n : Enumerable.Empty();", + "\n}", "\n", - "\n IEnumerable Loss => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC", - "\n ? Enumerable.Empty()", - "\n : Identity.IsReinsurance ", - "\n ? GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n })", - "\n : GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\npublic interface EmptyTmIfrsVariable: TmToIfrsVariable {", + "\n IEnumerable TmToIfrsVariable.Csms => Enumerable.Empty();", + "\n IEnumerable TmToIfrsVariable.Loss => Enumerable.Empty();", + "\n IEnumerable TmToIfrsVariable.AmortizationFactor => Enumerable.Empty();", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index e4df433c..6077aeed 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -256,7 +256,8 @@ "\n if(allImportScopesNotAtInceptionYear.Any()) {", "\n PreviousPeriodPartition = (await querySource.Query()", "\n .Where(p => p.ReportingNode == args.ReportingNode && p.Year == PreviousReportingPeriod.Year ", - "\n && p.Month == PreviousReportingPeriod.Month && p.Scenario == null).ToArrayAsync()).Single().Id;", + "\n && p.Month == PreviousReportingPeriod.Month && p.Scenario == null).ToArrayAsync()).SingleOrDefault()?.Id ?? ", + "\n (Guid)ApplicationMessage.Log(Error.MissingPreviousPeriodData, PreviousReportingPeriod.Year.ToString(), PreviousReportingPeriod.Month.ToString(), string.Join(\"\",allImportScopesNotAtInceptionYear));", "\n ", "\n await querySource.Partition.SetAsync(PreviousPeriodPartition);", "\n ", @@ -403,14 +404,19 @@ "\n if (patternFromCashflow.Any())", "\n return (amountType, Enumerable.Repeat(0d, patternShift).Concat(patternFromCashflow).ToArray());", "\n ", - "\n double[] patternFromParameter = Enumerable.Empty().ToArray();", - "\n if(!SingleDataNodeParametersByGoc.TryGetValue(identity.DataNode, out var dataNodeParameterByPeriod))", - "\n return (null, patternFromParameter);", + "\n if(SingleDataNodeParametersByGoc.TryGetValue(identity.DataNode, out var dataNodeParameterByPeriod) && dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern != null){", + "\n var annualCohort = DataNodeDataBySystemName[identity.DataNode].AnnualCohort;", + "\n var skipMonthsToCurrentReportingPeriod = MonthInAYear * (CurrentReportingPeriod.Year - annualCohort);", + "\n var monthlyPattern = dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern.Interpolate(dataNodeParameterByPeriod[CurrentPeriod].CashFlowPeriodicity, dataNodeParameterByPeriod[CurrentPeriod].InterpolationMethod);", + "\n return (null, Enumerable.Repeat(0d, patternShift).Concat(monthlyPattern.Normalize()).Skip(skipMonthsToCurrentReportingPeriod).ToArray());", + "\n }", + "\n", + "\n var patternFromCoverageUnits = GetValues(identity with {AocType = AocTypes.CL, Novelty = Novelties.C}, AmountTypes.CU, EstimateTypes.P, (int?)null);", + "\n if (patternFromCoverageUnits.Any())", + "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n var annualCohort = DataNodeDataBySystemName[identity.DataNode].AnnualCohort;", - "\n var skipMonthsToCurrentReportingPeriod = MonthInAYear * (CurrentReportingPeriod.Year - annualCohort);", - "\n var monthlyPattern = dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern.Interpolate(dataNodeParameterByPeriod[CurrentPeriod].CashFlowPeriodicity, dataNodeParameterByPeriod[CurrentPeriod].InterpolationMethod);", - "\n return (null, Enumerable.Repeat(0d, patternShift).Concat(monthlyPattern.Normalize()).Skip(skipMonthsToCurrentReportingPeriod).ToArray());", + "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ", "\n public double GetPremiumAllocationFactor(ImportIdentity id) => ", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index c35802d7..66ec8b69 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1706,7 +1706,7 @@ "\n // Checking if there are inconsistencies in the TechnicalMarginEstimateTypes --> double entries in the steps where we expect to have unique values", "\n var invalidVariables = await workspace.Query()", "\n .Where(iv => parsingStorage.TechnicalMarginEstimateTypes.Contains(iv.EstimateType))", - "\n .Where(iv => iv.AocType == AocTypes.BOP || iv.AocType == AocTypes.EOP || iv.AocType == AocTypes.AM || iv.AocType == AocTypes.EA)", + "\n .Where(iv => GetAocTypeWithoutCsmSwitch().Contains(iv.AocType))", "\n .GroupBy(iv => new {iv.DataNode, iv.AocType, iv.Novelty})", "\n .Where(g => g.Count() > 1)", "\n .Select(g => g.Key)", diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 3407c03e..e6daa007 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -252,6 +252,24 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Extend Parsed Raw Variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task ExtendParsedVariables (this IWorkspace workspace, Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache) {}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -356,7 +374,7 @@ { "cell_type": "markdown", "source": [ - "## Extend Parsed Variables" + "## Simple Value and Opening Importer" ], "metadata": {}, "execution_count": 0, @@ -365,7 +383,7 @@ { "cell_type": "code", "source": [ - "public static async Task ExtendParsedVariables (this IWorkspace workspace, Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache) {}" + "public static HashSet GetAocTypeWithoutCsmSwitch() => new []{AocTypes.BOP, AocTypes.EOP, AocTypes.AM, AocTypes.EA}.ToHashSet();" ], "metadata": {}, "execution_count": 0, @@ -374,7 +392,7 @@ { "cell_type": "markdown", "source": [ - "# Helper variables used in calculation", + "# Helper variables used in import calculation", "\n", "\nVariables defined here and used in the calculation:", "\n- AocTypeWithNoPv : used in [Present Value](../Import/2ImportScope-PresentValue#present-value-1) to trigger no calculation for some AoC Type.", @@ -388,7 +406,8 @@ "cell_type": "code", "source": [ "public static class ComputationHelper{", - "\n public static string [] AocTypeWithNoPv = new string[]{AocTypes.BOP, AocTypes.EA, AocTypes.AM, AocTypes.RCU};", + "\n public static HashSet AocStepWithNoPv = new AocStep[]{new AocStep(AocTypes.EA, Novelties.C), new AocStep(AocTypes.AM, Novelties.C), new AocStep(AocTypes.RCU, Novelties.I),}.ToHashSet();", + "\n public static HashSet AocStepWithNoCsm = new AocStep[]{new AocStep(AocTypes.CF, Novelties.C),new AocStep(AocTypes.WO, Novelties.C)}.ToHashSet();", "\n public static Dictionary> ReferenceAocSteps => new Dictionary>()", "\n {", "\n {new AocStep(AocTypes.EA ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CF,Novelties.C)}},",