From b8121e1102c4f24898272738f3689161a4e03d2d Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Thu, 31 Aug 2023 13:53:43 +0200 Subject: [PATCH 01/12] 1st attempt --- ifrs17/Constants/Enums.ipynb | 2 +- ifrs17/Import/2ImportScope-PresentValue.ipynb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ifrs17/Constants/Enums.ipynb b/ifrs17/Constants/Enums.ipynb index 7046c0ca..0c2716f4 100644 --- a/ifrs17/Constants/Enums.ipynb +++ b/ifrs17/Constants/Enums.ipynb @@ -117,7 +117,7 @@ { "cell_type": "code", "source": [ - "public enum ValuationPeriod { NotApplicable, BeginningOfPeriod, MidOfPeriod, Delta, EndOfPeriod }" + "public enum ValuationPeriod { NotApplicable, BeginningOfPeriod, MidOfPeriod, Delta, FullDelta, EndOfPeriod }" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 65f4017d..d348e20b 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -169,13 +169,13 @@ "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if it is NOT CL AND NOT EOP AND", "\n x.Identity.Id.Novelty != Novelties.I && // if it is NOT inforce", "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", - "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (LRC OR LIC with AY < than projected FY)", + "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it (has AY and is LIC with AY < than projected FY)", "\n )", "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", "\n x.Identity.Id.Novelty == Novelties.I && // if it is inforce", "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", - "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (LIC AND AY is >= than projected FY)", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", "\n )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", @@ -385,6 +385,7 @@ "\n\\text{PV}_{S} ~, & \\text{if Valuation Period is Beginning of Period} \\\\", "\n\\text{PV}_{S+TS/2 -1} ~, & \\text{if Valuation Period is Mid of Period} \\\\", "\n\\sum_{i=S}^{S + TS - 1}\\text{PV }_{i} ~, & \\text{if Valuation Period is Delta} \\\\", + "\n\\sum_{i=S}^{\\infty}\\text{PV }_{i} ~, & \\text{if Valuation Period is Full Delta} \\\\", "\n\\text{PV}_{S + TS} ~, & \\text{if Valuation Period is End of Period} \\\\", "\n\\end{array}", "\n\\right.", @@ -414,6 +415,7 @@ "\n ValuationPeriod.BeginningOfPeriod => Values.ElementAtOrDefault(shift),", "\n ValuationPeriod.MidOfPeriod => Values.ElementAtOrDefault(shift + Convert.ToInt32(Math.Round(timeStep / 2d, MidpointRounding.AwayFromZero)) - 1),", "\n ValuationPeriod.Delta => Values.Skip(shift).Take(timeStep).Sum(),", + "\n ValuationPeriod.FullDelta => Values.Skip(shift).Sum(),", "\n ValuationPeriod.EndOfPeriod => Values.ElementAtOrDefault(shift + timeStep),", "\n ValuationPeriod.NotApplicable => default", "\n };", @@ -573,6 +575,7 @@ "\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 && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\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)) ||", @@ -597,6 +600,14 @@ "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", "\n", + "\npublic interface CashflowAocStepLrcWithAccidentYear : PresentValue {", + "\n double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString());", + "\n [NotVisible] double[] PresentValue.Values => MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod))", + "\n ? GetScope(Identity).Values", + "\n : Enumerable.Empty().ToArray();", + "\n ", + "\n}", + "\n", "\npublic interface CashflowAocStep : PresentValue {", "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", From 0b872b4beda2eb250372ddf859643b115d66b4cb Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Fri, 1 Sep 2023 10:44:58 +0200 Subject: [PATCH 02/12] fixing CL C --- ifrs17/Import/2ImportScope-PresentValue.ipynb | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index d348e20b..20e23561 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -168,15 +168,20 @@ "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if it is NOT CL AND NOT EOP AND", "\n x.Identity.Id.Novelty != Novelties.I && // if it is NOT inforce", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it (has AY and is LIC with AY < than projected FY)", "\n )", "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", "\n x.Identity.Id.Novelty == Novelties.I && // if it is inforce", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", "\n )", + "\n .WithApplicability(x =>", + "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 Year AND", + "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", "\n );", @@ -406,8 +411,10 @@ "public interface IWithGetValueFromValues : IScope<(ImportIdentity Id, string AmountType, string EstimateType, int? AccidentYear), ImportStorage>", "\n{", "\n private int shift => GetStorage().GetShift(Identity.Id.ProjectionPeriod);", - "\n private int timeStep => GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", - "\n ", + "\n private int timeStep => GetStorage().DataNodeDataBySystemName[Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && Identity.AccidentYear.HasValue", + "\n ? int.MaxValue", + "\n : GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", + "\n", "\n public double GetValueFromValues(double[] Values, string overrideValuationPeriod = null)", "\n {", "\n var valuationPeriod = Enum.TryParse(overrideValuationPeriod, out ValuationPeriod ret) ? ret : GetStorage().GetValuationPeriod(Identity.Id);", @@ -575,7 +582,7 @@ "\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 && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", + "\n //.WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\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)) ||", @@ -600,13 +607,12 @@ "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", "\n", - "\npublic interface CashflowAocStepLrcWithAccidentYear : PresentValue {", - "\n double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString());", - "\n [NotVisible] double[] PresentValue.Values => MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod))", - "\n ? GetScope(Identity).Values", - "\n : Enumerable.Empty().ToArray();", - "\n ", - "\n}", + "\n// public interface CashflowAocStepLrcWithAccidentYear : PresentValue {", + "\n// double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString());", + "\n// [NotVisible] double[] PresentValue.Values => MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod))", + "\n// ? GetScope(Identity).Values", + "\n// : Enumerable.Empty().ToArray();", + "\n// }", "\n", "\npublic interface CashflowAocStep : PresentValue {", "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", From afb115822605d9152774e02c904956292872e748 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Fri, 1 Sep 2023 18:34:44 +0200 Subject: [PATCH 03/12] wip --- .../NominalCashflows_CH_2020_12_AyLRC.csv | 21 ++++++ .../EvaluateImportScopes.ipynb | 66 ++++++++++++------- ifrs17/Import/2ImportScope-PresentValue.ipynb | 64 ++++++++++++++++-- .../Import/4ImportScope-TechnicalMargin.ipynb | 16 ++--- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 19 +++--- ifrs17/Import/ImportStorage.ipynb | 7 +- 6 files changed, 147 insertions(+), 46 deletions(-) create mode 100644 ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv diff --git a/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv b/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv new file mode 100644 index 00000000..39b966cb --- /dev/null +++ b/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv @@ -0,0 +1,21 @@ +@@Main,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +ReportingNode,Year,Month,Scenario,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +CH,2020,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +DataNode,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,Values24,Values25,Values26,Values27,Values28,Values29,Values30,Values31,Values32,Values33,Values34,Values35 +DT1.1,NIC,BE,BOP,N,2020,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, +DT1.1,NIC,BE,CL,C,2020,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +DT1.1,NIC,BE,BOP,N,2021,0,0,0,0,0,0,0,0,0,0,0,0,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 +DT1.1,NIC,BE,CL,C,2021,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,,,,,,,,,,,,,,,,, +DT1.1,PR,BE,BOP,N,,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 +DT1.1,PR,BE,CL,C,,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 +DT1.1,,RA,BOP,N,,-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,,,,,,,,,,,, +DT1.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,,,,,,,,,,,, +DT1.1,CU,P,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,,,,,,,,,,,, +DT1.2,NIC,BE,BOP,N,2020,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, +DT1.2,,RA,BOP,N,2020,-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,,,,,,,,,,,, +DT1.2,NIC,BE,CL,C,2020,0,0,0,0,0,0,0,0,0,0,0,0,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, +DT1.2,CU,P,CL,C,2020,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3,,,,,,,,,,,, +DT1.2,,RA,CL,C,2020,-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,,,,,,,,,,,, +DT1.2,NIC,BE,BOP,N,2021,0,0,0,0,0,0,0,0,0,0,0,0,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,,,,,,,,,,,, +DT1.2,NIC,BE,CL,C,2021,0,0,0,0,0,0,0,0,0,0,0,0,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,,,,,,,,,,,, diff --git a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb index 09cabff5..a52dbc16 100644 --- a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb +++ b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb @@ -88,7 +88,7 @@ { "cell_type": "code", "source": [ - "await Import.FromFile(\"../../Files/TransactionalData/NominalCashflowsPAA_CH_2020_12.csv\")", + "await Import.FromFile(\"../../Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", @@ -256,7 +256,10 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.CumulatedNominal).ToArray();" + "Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = 0}), storage).ToScopes().SelectMany(x => x.PvLocked.Concat(x.PvCurrent)).ToArray()", + "\n.Where(x => x.EconomicBasis==\"L\" && x.Values.Any(y => Math.Abs(y)> Precision) && x.DataNode == \"DT1.1\" && new[]{\"PR\",\"NIC\"}.Contains(x.AmountType))", + "\n", + "\n.Where(x=> x.AmountType==\"NIC\")//.Aggregate()" ], "metadata": {}, "execution_count": 0, @@ -265,7 +268,8 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.RaCurrent.Concat(x.RaLocked)).ToArray();" + "Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = 1}), storage).ToScopes().SelectMany(x => x.PvLocked.Concat(x.PvCurrent)).ToArray()", + "\n.Where(x => x.EconomicBasis==\"L\" && x.Values != null && x.Values.Any(y => Math.Abs(y)> Precision) && x.DataNode == \"DT1.1\" && new[]{\"PR\",\"NIC\"}.Contains(x.AmountType))" ], "metadata": {}, "execution_count": 0, @@ -274,7 +278,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Actual.Concat(x.AdvanceActual).Concat(x.OverdueActual)).ToArray();" + "" ], "metadata": {}, "execution_count": 0, @@ -283,7 +287,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Deferrable).ToArray();" + "" ], "metadata": {}, "execution_count": 0, @@ -292,7 +296,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.BeEAForPremium.Concat(x.ActEAForPremium)).ToArray();" + "" ], "metadata": {}, "execution_count": 0, @@ -301,7 +305,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.AmortizationFactor.Concat(x.Csms).Concat(x.Loss)).ToArray();" + "" ], "metadata": {}, "execution_count": 0, @@ -310,16 +314,16 @@ { "cell_type": "code", "source": [ - "" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.CumulatedNominal).ToArray();" ], "metadata": {}, "execution_count": 0, "outputs": [] }, { - "cell_type": "markdown", + "cell_type": "code", "source": [ - "# Temporary test of DAC for PAA" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.RaCurrent.Concat(x.RaLocked)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -328,16 +332,7 @@ { "cell_type": "code", "source": [ - "var iv = Enumerable.Range(0,5).SelectMany(p=>", - "\n Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod=p}), storage)", - "\n .ToScopes().SelectMany(x => x.Deferrable))", - "\n.AggregateProjections().Where(x => x.Values.Any(v => Math.Abs(v) > Precision ))", - "\n.ToArray();", - "\n", - "\nvar eops= iv.Where(x => x.AocType == \"EOP\");", - "\nvar ams = iv.Where(x => x.AocType == \"AM\" && x.EstimateType == \"DA\");", - "\n", - "\niv" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Actual.Concat(x.AdvanceActual).Concat(x.OverdueActual)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -346,9 +341,34 @@ { "cell_type": "code", "source": [ - "//Testing", - "\n(Math.Abs(eops.Single(x => x.AccidentYear == 0).Values.First() - 647.5)< Precision, Math.Abs(eops.Single(x => x.AccidentYear == 2).Values.First() - 918.125)< Precision, ", - "\nMath.Abs(ams.Single(x => x.AccidentYear == 0).Values.First() - -352.5)< Precision, Math.Abs(ams.Single(x => x.AccidentYear == 2).Values.First() - -381.87499999999994)< Precision)" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Deferrable).ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.BeEAForPremium.Concat(x.ActEAForPremium)).ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.AmortizationFactor.Concat(x.Csms).Concat(x.Loss)).ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 20e23561..7db7e08d 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -177,11 +177,11 @@ "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", "\n )", - "\n .WithApplicability(x =>", - "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 Year AND", - "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", - "\n )", + "\n // .WithApplicability(x =>", + "\n // x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", + "\n // x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 //&& // if it is projection == 0 Year AND", + "\n // //(MonthInAYear * x.Identity.AccidentYear < (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // AY == CurrentReportingYear + ProjectionShift", + "\n // )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", "\n );", @@ -636,6 +636,60 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## PV by Accident Year" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface PvOverAy : IScope<(ImportIdentity Id, string AmountType, string EstimateType), ImportStorage>", + "\n{ ", + "\n [IdentityProperty][NotVisible][Dimension(typeof(EconomicBasis))]", + "\n string EconomicBasis => GetContext();", + "\n ", + "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.Id.DataNode, Identity.Id.ProjectionPeriod).ToArray(); ", + "\n ", + "\n [NotVisible]", + "\n Dictionary<(string,string,int?),double> PresentValues => accidentYears.ToDictionary(", + "\n ay => (Identity.AmountType, Identity.EstimateType, ay),", + "\n ay => GetScope((Identity.Id, Identity.AmountType, Identity.EstimateType, ay), o => o.WithContext(EconomicBasis)).Value", + "\n ); //Dictionary is not the right structure as I would need an other ToDictionary in MyPvLocked", + "\n double Value => PresentValues.Sum(kvp => kvp.Value);", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface MyPvLocked : IScope", + "\n{ ", + "\n [IdentityProperty][NotVisible][Dimension(typeof(EconomicBasis))]", + "\n string EconomicBasis => EconomicBases.L;", + "\n ", + "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", + "\n string EstimateType => EstimateTypes.BE;", + "\n ", + "\n [NotVisible]", + "\n Dictionary<(string,string,int?),double> PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);", + "\n ", + "\n //double Value => PresentValues.Aggregate().Value;", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index f7bd8d39..7ebff638 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -280,8 +280,8 @@ "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", "\n double Value => GetScope((Identity, estimateType)).Values", - "\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 .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value;", "\n ", "\n double AggregatedValue => GetScope((Identity, InputSource.Cashflow)).Values", "\n .Sum(aoc => GetScope(Identity with {AocType = aoc.AocType, Novelty = aoc.Novelty}).Value);", @@ -294,8 +294,8 @@ "\npublic interface TechnicalMarginForPaa : TechnicalMargin{", "\n [NotVisible] string TechnicalMargin.EconomicBasis => EconomicBases.C;", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\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 .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value +", "\n GetScope(Identity).Value + GetScope(Identity).Value;", "\n}", "\n", @@ -330,10 +330,10 @@ "\n .Sum(n => GetScope(Identity with {AocType = referenceAocType, Novelty = n}, o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope(Identity with {AocType = referenceAocType, Novelty = Novelties.C}).Value;", "\n protected double deferrable => GetStorage().GetDeferrableExpenses().Sum(d =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, d, EstimateTypes.A, (int?)null)).Value);", "\n protected double investmentClaims => GetStorage().GetInvestmentClaims().Sum(ic =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, ic, EstimateTypes.A, (int?)null)).Value);", "\n ", "\n double TechnicalMargin.Value => premiums + deferrable + investmentClaims;", @@ -354,8 +354,8 @@ "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", "\n private IEnumerable novelties => GetStorage().GetNovelties(AocTypes.CF).Where(novelty => novelty != Novelties.C);", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value + ", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value));", + "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value + ", + "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value));", "\n//+ Revenue AM + Deferral AM", "\n", "\n}", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index fcf8696d..54c143b3 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -100,16 +100,17 @@ "\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 PvLocked => GetScope(Identity).PresentValues.Select(x => ", + "\n IEnumerable PvLocked => GetScope(Identity).RepeatOnce().SelectMany(x =>", + "\n x.PresentValues.Select(kvp => ", "\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 EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = kvp.Key.Item3,", + "\n AmountType = kvp.Key.Item1,", + "\n Values = SetProjectionValue(kvp.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition }));", "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", "\n EstimateType = x.Identity.EstimateType, ", diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 7fb36376..27df6148 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -366,7 +366,12 @@ "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", "\n ", "\n //Accident years", - "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", + "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) { ", + "\n if(!DataNodeDataBySystemName.TryGetValue(dataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, dataNode);", + "\n if(dataNodeData.LiabilityType == LiabilityTypes.LIC)", + "\n return AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", + "\n return AccidentYearsByDataNode.TryGetValue(dataNode, out var ret) ? ret : new int?[] { default };", + "\n }", "\n ", "\n //Parameters", "\n public double GetNonPerformanceRiskRate (ImportIdentity identity, string cdrBasis)", From 69fded566d169d39799b8d7663e76a73d4353a2b Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Wed, 6 Sep 2023 22:34:23 +0200 Subject: [PATCH 04/12] Working version, to be cleaned-up and reviewed --- ifrs17/Import/2ImportScope-PresentValue.ipynb | 28 +++++++++++++++---- ifrs17/Import/ImportStorage.ipynb | 5 +++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 7db7e08d..ca2b7968 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -168,20 +168,30 @@ "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if it is NOT CL AND NOT EOP AND", "\n x.Identity.Id.Novelty != Novelties.I && // if it is NOT inforce", + "\n //x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LIC && // if it is LIC", "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it (has AY and is LIC with AY < than projected FY)", "\n )", "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", "\n x.Identity.Id.Novelty == Novelties.I && // if it is inforce", + "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LIC && // if it is LIC", "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", "\n )", - "\n // .WithApplicability(x =>", - "\n // x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", - "\n // x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 //&& // if it is projection == 0 Year AND", - "\n // //(MonthInAYear * x.Identity.AccidentYear < (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // AY == CurrentReportingYear + ProjectionShift", - "\n // )", + "\n .WithApplicability(x =>", + "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", + "\n (x.Identity.Id.Novelty != Novelties.I && x.Identity.Id.Novelty != Novelties.C) && // if it is NOT inforce", + "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && // if it is LRC", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n )", + "\n .WithApplicability(x =>", + "\n (x.Identity.Id.AocType == AocTypes.CF) && ", + "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 Year AND", + "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", "\n );", @@ -411,7 +421,7 @@ "public interface IWithGetValueFromValues : IScope<(ImportIdentity Id, string AmountType, string EstimateType, int? AccidentYear), ImportStorage>", "\n{", "\n private int shift => GetStorage().GetShift(Identity.Id.ProjectionPeriod);", - "\n private int timeStep => GetStorage().DataNodeDataBySystemName[Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && Identity.AccidentYear.HasValue", + "\n private int timeStep => GetStorage().DataNodeDataBySystemName[Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && Identity.AccidentYear.HasValue && (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", "\n ? int.MaxValue", "\n : GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", "\n", @@ -581,6 +591,7 @@ "\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.EOP && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\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 && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", @@ -603,6 +614,11 @@ "\n double[] PresentValue.Values => Enumerable.Empty().ToArray();", "\n}", "\n", + "\n// public interface PresentValueFromDiscountedCashflowWithAccidentYear : PresentValue {", + "\n// [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", + "\n// double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString()); ", + "\n// }", + "\n", "\npublic interface PresentValueFromDiscountedCashflow : PresentValue {", "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 27df6148..b8d32d68 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -366,6 +366,9 @@ "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", "\n ", "\n //Accident years", + "\n //public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", + "\n", + "\n", "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) { ", "\n if(!DataNodeDataBySystemName.TryGetValue(dataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, dataNode);", "\n if(dataNodeData.LiabilityType == LiabilityTypes.LIC)", @@ -414,7 +417,7 @@ "\n if (patternFromCoverageUnits.Any())", "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n //ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ", From b5a78f6dcdf0f89de4e56216d28b4c489b14baf2 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Thu, 7 Sep 2023 16:10:01 +0200 Subject: [PATCH 05/12] clean Working version --- ifrs17/Constants/Enums.ipynb | 2 +- ifrs17/DataModel/DataStructure.ipynb | 3 + ifrs17/Import/1ImportScope-Identities.ipynb | 3 +- ifrs17/Import/2ImportScope-PresentValue.ipynb | 57 ++++++++----------- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/ifrs17/Constants/Enums.ipynb b/ifrs17/Constants/Enums.ipynb index 0c2716f4..7046c0ca 100644 --- a/ifrs17/Constants/Enums.ipynb +++ b/ifrs17/Constants/Enums.ipynb @@ -117,7 +117,7 @@ { "cell_type": "code", "source": [ - "public enum ValuationPeriod { NotApplicable, BeginningOfPeriod, MidOfPeriod, Delta, FullDelta, EndOfPeriod }" + "public enum ValuationPeriod { NotApplicable, BeginningOfPeriod, MidOfPeriod, Delta, EndOfPeriod }" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 0c70abf5..9bed0249 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -1873,6 +1873,9 @@ "\n ", "\n [NotVisible]", "\n public string ValuationApproach { get; init; }", + "\n", + "\n [NotVisible]", + "\n public string LiabilityType { get; init; }", "\n ", "\n [NotVisible]", "\n public int ProjectionPeriod { get; init; }", diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index c20a14d0..63470857 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -146,7 +146,8 @@ "\n protected IEnumerable allIdentities => GetStorage().AocConfigurationByAocStep.Values.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity });", "\n", "\n IEnumerable Identities => allIdentities.Select(id => id with { IsReinsurance = GetStorage().DataNodeDataBySystemName[id.DataNode].IsReinsurance,", - "\n ValuationApproach = GetStorage().DataNodeDataBySystemName[id.DataNode].ValuationApproach});", + "\n ValuationApproach = GetStorage().DataNodeDataBySystemName[id.DataNode].ValuationApproach,", + "\n LiabilityType = GetStorage().DataNodeDataBySystemName[id.DataNode].LiabilityType });", "\n}", "\n", "\npublic interface GetCashflowIdentities : GetIdentities", diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index ca2b7968..ae485d3f 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -165,32 +165,37 @@ "\n{", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", + "\n", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if it is NOT CL AND NOT EOP AND", - "\n x.Identity.Id.Novelty != Novelties.I && // if it is NOT inforce", - "\n //x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LIC && // if it is LIC", + "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if AocType is NOT CL AND NOT EOP AND", + "\n x.Identity.Id.Novelty != Novelties.I && // if Novelty is NOT inforce AND", "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", - "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it (has AY and is LIC with AY < than projected FY)", + "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES NOT (have AY and with AY >= than projected FY)", "\n )", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", - "\n x.Identity.Id.Novelty == Novelties.I && // if it is inforce", - "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LIC && // if it is LIC", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", - "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if AocType is BOP, CF or IA (or not in telescopic) AND", + "\n x.Identity.Id.Novelty == Novelties.I && // if Novelty is inforce AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LIC && // if LiabilityType is LIC AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY >= than projected FY)", "\n )", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", - "\n (x.Identity.Id.Novelty != Novelties.I && x.Identity.Id.Novelty != Novelties.C) && // if it is NOT inforce", - "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && // if it is LRC", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", - "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && // if LiabilityType is LRC", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear < (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY < than projected FY)", "\n )", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType == AocTypes.CF) && ", - "\n x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // is LRC with AY defined", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 Year AND", - "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (doesn't have AY and is LIC AND AY is >= than projected FY)", + "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if AocType is BOP, CF or IA (or not in telescopic) AND", + "\n (x.Identity.Id.Novelty != Novelties.I && x.Identity.Id.Novelty != Novelties.C) && // if Novelty is NOT inforce AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && // if LiabilityType is LRC AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY >= than projected FY)", + "\n )", + "\n .WithApplicability(x =>", + "\n (x.Identity.Id.AocType == AocTypes.CF) && // if AocType is CF AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // if LiabilityType is LRC with AY defined", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 AND", + "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if AY == projected FY", "\n )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", @@ -400,7 +405,6 @@ "\n\\text{PV}_{S} ~, & \\text{if Valuation Period is Beginning of Period} \\\\", "\n\\text{PV}_{S+TS/2 -1} ~, & \\text{if Valuation Period is Mid of Period} \\\\", "\n\\sum_{i=S}^{S + TS - 1}\\text{PV }_{i} ~, & \\text{if Valuation Period is Delta} \\\\", - "\n\\sum_{i=S}^{\\infty}\\text{PV }_{i} ~, & \\text{if Valuation Period is Full Delta} \\\\", "\n\\text{PV}_{S + TS} ~, & \\text{if Valuation Period is End of Period} \\\\", "\n\\end{array}", "\n\\right.", @@ -432,7 +436,6 @@ "\n ValuationPeriod.BeginningOfPeriod => Values.ElementAtOrDefault(shift),", "\n ValuationPeriod.MidOfPeriod => Values.ElementAtOrDefault(shift + Convert.ToInt32(Math.Round(timeStep / 2d, MidpointRounding.AwayFromZero)) - 1),", "\n ValuationPeriod.Delta => Values.Skip(shift).Take(timeStep).Sum(),", - "\n ValuationPeriod.FullDelta => Values.Skip(shift).Sum(),", "\n ValuationPeriod.EndOfPeriod => Values.ElementAtOrDefault(shift + timeStep),", "\n ValuationPeriod.NotApplicable => default", "\n };", @@ -591,9 +594,7 @@ "\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.EOP && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\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 && x.GetStorage().DataNodeDataBySystemName[x.Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue)", "\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)) ||", @@ -614,22 +615,10 @@ "\n double[] PresentValue.Values => Enumerable.Empty().ToArray();", "\n}", "\n", - "\n// public interface PresentValueFromDiscountedCashflowWithAccidentYear : PresentValue {", - "\n// [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", - "\n// double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString()); ", - "\n// }", - "\n", "\npublic interface PresentValueFromDiscountedCashflow : PresentValue {", "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", "\n", - "\n// public interface CashflowAocStepLrcWithAccidentYear : PresentValue {", - "\n// double PresentValue.Value => GetValueFromValues(Values, ValuationPeriod.FullDelta.ToString());", - "\n// [NotVisible] double[] PresentValue.Values => MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod))", - "\n// ? GetScope(Identity).Values", - "\n// : Enumerable.Empty().ToArray();", - "\n// }", - "\n", "\npublic interface CashflowAocStep : PresentValue {", "\n [NotVisible] double[] PresentValue.Values => GetScope(Identity).Values;", "\n}", From 2adfdb05a4f665d957c1f97cc980a9ef5ef26580 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Mon, 11 Sep 2023 09:18:35 +0200 Subject: [PATCH 06/12] more clean up --- ifrs17/Import/ImportStorage.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index b8d32d68..6379f093 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -417,7 +417,7 @@ "\n if (patternFromCoverageUnits.Any())", "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n //ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ", From d7463aa3a109cddfae28a7ccd19e61892295c897 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Mon, 11 Sep 2023 09:34:08 +0200 Subject: [PATCH 07/12] clean up --- ifrs17/Import/ImportStorage.ipynb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 6379f093..b7c3725d 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -348,7 +348,6 @@ "\n ? ct.PeriodType : PeriodType.EndOfPeriod;", "\n", "\n //Variables and Cash flows", - "\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 ", @@ -366,21 +365,20 @@ "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", "\n ", "\n //Accident years", - "\n //public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", - "\n", - "\n", "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) { ", - "\n if(!DataNodeDataBySystemName.TryGetValue(dataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, dataNode);", - "\n if(dataNodeData.LiabilityType == LiabilityTypes.LIC)", - "\n return AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", - "\n return AccidentYearsByDataNode.TryGetValue(dataNode, out var ret) ? ret : new int?[] { default };", - "\n }", + "\n if(!DataNodeDataBySystemName.TryGetValue(dataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, dataNode);", + "\n if (AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYears))", + "\n return dataNodeData.LiabilityType == LiabilityTypes.LIC", + "\n ? accidentYears.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet()", + "\n : accidentYears;", + "\n return new int?[] { default };", + "\n }", "\n ", "\n //Parameters", "\n public double GetNonPerformanceRiskRate (ImportIdentity identity, string cdrBasis)", "\n {", - "\n if(!DataNodeDataBySystemName.TryGetValue(identity.DataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, identity.DataNode);", - "\n if(dataNodeData.Partner == null) ApplicationMessage.Log(Error.PartnerNotFound, identity.DataNode);", + "\n if(!DataNodeDataBySystemName.TryGetValue(identity.DataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, identity.DataNode);", + "\n if(dataNodeData.Partner == null) ApplicationMessage.Log(Error.PartnerNotFound, identity.DataNode);", "\n ", "\n double rate;", "\n if(cdrBasis == EconomicBases.C)", From cce1c21cf3b74874a68dbc1ec136cdcba72aa500 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Wed, 13 Sep 2023 12:59:18 +0200 Subject: [PATCH 08/12] PV cosmetic --- ifrs17/Import/2ImportScope-PresentValue.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index ae485d3f..743ebed5 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -165,7 +165,6 @@ "\n{", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", - "\n", "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if AocType is NOT CL AND NOT EOP AND", "\n x.Identity.Id.Novelty != Novelties.I && // if Novelty is NOT inforce AND", @@ -425,7 +424,10 @@ "public interface IWithGetValueFromValues : IScope<(ImportIdentity Id, string AmountType, string EstimateType, int? AccidentYear), ImportStorage>", "\n{", "\n private int shift => GetStorage().GetShift(Identity.Id.ProjectionPeriod);", - "\n private int timeStep => GetStorage().DataNodeDataBySystemName[Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && Identity.AccidentYear.HasValue && (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", + "\n private int timeStep => ", + "\n Identity.Id.LiabilityType == LiabilityTypes.LRC && ", + "\n Identity.AccidentYear.HasValue && ", + "\n (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", "\n ? int.MaxValue", "\n : GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", "\n", From fc69e4c3b2eadae54e0087021cbbd3a6123cecfa Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Mon, 18 Sep 2023 21:48:13 +0200 Subject: [PATCH 09/12] refactoring + warning for missing Pattern --- ifrs17/Constants/Validations.ipynb | 6 + ifrs17/Import/2ImportScope-PresentValue.ipynb | 131 +++++++----------- .../Import/4ImportScope-TechnicalMargin.ipynb | 19 +-- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 104 ++++++++------ ifrs17/Import/ImportStorage.ipynb | 5 +- 5 files changed, 128 insertions(+), 137 deletions(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 8e654e7d..4c8d05b8 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -75,6 +75,10 @@ "\n public static readonly Warning VariablesAlreadyCalculated = new Warning(nameof(VariablesAlreadyCalculated));", "\n public static readonly Warning ScenarioReCalculations = new Warning(nameof(ScenarioReCalculations));", "\n public static readonly Warning MandatoryAocStepMissing = new Warning(nameof(MandatoryAocStepMissing));", + "\n", + "\n // ImportStorage", + "\n public static readonly Warning ReleasePatternNotFound = new Warning(nameof(ReleasePatternNotFound));", + "\n", "\n public static readonly Warning Generic = new Warning(nameof(Generic));", "\n", "\n public override string GetMessage(params string[] s) => (MessageCode, s.Length) switch{", @@ -82,6 +86,8 @@ "\n (nameof(VariablesAlreadyImported), 0) => $\"The import of the current file does not contain any new data. Hence, no data will be saved or calculations will be performed.\",", "\n (nameof(MandatoryAocStepMissing), 3) => $\"The AoC step ({s[0]}, {s[1]}) is not imported for ({s[2]}).\",", "\n (nameof(ScenarioReCalculations), 1) => $\"The present Best Estimate import makes the result of dependent Scenarios out of date. Hence, the following Scenarios are re-calculated: {s[0]}.\", ", + "\n // ImportStorage", + "\n (nameof(ReleasePatternNotFound), 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found.\",", "\n // Default", "\n (nameof(Generic), _) => $\"{s[0]}\",", "\n _ => DefaultMessage", diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index ae485d3f..f2eeba51 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -165,7 +165,6 @@ "\n{", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", - "\n", "\n .WithApplicability(x =>", "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if AocType is NOT CL AND NOT EOP AND", "\n x.Identity.Id.Novelty != Novelties.I && // if Novelty is NOT inforce AND", @@ -395,7 +394,7 @@ { "cell_type": "markdown", "source": [ - "## Present Value", + "## Valuation Period ", "\n", "\nThe present value ($\\rm{PV}$) can be determined by taking the appropriate elements of the cumulated discounted cash flows. This is done as function of the two [projection parameters](../DataModel/DataStructure#projection-configuration) $\\rm{Shift}$ ($S$) and $\\rm{TimeStep}$ ($TS$):", "\n", @@ -425,7 +424,10 @@ "public interface IWithGetValueFromValues : IScope<(ImportIdentity Id, string AmountType, string EstimateType, int? AccidentYear), ImportStorage>", "\n{", "\n private int shift => GetStorage().GetShift(Identity.Id.ProjectionPeriod);", - "\n private int timeStep => GetStorage().DataNodeDataBySystemName[Identity.Id.DataNode].LiabilityType == LiabilityTypes.LRC && Identity.AccidentYear.HasValue && (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", + "\n private int timeStep => ", + "\n Identity.Id.LiabilityType == LiabilityTypes.LRC && ", + "\n Identity.AccidentYear.HasValue && ", + "\n (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", "\n ? int.MaxValue", "\n : GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", "\n", @@ -644,7 +646,8 @@ { "cell_type": "markdown", "source": [ - "## PV by Accident Year" + "## Wrapper over Accident Year", + "\nPresent Value are here collected for all available Accident Year for any combination of [Amount Type](../DataModel/DataStructure#amount-type) and [Estimate Type](../DataModel/DataStructure#estimate-type) specified in input (scope identity). In addition, the sum of present values over the available Accident Years is also provided. " ], "metadata": {}, "execution_count": 0, @@ -653,7 +656,7 @@ { "cell_type": "code", "source": [ - "public interface PvOverAy : IScope<(ImportIdentity Id, string AmountType, string EstimateType), ImportStorage>", + "public interface PvAggregatedOverAccidentYear : IScope<(ImportIdentity Id, string AmountType, string EstimateType), ImportStorage>", "\n{ ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EconomicBasis))]", "\n string EconomicBasis => GetContext();", @@ -661,11 +664,11 @@ "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.Id.DataNode, Identity.Id.ProjectionPeriod).ToArray(); ", "\n ", "\n [NotVisible]", - "\n Dictionary<(string,string,int?),double> PresentValues => accidentYears.ToDictionary(", - "\n ay => (Identity.AmountType, Identity.EstimateType, ay),", - "\n ay => GetScope((Identity.Id, Identity.AmountType, Identity.EstimateType, ay), o => o.WithContext(EconomicBasis)).Value", - "\n ); //Dictionary is not the right structure as I would need an other ToDictionary in MyPvLocked", - "\n double Value => PresentValues.Sum(kvp => kvp.Value);", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => accidentYears.Select(ay => ", + "\n (Identity.AmountType, Identity.EstimateType, ay, GetScope((Identity.Id, Identity.AmountType, Identity.EstimateType, ay), o => o.WithContext(EconomicBasis)).Value))", + "\n .ToArray();", + "\n ", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -673,23 +676,9 @@ "outputs": [] }, { - "cell_type": "code", + "cell_type": "markdown", "source": [ - "public interface MyPvLocked : IScope", - "\n{ ", - "\n [IdentityProperty][NotVisible][Dimension(typeof(EconomicBasis))]", - "\n string EconomicBasis => EconomicBases.L;", - "\n ", - "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", - "\n string EstimateType => EstimateTypes.BE;", - "\n ", - "\n [NotVisible]", - "\n Dictionary<(string,string,int?),double> PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", - "\n ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);", - "\n ", - "\n //double Value => PresentValues.Aggregate().Value;", - "\n}" + "# Best Estimate" ], "metadata": {}, "execution_count": 0, @@ -698,9 +687,7 @@ { "cell_type": "markdown", "source": [ - "## Current and Locked", - "\n", - "\nPV Current and PV Locked below basically hold the Present Values [PV](#present-value) computed using the **Current** yield curves and the **Locked** yield curves, respectively.", + "PV Current and PV Locked below basically hold the Present Values [PV](#present-value) computed using the **Current** yield curves and the **Locked** yield curves, respectively.", "\n", "\nValues are available for each AmountType (by calling PvLocked.ByAmountType):", "\n", @@ -713,7 +700,7 @@ "\n$$", "\n", "\n", - "\nAnd aggregated values are also available as the sum over all [Amount Types](../DataModel/DataStructure#amount-type) (by calling PvLocked.Value):", + "\nAnd aggregated values are also available as the sum over all [Amount Types](../DataModel/DataStructure#amount-type) and Accident Year (by calling PvLocked.Value):", "\n", "\n$$", "\n\\text{PV Locked}(\\text{AoC step}) = \\sum_{\\text{Amount Types}} \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = L}}", @@ -739,15 +726,13 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", + "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", + "\n", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -764,31 +749,19 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", + "\n", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", + "\n", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "## Nominal" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -799,15 +772,12 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", + "\n", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -845,12 +815,11 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n", + "\n [NotVisible]", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", + "\n ", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -868,11 +837,10 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray(); ", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n [NotVisible]", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", + "\n ", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -889,12 +857,10 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", + "\n ", + "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -915,7 +881,7 @@ { "cell_type": "markdown", "source": [ - "## Amortization Factor" + "## Monthly AM Factor" ], "metadata": {}, "execution_count": 0, @@ -987,7 +953,8 @@ { "cell_type": "markdown", "source": [ - "For a certain projection period - defined by the Shift, $S$, and the Time-Step, $TS$, parameters - the Amortization Factor is then given by the product of the corresponding monthly amortization factors:", + "## Current Period AM actor", + "\nFor a certain projection period - defined by the Shift, $S$, and the Time-Step, $TS$, parameters - the Amortization Factor is then given by the product of the corresponding monthly amortization factors:", "\n", "\n$$", "\nAF = 1 - \\prod _{i = S}^{S + TS - 1} \\text{Monthly }AF_i ~.", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index 7ebff638..47905e2e 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -120,7 +120,7 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(AmountType))] string AmountType => AmountTypes.PR;", "\n", "\n double Value => GetStorage().GetPremiumAllocationFactor(Identity) * ", - "\n GetStorage().GetPremiums().Sum(pr => GetScope((Identity, pr, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value);", + "\n GetStorage().GetPremiums().Sum(pr => GetScope((Identity, pr, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value);", "\n}", "\n", "\npublic interface DefaultValueBeExperienceAdjustmentForPremium : BeExperienceAdjustmentForPremium{", @@ -270,6 +270,7 @@ "\n .WithApplicability(x => x.Identity.AocType == AocTypes.BOP && x.Identity.Novelty == Novelties.I && x.Identity.ProjectionPeriod > 0)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.BOP && x.Identity.Novelty == Novelties.I)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.CF)", + "\n //.WithApplicability(x => x.Identity.AocType == AocTypes.IA && x.Identity.Novelty == Novelties.N) //Change", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.IA && x.Identity.Novelty == Novelties.I)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.EA && !x.Identity.IsReinsurance)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.AM)", @@ -280,8 +281,8 @@ "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", "\n double Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", - "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value;", + "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value;", "\n ", "\n double AggregatedValue => GetScope((Identity, InputSource.Cashflow)).Values", "\n .Sum(aoc => GetScope(Identity with {AocType = aoc.AocType, Novelty = aoc.Novelty}).Value);", @@ -294,8 +295,8 @@ "\npublic interface TechnicalMarginForPaa : TechnicalMargin{", "\n [NotVisible] string TechnicalMargin.EconomicBasis => EconomicBases.C;", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", - "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value +", + "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value +", "\n GetScope(Identity).Value + GetScope(Identity).Value;", "\n}", "\n", @@ -330,10 +331,10 @@ "\n .Sum(n => GetScope(Identity with {AocType = referenceAocType, Novelty = n}, o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope(Identity with {AocType = referenceAocType, Novelty = Novelties.C}).Value;", "\n protected double deferrable => GetStorage().GetDeferrableExpenses().Sum(d =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, d, EstimateTypes.A, (int?)null)).Value);", "\n protected double investmentClaims => GetStorage().GetInvestmentClaims().Sum(ic =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, ic, EstimateTypes.A, (int?)null)).Value);", "\n ", "\n double TechnicalMargin.Value => premiums + deferrable + investmentClaims;", @@ -354,8 +355,8 @@ "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", "\n private IEnumerable novelties => GetStorage().GetNovelties(AocTypes.CF).Where(novelty => novelty != Novelties.C);", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value + ", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value));", + "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value + ", + "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value));", "\n//+ Revenue AM + Deferral AM", "\n", "\n}", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 54c143b3..aa0ebe69 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -100,27 +100,28 @@ "\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 PvLocked => GetScope(Identity).RepeatOnce().SelectMany(x =>", - "\n x.PresentValues.Select(kvp => ", + "\n IEnumerable PvLocked => GetScope(Identity).RepeatOnce().SelectMany(x =>", + "\n x.PresentValues.Select(pv =>", "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", "\n EstimateType = x.EstimateType, ", "\n DataNode = x.Identity.DataNode, ", "\n AocType = x.Identity.AocType, ", "\n Novelty = x.Identity.Novelty, ", - "\n AccidentYear = kvp.Key.Item3,", - "\n AmountType = kvp.Key.Item1,", - "\n Values = SetProjectionValue(kvp.Value, x.Identity.ProjectionPeriod),", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }));", - "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", + "\n IEnumerable PvCurrent => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv =>", "\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 EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition }));", "\n}", "\n", "\npublic interface EmptyPvIfrsVariable: PvToIfrsVariable{", @@ -147,17 +148,28 @@ "source": [ "public interface NominalToIfrsVariable: IScope", "\n{", - "\n IEnumerable CumulatedNominal => GetScope(Identity).PresentValues", - "\n .Concat(GetScope(Identity).PresentValues)", - "\n .Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod), ", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable CumulatedNominal => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}))", + "\n .Concat(GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition})));", "\n}" ], "metadata": {}, @@ -178,27 +190,29 @@ "source": [ "public interface RaToIfrsVariable: IScope", "\n{", - "\n IEnumerable RaCurrent => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable RaCurrent => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}));", "\n ", - "\n IEnumerable RaLocked => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable RaLocked => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}));", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index b7c3725d..19dca75c 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -415,7 +415,10 @@ "\n if (patternFromCoverageUnits.Any())", "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n if(DataNodeDataBySystemName[identity.DataNode].ValuationApproach == ValuationApproaches.PAA && DataNodeDataBySystemName[identity.DataNode].LiabilityType == LiabilityTypes.LRC)", + "\n ApplicationMessage.Log(Warning.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n else ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n ", "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ", From 04490ad8bdabf7999b60139c44e750d6382f0b19 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Mon, 18 Sep 2023 22:09:28 +0200 Subject: [PATCH 10/12] reset --- .../NominalCashflows_CH_2020_12_AyLRC.csv | 21 ------ .../EvaluateImportScopes.ipynb | 66 +++++++------------ 2 files changed, 23 insertions(+), 64 deletions(-) delete mode 100644 ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv diff --git a/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv b/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv deleted file mode 100644 index 39b966cb..00000000 --- a/ifrs17-template/Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv +++ /dev/null @@ -1,21 +0,0 @@ -@@Main,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -ReportingNode,Year,Month,Scenario,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -CH,2020,12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -DataNode,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,Values24,Values25,Values26,Values27,Values28,Values29,Values30,Values31,Values32,Values33,Values34,Values35 -DT1.1,NIC,BE,BOP,N,2020,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, -DT1.1,NIC,BE,CL,C,2020,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -DT1.1,NIC,BE,BOP,N,2021,0,0,0,0,0,0,0,0,0,0,0,0,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 -DT1.1,NIC,BE,CL,C,2021,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,,,,,,,,,,,,,,,,, -DT1.1,PR,BE,BOP,N,,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 -DT1.1,PR,BE,CL,C,,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-666.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200 -DT1.1,,RA,BOP,N,,-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,,,,,,,,,,,, -DT1.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,,,,,,,,,,,, -DT1.1,CU,P,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,,,,,,,,,,,, -DT1.2,NIC,BE,BOP,N,2020,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-466.6666667,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, -DT1.2,,RA,BOP,N,2020,-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,,,,,,,,,,,, -DT1.2,NIC,BE,CL,C,2020,0,0,0,0,0,0,0,0,0,0,0,0,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,-200,,,,,,,,,,,, -DT1.2,CU,P,CL,C,2020,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3,,,,,,,,,,,, -DT1.2,,RA,CL,C,2020,-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,,,,,,,,,,,, -DT1.2,NIC,BE,BOP,N,2021,0,0,0,0,0,0,0,0,0,0,0,0,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,,,,,,,,,,,, -DT1.2,NIC,BE,CL,C,2021,0,0,0,0,0,0,0,0,0,0,0,0,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,-83.33333333,,,,,,,,,,,, diff --git a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb index a52dbc16..09cabff5 100644 --- a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb +++ b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb @@ -88,7 +88,7 @@ { "cell_type": "code", "source": [ - "await Import.FromFile(\"../../Files/TransactionalData/NominalCashflows_CH_2020_12_AyLRC.csv\")", + "await Import.FromFile(\"../../Files/TransactionalData/NominalCashflowsPAA_CH_2020_12.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", @@ -256,38 +256,7 @@ { "cell_type": "code", "source": [ - "Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = 0}), storage).ToScopes().SelectMany(x => x.PvLocked.Concat(x.PvCurrent)).ToArray()", - "\n.Where(x => x.EconomicBasis==\"L\" && x.Values.Any(y => Math.Abs(y)> Precision) && x.DataNode == \"DT1.1\" && new[]{\"PR\",\"NIC\"}.Contains(x.AmountType))", - "\n", - "\n.Where(x=> x.AmountType==\"NIC\")//.Aggregate()" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = 1}), storage).ToScopes().SelectMany(x => x.PvLocked.Concat(x.PvCurrent)).ToArray()", - "\n.Where(x => x.EconomicBasis==\"L\" && x.Values != null && x.Values.Any(y => Math.Abs(y)> Precision) && x.DataNode == \"DT1.1\" && new[]{\"PR\",\"NIC\"}.Contains(x.AmountType))" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.CumulatedNominal).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -296,7 +265,7 @@ { "cell_type": "code", "source": [ - "" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.RaCurrent.Concat(x.RaLocked)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -305,7 +274,7 @@ { "cell_type": "code", "source": [ - "" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Actual.Concat(x.AdvanceActual).Concat(x.OverdueActual)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -314,7 +283,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.CumulatedNominal).ToArray();" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Deferrable).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -323,7 +292,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.RaCurrent.Concat(x.RaLocked)).ToArray();" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.BeEAForPremium.Concat(x.ActEAForPremium)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -332,7 +301,7 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Actual.Concat(x.AdvanceActual).Concat(x.OverdueActual)).ToArray();" + "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.AmortizationFactor.Concat(x.Csms).Concat(x.Loss)).ToArray();" ], "metadata": {}, "execution_count": 0, @@ -341,16 +310,16 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.Deferrable).ToArray();" + "" ], "metadata": {}, "execution_count": 0, "outputs": [] }, { - "cell_type": "code", + "cell_type": "markdown", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.BeEAForPremium.Concat(x.ActEAForPremium)).ToArray();" + "# Temporary test of DAC for PAA" ], "metadata": {}, "execution_count": 0, @@ -359,7 +328,16 @@ { "cell_type": "code", "source": [ - "var ivs = Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod = projection}), storage).ToScopes().SelectMany(x => x.AmortizationFactor.Concat(x.Csms).Concat(x.Loss)).ToArray();" + "var iv = Enumerable.Range(0,5).SelectMany(p=>", + "\n Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod=p}), storage)", + "\n .ToScopes().SelectMany(x => x.Deferrable))", + "\n.AggregateProjections().Where(x => x.Values.Any(v => Math.Abs(v) > Precision ))", + "\n.ToArray();", + "\n", + "\nvar eops= iv.Where(x => x.AocType == \"EOP\");", + "\nvar ams = iv.Where(x => x.AocType == \"AM\" && x.EstimateType == \"DA\");", + "\n", + "\niv" ], "metadata": {}, "execution_count": 0, @@ -368,7 +346,9 @@ { "cell_type": "code", "source": [ - "" + "//Testing", + "\n(Math.Abs(eops.Single(x => x.AccidentYear == 0).Values.First() - 647.5)< Precision, Math.Abs(eops.Single(x => x.AccidentYear == 2).Values.First() - 918.125)< Precision, ", + "\nMath.Abs(ams.Single(x => x.AccidentYear == 0).Values.First() - -352.5)< Precision, Math.Abs(ams.Single(x => x.AccidentYear == 2).Values.First() - -381.87499999999994)< Precision)" ], "metadata": {}, "execution_count": 0, From 95df8b30d2ae21804200bba0ef40ae92472379ca Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Mon, 18 Sep 2023 22:26:24 +0200 Subject: [PATCH 11/12] doc and clean up --- .../EvaluateImportScopes.ipynb | 47 ------------------- ifrs17/Import/2ImportScope-PresentValue.ipynb | 27 ++--------- 2 files changed, 3 insertions(+), 71 deletions(-) diff --git a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb index 09cabff5..8c8824e0 100644 --- a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb +++ b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb @@ -307,53 +307,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Temporary test of DAC for PAA" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var iv = Enumerable.Range(0,5).SelectMany(p=>", - "\n Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod=p}), storage)", - "\n .ToScopes().SelectMany(x => x.Deferrable))", - "\n.AggregateProjections().Where(x => x.Values.Any(v => Math.Abs(v) > Precision ))", - "\n.ToArray();", - "\n", - "\nvar eops= iv.Where(x => x.AocType == \"EOP\");", - "\nvar ams = iv.Where(x => x.AocType == \"AM\" && x.EstimateType == \"DA\");", - "\n", - "\niv" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "//Testing", - "\n(Math.Abs(eops.Single(x => x.AccidentYear == 0).Values.First() - 647.5)< Precision, Math.Abs(eops.Single(x => x.AccidentYear == 2).Values.First() - 918.125)< Precision, ", - "\nMath.Abs(ams.Single(x => x.AccidentYear == 0).Values.First() - -352.5)< Precision, Math.Abs(ams.Single(x => x.AccidentYear == 2).Values.First() - -381.87499999999994)< Precision)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index f2eeba51..c01e0b1b 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -689,7 +689,7 @@ "source": [ "PV Current and PV Locked below basically hold the Present Values [PV](#present-value) computed using the **Current** yield curves and the **Locked** yield curves, respectively.", "\n", - "\nValues are available for each AmountType (by calling PvLocked.ByAmountType):", + "\nValues are available for each AmountType and AccidentYear (by calling PvLocked.PresentValues):", "\n", "\n$$", "\n\\text{PV Locked}(\\text{AoC step}, \\text{Amount Type}) = \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = L}}", @@ -699,18 +699,9 @@ "\n\\text{PV Current}(\\text{AoC step}, \\text{Amount Type}) = \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = C}}", "\n$$", "\n", + "\nAggregated present values are also available through summing over Amount Types and Accident Year (by calling PvLocked.PresentValues.Sum(pv => pv.Value)).", "\n", - "\nAnd aggregated values are also available as the sum over all [Amount Types](../DataModel/DataStructure#amount-type) and Accident Year (by calling PvLocked.Value):", - "\n", - "\n$$", - "\n\\text{PV Locked}(\\text{AoC step}) = \\sum_{\\text{Amount Types}} \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = L}}", - "\n$$", - "\n", - "\n$$", - "\n\\text{PV Current}(\\text{AoC step}) = \\sum_{\\text{Amount Types}} \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = C}}", - "\n$$", - "\n", - "\nThese are used in the BBA methodology, whereby in the CSM calculations only PV Locked is used, and both of them are stored in the database under the [IfrsVariable](../DataModel/DataStructure#ifrs-variable) data structure." + "\nPV Current and PV Locked are both computed in the BBA methodology, although the CSM calculations uses only PV Locked for BBA valuation approach and PV Current for VFA valuation approach. Depending on the valuation approach Present Values Locked and/or Present Values current are stored in the database under the [IfrsVariable](../DataModel/DataStructure#ifrs-variable) data structure." ], "metadata": {}, "execution_count": 0, @@ -731,8 +722,6 @@ "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", "\n ).ToArray();", - "\n", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -754,8 +743,6 @@ "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", "\n ).ToArray();", - "\n", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -776,8 +763,6 @@ "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", "\n ).ToArray();", - "\n", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -818,8 +803,6 @@ "\n", "\n [NotVisible]", "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", - "\n ", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -839,8 +822,6 @@ "\n ", "\n [NotVisible]", "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", - "\n ", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, @@ -859,8 +840,6 @@ "\n ", "\n [NotVisible]", "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", - "\n ", - "\n double Value => PresentValues.Sum(pv => pv.Value);", "\n}" ], "metadata": {}, From ea5c70669479d5d2f4ceb300a6f1786cb1f30071 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Mon, 18 Sep 2023 23:02:39 +0200 Subject: [PATCH 12/12] clean --- ifrs17/Import/4ImportScope-TechnicalMargin.ipynb | 1 - 1 file changed, 1 deletion(-) diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index 47905e2e..cd4d2957 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -270,7 +270,6 @@ "\n .WithApplicability(x => x.Identity.AocType == AocTypes.BOP && x.Identity.Novelty == Novelties.I && x.Identity.ProjectionPeriod > 0)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.BOP && x.Identity.Novelty == Novelties.I)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.CF)", - "\n //.WithApplicability(x => x.Identity.AocType == AocTypes.IA && x.Identity.Novelty == Novelties.N) //Change", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.IA && x.Identity.Novelty == Novelties.I)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.EA && !x.Identity.IsReinsurance)", "\n .WithApplicability(x => x.Identity.AocType == AocTypes.AM)",