Skip to content

Commit

Permalink
Filter identities to compute import scopes (#348)
Browse files Browse the repository at this point in the history
* clean up AocConfig

* refactor creation of identities

* ifrs17ce

* dimension

* dimension

* scopes and tests

* clean up

* test new novelty

* remove hardcoded novelties.N

* fix reference

* AocConfiguration - remove compulsory requirements

Add use case

* clean up

* improvements

* improvements

* improve GetReleasePattern + clear CSM-LC calc for PAA

# Conflicts:
#	ifrs17/Import/5ImportScope-ToIfrsVar.ipynb

* merge issue

* wip

* fixes AMF calc and fix test

* update bm iv

* filter for null

* adjust amf from ifrsvariable

* resolve conflict

* validate missing previous period data

* pr comments
  • Loading branch information
dcolleoni authored Jul 20, 2023
1 parent 08318fb commit f8c3cb5
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions ifrs17-template/Test/IfrsVariablesTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }",
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions ifrs17-template/Test/ReimportTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\";"
],
Expand Down
7 changes: 6 additions & 1 deletion ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion ifrs17/Constants/Validations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.\",",
Expand Down
28 changes: 17 additions & 11 deletions ifrs17/Import/2ImportScope-PresentValue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,13 @@
"public interface PresentValue : IWithGetValueFromValues { ",
"\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>",
"\n builder.ForScope<PresentValue>(s => s",
"\n .WithApplicability<ComputePresentValueWithIfrsVariable>(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))",
"\n .WithApplicability<PresentValueFromDiscountedCashflow>(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)",
"\n .WithApplicability<CashflowAocStep>(x => x.Identity.Id.AocType == AocTypes.CF)",
"\n .WithApplicability<PresentValueWithInterestAccretion>(x => x.Identity.Id.AocType == AocTypes.IA)",
"\n .WithApplicability<EmptyValuesAocStep>(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<ComputePresentValueWithIfrsVariable>(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))",
"\n .WithApplicability<PresentValueFromDiscountedCashflow>(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)",
"\n .WithApplicability<CashflowAocStep>(x => x.Identity.Id.AocType == AocTypes.CF)",
"\n .WithApplicability<PresentValueWithInterestAccretion>(x => x.Identity.Id.AocType == AocTypes.IA)",
"\n .WithApplicability<EmptyValuesAocStep>(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();",
Expand Down Expand Up @@ -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": {},
Expand Down
6 changes: 3 additions & 3 deletions ifrs17/Import/3ImportScope-Actuals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"\n private double AmortizationFactor => GetScope<DiscountedAmortizationFactorForDeferrals>(Identity, o => o.WithContext(EconomicBasis)).Value;",
"\n private double AggregatedDeferrable => GetScope<PreviousAocSteps>((Identity, InputSource.Actual)).Values",
"\n .Sum(aocStep => GetScope<DeferrableActual>(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{",
Expand Down Expand Up @@ -450,7 +450,7 @@
"\n private double AmortizationFactor => GetScope<DiscountedAmortizationFactorForDeferrals>(Identity, o => o.WithContext(EconomicBasis)).Value;",
"\n private double AggregatedValue => GetScope<PreviousAocSteps>((Identity, InputSource.Cashflow)).Values",
"\n .Sum(aocStep => GetScope<DiscountedDeferrable>(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 {",
Expand Down Expand Up @@ -558,7 +558,7 @@
"\n private IEnumerable<AocStep> referenceAocSteps => GetScope<ReferenceAocStep>(Identity.Id).Values; //Reference step of AM,C is CL,C",
"\n private double referenceCashflow => referenceAocSteps.Sum(refAocStep => GetScope<NominalDeferrable>((Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.MonthlyShift)).Value);",
"\n",
"\n double NominalDeferrable.Value => -1d * referenceCashflow * GetScope<CurrentPeriodAmortizationFactor>((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value;",
"\n double NominalDeferrable.Value => Math.Abs(referenceCashflow) > Precision ? -1d * referenceCashflow * GetScope<CurrentPeriodAmortizationFactor>((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value : default;",
"\n}",
"\n",
"\npublic interface EopDeferrable : NominalDeferrable{",
Expand Down
6 changes: 3 additions & 3 deletions ifrs17/Import/4ImportScope-TechnicalMargin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"\n ",
"\n protected string estimateType => GetContext();",
"\n [NotVisible] string EconomicBasis => EconomicBases.L;",
"\n double Value => GetScope<TechnicalMarginAmountType>((Identity.DataNode, estimateType)).Values",
"\n double Value => GetScope<TechnicalMarginAmountType>((Identity.DataNode, estimateType)).Values ////TODO. PAA should use PR-Revenue and DAE-Allocated (allocated to the period)? ",
"\n .Sum(at => GetScope<PresentValue>((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +",
"\n GetScope<PresentValue>((Identity, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value;",
"\n ",
Expand Down Expand Up @@ -338,7 +338,7 @@
"\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>",
"\n builder.ForScope<TechnicalMarginForAM>(s => s.WithApplicability<TechnicalMarginForAmForPaa>(x => x.Identity.ValuationApproach == ValuationApproaches.PAA)); ",
"\n ",
"\n double TechnicalMargin.Value => -1d * AggregatedValue * GetScope<CurrentPeriodAmortizationFactor>((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value;",
"\n double TechnicalMargin.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope<CurrentPeriodAmortizationFactor>((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value : default;",
"\n}",
"\n",
"\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{",
Expand Down Expand Up @@ -769,7 +769,7 @@
"\n",
"\npublic interface LossRecoveryComponentForAm : LossRecoveryComponent{",
"\n private string economicBasis => GetScope<TechnicalMargin>(Identity).EconomicBasis;",
"\n double LossRecoveryComponent.Value => -1d * AggregatedValue * GetScope<CurrentPeriodAmortizationFactor>((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value;",
"\n double LossRecoveryComponent.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope<CurrentPeriodAmortizationFactor>((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value : default;",
"\n}",
"\n",
"\npublic interface LossRecoveryComponentForEop : LossRecoveryComponent{",
Expand Down
Loading

0 comments on commit f8c3cb5

Please sign in to comment.