From 3ab54870481e08a1c1509309db897730903f8990 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 6 Jul 2023 14:35:17 +0200 Subject: [PATCH 01/24] clean up AocConfig --- ifrs17-template/Files/Dimensions.csv | 1 - 1 file changed, 1 deletion(-) diff --git a/ifrs17-template/Files/Dimensions.csv b/ifrs17-template/Files/Dimensions.csv index da6e028c..ebdf7f14 100644 --- a/ifrs17-template/Files/Dimensions.csv +++ b/ifrs17-template/Files/Dimensions.csv @@ -65,7 +65,6 @@ WO,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable, CL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1 EA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1 AM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1 -FX,C,Calculated,0,NotApplicable,NotApplicable,NotApplicable,NotApplicable,NotApplicable,210,1900,1 EOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1 ,,,,,,,,,,, @@CreditRiskRating,,,,,,,,,,, From 7f2ae3383603c990a8f3a6d6a102c187982e1954 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 6 Jul 2023 14:38:39 +0200 Subject: [PATCH 02/24] refactor creation of identities --- ifrs17/Import/1ImportScope-Identities.ipynb | 117 +++++------------- ifrs17/Import/2ImportScope-PresentValue.ipynb | 2 +- ifrs17/Import/6ImportScope-Compute.ipynb | 2 +- ifrs17/Test/AocStructureTest.ipynb | 8 +- ifrs17/Test/TestData.ipynb | 1 - 5 files changed, 38 insertions(+), 92 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index 7a46a361..667ead90 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -113,14 +113,22 @@ { "cell_type": "code", "source": [ - "public interface AllCfIdentities : IScope // string represents a DataNode", + "public interface AllCfIdentities : IScope // Identity corresponds to the DataNode", "\n{", - "\n public IEnumerable ids => GetStorage().GetAllAocSteps(InputSource.Cashflow)", - "\n .Select(aocStep => new ImportIdentity {", - "\n AocType = aocStep.AocType,", - "\n Novelty = aocStep.Novelty,", - "\n DataNode = Identity", - "\n });", + "\n IEnumerable ids => GetStorage().GetAllAocSteps(InputSource.Cashflow)", + "\n .Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity });", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface GetParsedAocSteps : IScope", + "\n{", + "\n IEnumerable Values => GetStorage().GetRawVariables(Identity).Select(x => new AocStep(x.AocType, x.Novelty)).Distinct();", "\n}" ], "metadata": {}, @@ -133,88 +141,30 @@ "public interface GetIdentities : IScope", "\n{", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", - "\n builder.ForScope(s => s.WithApplicability(x => x.GetStorage().IsSecondaryScope(x.Identity))", - "\n .WithApplicability(x => x.GetStorage().ImportFormat == ImportFormats.Actual)", - "\n .WithApplicability(x => x.GetStorage().ImportFormat == ImportFormats.Cashflow)", - "\n .WithApplicability(x => x.GetStorage().ImportFormat == ImportFormats.Opening)", - "\n );", + "\n builder.ForScope(s => s.WithApplicability(x => x.GetStorage().ImportFormat == ImportFormats.Cashflow));", "\n ", - "\n private IEnumerable computedIdentities => new string[]{AocTypes.EA, AocTypes.AM, AocTypes.EOP}", - "\n .Select(aocType => new ImportIdentity {", - "\n AocType = aocType,", - "\n Novelty = Novelties.C,", - "\n DataNode = Identity", - "\n });", - "\n private IEnumerable allIdentities => ParsedIdentities.Concat(computedIdentities).Concat(SpecialIdentities).ToHashSet(); ", - "\n ", - "\n IEnumerable ParsedIdentities => Enumerable.Empty(); ", - "\n IEnumerable SpecialIdentities => Enumerable.Empty();", - "\n ", - "\n //Set DataNode properties and ProjectionPeriod", - "\n IEnumerable Identities => allIdentities.Select(id => id with { IsReinsurance = GetStorage().DataNodeDataBySystemName[id.DataNode].IsReinsurance,", - "\n ValuationApproach = GetStorage().DataNodeDataBySystemName[id.DataNode].ValuationApproach", - "\n });", - "\n /* .SelectMany(id => Enumerable.Range(0,GetStorage().GetProjectionCount() + 1)", - "\n .Select(pp => id with {ProjectionPeriod = pp })", - "\n );*/", - "\n}", + "\n protected IEnumerable allIdentities => GetStorage().AocConfigurationByAocStep.Values.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity });", "\n", - "\npublic interface AllCashflowIdentities : GetIdentities", - "\n{", - "\n IEnumerable GetIdentities.SpecialIdentities => GetScope(Identity).ids;", - "\n}", - "\n", - "\n", - "\npublic interface GetActualIdentities : GetIdentities", - "\n{", - "\n private IEnumerable actualEstimateTypes => GetStorage().EstimateTypesByImportFormat[ImportFormats.Actual];", - "\n ", - "\n IEnumerable GetIdentities.ParsedIdentities => GetStorage().GetIfrsVariables(Identity).Where(iv => actualEstimateTypes.Contains(iv.EstimateType)).Select(v => new ImportIdentity(v));", - "\n IEnumerable GetIdentities.SpecialIdentities => GetScope(Identity).ids", - "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Opening)", - "\n .Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, ", - "\n Novelty = aocStep.Novelty,", - "\n 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}", "\n", "\npublic interface GetCashflowIdentities : GetIdentities", "\n{", - "\n private bool isReinsurance => GetStorage().DataNodeDataBySystemName[Identity].IsReinsurance; //clean up in the next PR", + "\n private bool isReinsurance => GetStorage().DataNodeDataBySystemName[Identity].IsReinsurance;", "\n ", - "\n IEnumerable GetIdentities.ParsedIdentities => GetStorage().GetRawVariables(Identity).Select(v => new ImportIdentity(v));", + "\n private IEnumerable ParsedIdentities => GetScope(Identity).Values.Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity});", "\n ", - "\n IEnumerable GetIdentities.SpecialIdentities => ParsedIdentities.Where(id => id.Novelty != Novelties.C)", - "\n .Select(id => id.Novelty).ToHashSet()", - "\n .SelectMany(n => (n == Novelties.N ", - "\n ? new string[]{AocTypes.IA, AocTypes.CF} //Add IA, CF, for New Business", - "\n : isReinsurance ", - "\n ? new string[]{AocTypes.IA, AocTypes.CF, AocTypes.YCU, AocTypes.CRU, AocTypes.RCU} //Add IA, CF, YCU, CRU, RCU for in force", - "\n : new string[]{AocTypes.IA, AocTypes.CF, AocTypes.YCU}) //Add IA, CF, YCU,", - "\n .Select(aocType => new ImportIdentity {", - "\n AocType = aocType,", - "\n Novelty = n,", - "\n DataNode = Identity }))", - "\n .Concat(new ImportIdentity {", - "\n AocType = AocTypes.CF, //Add CF for Deferral", - "\n Novelty = Novelties.C,", - "\n DataNode = Identity", - "\n }.RepeatOnce()) ", - "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Opening)", - "\n .Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, ", - "\n Novelty = aocStep.Novelty,", - "\n DataNode = Identity", - "\n })); ", - "\n}", + "\n private IEnumerable rawVariableNovelties => GetStorage().GetRawVariables(Identity).Select(rv => rv.Novelty).Distinct().Concat(Novelties.C.RepeatOnce());", "\n", - "\npublic interface GetAllIdentities : GetIdentities", - "\n{", - "\n IEnumerable GetIdentities.SpecialIdentities => GetScope(Identity).ids", - "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Actual)", - "\n .Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, ", - "\n Novelty = aocStep.Novelty,", - "\n DataNode = Identity,", - "\n }));", + "\n private IEnumerable calculatedAocSteps => GetStorage().AocConfigurationByAocStep.Values.Where(x => new DataType[]{DataType.Calculated, DataType.CalculatedTelescopic}.Contains(x.DataType) &&", + "\n (!isReinsurance ? !new []{AocTypes.CRU, AocTypes.RCU}.Contains(x.AocType) : true) && rawVariableNovelties.Contains(x.Novelty) ).Select(x => new AocStep(x.AocType, x.Novelty));", + "\n", + "\n private IEnumerable SpecialIdentities => calculatedAocSteps.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity })", + "\n .Concat(new ImportIdentity {AocType = AocTypes.CF, Novelty = Novelties.C,DataNode = Identity}.RepeatOnce()) //Add CF for Deferral", + "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Opening).Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity}));//Add BOP,I and IA,I", + "\n", + "\n IEnumerable GetIdentities.allIdentities => ParsedIdentities.Concat(SpecialIdentities).Distinct(); ", "\n}" ], "metadata": {}, @@ -312,7 +262,7 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.AmountType != AmountTypes.CDR));", "\n ", - "\n private HashSet ParsedAocSteps => GetScope(Identity.Id.DataNode).ParsedIdentities.Select(id => new AocStep(id.AocType, id.Novelty)).ToHashSet();", + "\n private IEnumerable ParsedAocSteps => GetScope(Identity.Id.DataNode).Values;", "\n private IEnumerable OrderedParsedAocSteps => ParsedAocSteps.Concat(CalculatedTelescopicAocStep).OrderBy(x => GetStorage().AocConfigurationByAocStep[x].Order);", "\n ", "\n private Dictionary> ParentParsedIdentities => GetPreviousIdentities(OrderedParsedAocSteps);", @@ -371,10 +321,7 @@ "source": [ "public interface ReferenceAocStep : IScope ", "\n{", - "\n private IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).ParsedIdentities", - "\n .Select(id => new AocStep(id.AocType, id.Novelty))", - "\n .Distinct()", - "\n .OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", + "\n private IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", "\n private AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", "\n private AocStep GetReferenceAocStep(string aocType) {", "\n return aocType switch {", diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index bdb574ec..90ca4e06 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -528,7 +528,7 @@ "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.IA)", "\n .WithApplicability(x => ComputationHelper.AocTypeWithNoPv.Contains(x.Identity.Id.AocType) ||", - "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) ) ", + "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) )", "\n );", "\n ", "\n [NotVisible][IdentityProperty][Dimension(typeof(EconomicBasis))]", diff --git a/ifrs17/Import/6ImportScope-Compute.ipynb b/ifrs17/Import/6ImportScope-Compute.ipynb index eabcf6ad..3eb5c113 100644 --- a/ifrs17/Import/6ImportScope-Compute.ipynb +++ b/ifrs17/Import/6ImportScope-Compute.ipynb @@ -125,7 +125,7 @@ { "cell_type": "markdown", "source": [ - "# Chashflows with Projections" + "# Cashflows with Projections" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index 298a59d2..500ca1b2 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -155,19 +155,20 @@ "\n inputSource = InputSource.Actual;", "\n }", "\n ", + "\n ", "\n var newArgs = args with {ImportFormat = importFormat };", + "\n var goc = inputVariables.First().DataNode;", + "\n ", "\n //Set up import storage and test universe", "\n var testStorage = new ImportStorage(newArgs, DataSource, Workspace);", "\n await testStorage.InitializeAsync();", - "\n var isReinsurance = testStorage.DataNodeDataBySystemName[inputVariables.First().DataNode].IsReinsurance;", + "\n var isReinsurance = testStorage.DataNodeDataBySystemName[goc].IsReinsurance;", "\n var testUniverse = Scopes.ForStorage(testStorage).ToScope();", "\n //Clean up Workspace", "\n await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync()); ", "\n await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync()); ", "\n ", "\n var errors = new List();", - "\n ", - "\n var goc = inputVariables.First().DataNode;", "\n var identities = testUniverse.GetScopes(testStorage.DataNodesByImportScope[ImportScope.Primary].Where(dn => dn == goc)).SelectMany(s => s.Identities);", "\n ", "\n //Assert Parents", @@ -704,7 +705,6 @@ "\nCL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", "\nEA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", "\nAM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", - "\nFX,C,Calculated,0,NotApplicable,NotApplicable,NotApplicable,NotApplicable,NotApplicable,210,1900,1", "\nEOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], "metadata": {}, diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index 076f9df1..bd518ecd 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -79,7 +79,6 @@ "\nCL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", "\nEA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", "\nAM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", - "\nFX,C,Calculated,0,NotApplicable,NotApplicable,NotApplicable,NotApplicable,NotApplicable,210,1900,1", "\nEOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], "metadata": {}, From 06a38e0874ec82ac7be1631f8073d82de98b6b99 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Fri, 7 Jul 2023 18:31:23 +0200 Subject: [PATCH 03/24] ifrs17ce --- ifrs17/Constants/Enums.ipynb | 10 +- ifrs17/Import/1ImportScope-Identities.ipynb | 109 ++++++++++++------ ifrs17/Import/2ImportScope-PresentValue.ipynb | 2 +- ifrs17/Test/TestData.ipynb | 42 +++---- ifrs17/Utils/ImportCalculationMethods.ipynb | 5 +- 5 files changed, 105 insertions(+), 63 deletions(-) diff --git a/ifrs17/Constants/Enums.ipynb b/ifrs17/Constants/Enums.ipynb index d1f3e733..3d4ad525 100644 --- a/ifrs17/Constants/Enums.ipynb +++ b/ifrs17/Constants/Enums.ipynb @@ -277,7 +277,15 @@ { "cell_type": "code", "source": [ - "public enum DataType { Optional, Mandatory, Calculated, CalculatedTelescopic }" + "[Flags]", + "\npublic enum DataType {Optional = 1, Mandatory = 2, Calculated = 4, CalculatedTelescopic = 8}", + "\n//Optional + Mandatory = 3", + "\n//Optional + Calculated = 5", + "\n//Optional + CalculatedTelescopic = 9", + "\n//Mandatory + Calculated = 6", + "\n//Mandatory + CalculatedTelescopic = 10", + "\n//Calculated + CalculatedTelescopic = 12", + "\n//Optional + Mandatory + Calculated + CalculatedTelescopic = 15" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index 667ead90..cffee20a 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -152,16 +152,13 @@ "\npublic interface GetCashflowIdentities : GetIdentities", "\n{", "\n private bool isReinsurance => GetStorage().DataNodeDataBySystemName[Identity].IsReinsurance;", - "\n ", "\n private IEnumerable ParsedIdentities => GetScope(Identity).Values.Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity});", - "\n ", "\n private IEnumerable rawVariableNovelties => GetStorage().GetRawVariables(Identity).Select(rv => rv.Novelty).Distinct().Concat(Novelties.C.RepeatOnce());", - "\n", "\n private IEnumerable calculatedAocSteps => GetStorage().AocConfigurationByAocStep.Values.Where(x => new DataType[]{DataType.Calculated, DataType.CalculatedTelescopic}.Contains(x.DataType) &&", "\n (!isReinsurance ? !new []{AocTypes.CRU, AocTypes.RCU}.Contains(x.AocType) : true) && rawVariableNovelties.Contains(x.Novelty) ).Select(x => new AocStep(x.AocType, x.Novelty));", - "\n", "\n private IEnumerable SpecialIdentities => calculatedAocSteps.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity })", - "\n .Concat(new ImportIdentity {AocType = AocTypes.CF, Novelty = Novelties.C,DataNode = Identity}.RepeatOnce()) //Add CF for Deferral", + "\n .Concat(new ImportIdentity {AocType = AocTypes.CF, Novelty = Novelties.C,DataNode = Identity}.RepeatOnce()) //Add CF for Deferral - ", + "\n //.Concat(GetStorage().)", "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Opening).Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity}));//Add BOP,I and IA,I", "\n", "\n IEnumerable GetIdentities.allIdentities => ParsedIdentities.Concat(SpecialIdentities).Distinct(); ", @@ -257,32 +254,35 @@ { "cell_type": "code", "source": [ - "public interface ParentAocStep : IScope<(ImportIdentity Id, string AmountType), ImportStorage>", - "\n{", - "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", - "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.AmountType != AmountTypes.CDR));", - "\n ", - "\n private IEnumerable ParsedAocSteps => GetScope(Identity.Id.DataNode).Values;", - "\n private IEnumerable OrderedParsedAocSteps => ParsedAocSteps.Concat(CalculatedTelescopicAocStep).OrderBy(x => GetStorage().AocConfigurationByAocStep[x].Order);", + "// public interface ParentAocStep : IScope<(ImportIdentity Id, string AmountType), ImportStorage>", + "\n// {", + "\n// static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", + "\n// builder.ForScope(s => s.WithApplicability(x => x.Identity.AmountType != AmountTypes.CDR));", "\n ", - "\n private Dictionary> ParentParsedIdentities => GetPreviousIdentities(OrderedParsedAocSteps);", - "\n private AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", + "\n// private IEnumerable ParsedAocSteps => GetScope(Identity.Id.DataNode).Values;", + "\n// //private ", + "\n// IEnumerable OrderedParsedAocSteps => ParsedAocSteps.Concat(CalculatedTelescopicAocStep).OrderBy(x => GetStorage().AocConfigurationByAocStep[x].Order);", "\n ", - "\n IEnumerable CalculatedTelescopicAocStep => GetStorage().GetCalculatedTelescopicAocSteps();", + "\n// //private ", + "\n// Dictionary> ParentParsedIdentities => GetPreviousIdentities(OrderedParsedAocSteps, GetStorage().GetNovelties());", + "\n// //private ", + "\n// AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", "\n ", - "\n IEnumerable Values => ", - "\n Identity.Id.AocType switch {", - "\n AocTypes.CRU => new AocStep(AocTypes.YCU, Novelties.I).RepeatOnce(),", - "\n AocTypes.YCU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep).RepeatOnce(),", - "\n _ => ParentParsedIdentities.TryGetValue(identityAocStep, out var parents) ? parents : Enumerable.Empty(),", - "\n };", - "\n}", + "\n// IEnumerable CalculatedTelescopicAocStep => GetStorage().GetCalculatedTelescopicAocSteps();", + "\n// // calculated step => empty, _ => PreviousAocSteps, Ordered, last not calculated (but calc telescopic)", + "\n// IEnumerable Values => ", + "\n// Identity.Id.AocType switch {", + "\n// AocTypes.CRU => new AocStep(AocTypes.YCU, Novelties.I).RepeatOnce(),", + "\n// AocTypes.YCU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep).RepeatOnce(),", + "\n// _ => ParentParsedIdentities.TryGetValue(identityAocStep, out var parents) ? parents : Enumerable.Empty(),", + "\n// };", + "\n// }", "\n", - "\npublic interface ParentAocStepForCreditRisk : ParentAocStep", - "\n{", - "\n IEnumerable ParentAocStep.CalculatedTelescopicAocStep => ", - "\n GetStorage().GetCalculatedTelescopicAocSteps().Where(aoc => aoc.AocType != AocTypes.CRU);", - "\n}" + "\n// public interface ParentAocStepForCreditRisk : ParentAocStep", + "\n// {", + "\n// IEnumerable ParentAocStep.CalculatedTelescopicAocStep => ", + "\n// GetStorage().GetCalculatedTelescopicAocSteps().Where(aoc => aoc.AocType != AocTypes.CRU);", + "\n// }" ], "metadata": {}, "execution_count": 0, @@ -321,9 +321,12 @@ "source": [ "public interface ReferenceAocStep : IScope ", "\n{", - "\n private IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", - "\n private AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", - "\n private AocStep GetReferenceAocStep(string aocType) {", + "\n // private ", + "\n IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", + "\n // private ", + "\n AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", + "\n // private ", + "\n AocStep GetReferenceAocStep(string aocType) { //TODO return Enumerable", "\n return aocType switch {", "\n AocTypes.RCU or AocTypes.CF or AocTypes.IA or AocTypes.YCU or AocTypes.CRU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep),", "\n AocTypes.EA => new AocStep(AocTypes.CF, Identity.Novelty),", @@ -377,13 +380,14 @@ "source": [ "public interface PreviousAocSteps : IScope<(ImportIdentity Id, InputSource ScopeInputSource), ImportStorage> ", "\n{ ", - "\n private AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", - "\n private int aocStepOrder => GetStorage().AocConfigurationByAocStep[identityAocStep].Order;", - "\n private HashSet allAocSteps => GetStorage().GetAllAocSteps(Identity.ScopeInputSource).ToHashSet();", + "\n // private ", + "\n AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", + "\n // private ", + "\n int aocStepOrder => GetStorage().AocConfigurationByAocStep[identityAocStep].Order;", + "\n // private ", + "\n HashSet allAocSteps => GetStorage().GetAllAocSteps(Identity.ScopeInputSource).ToHashSet();", "\n IEnumerable Values => allAocSteps.Contains(identityAocStep)", - "\n ? GetScope(Identity.Id.DataNode).Identities", - "\n .Select(id => new AocStep(id.AocType, id.Novelty))", - "\n .Distinct()", + "\n ? GetScope(Identity.Id.DataNode).Identities.Select(id => new AocStep(id.AocType, id.Novelty)).Distinct()", "\n .Where(aoc => allAocSteps.Contains(aoc) && ", "\n GetStorage().AocConfigurationByAocStep[aoc].Order < aocStepOrder && ", "\n (Identity.Id.Novelty != Novelties.C ? aoc.Novelty == Identity.Id.Novelty : true) )", @@ -398,7 +402,38 @@ { "cell_type": "markdown", "source": [ - "The exact structure being return depends on the **order** of the AoC Steps (which is set by the [AoC Type](../DataModel/DataStructure#aoc-type)), and on which AoC steps exist." + "The exact structure being return depends on the **order** of the AoC Steps (which is set by the [AoC Step Configuration](../DataModel/DataStructure#aoc-configuration)), and on which AoC steps exist." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface ParentAocStep : IScope<(ImportIdentity Id, string AmountType, InputSource ScopeInputSource), ImportStorage>", + "\n{", + "\n // calculated step => empty, _ => PreviousAocSteps, Ordered, last not calculated (but calc telescopic)", + "\n IEnumerable CalculatedAocStep => GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType.Contains(DataType.Calculated)).Select(kvp => kvp.Key);", + "\n // private ", + "\n IEnumerable PreviousAocSteps => GetScope((Identity.Id, Identity.ScopeInputSource)).Values;", + "\n", + "\n", + "\n // private ", + "\n IEnumerable TelescopicStepToBeRemoved => Identity.AmountType == AmountTypes.CDR ? Enumerable.Empty() : GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.AocType == AocTypes.CRU).Select(kvp => kvp.Key);", + "\n // private ", + "\n IEnumerable PreviousAocStepsNotCalculated => PreviousAocSteps.Where(aoc => !CalculatedAocStep.Concat(TelescopicStepToBeRemoved).Contains(aoc));", + "\n // private ", + "\n bool IsFirstCombinedStep => Identity.Id.Novelty == Novelties.C && !PreviousAocStepsNotCalculated.Any(aoc => aoc.Novelty == Novelties.C);", + "\n // private ", + "\n bool IsCalculatedStep => CalculatedAocStep.Contains(new AocStep(Identity.Id.AocType, Identity.Id.Novelty));//Would be nice to use Identity.AocStep", + "\n", + "\n IEnumerable Values => (Identity.Id.AocType == AocTypes.BOP || IsCalculatedStep, IsFirstCombinedStep) switch {", + "\n (true, _ ) => Enumerable.Empty(),", + "\n (false, true) => PreviousAocStepsNotCalculated.GroupBy(g => g.Novelty, (g, val) => val.Last()),", + "\n (false, false) => PreviousAocStepsNotCalculated.Last(aoc => aoc.Novelty == Identity.Id.Novelty).RepeatOnce(),", + "\n };", + "\n}" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 90ca4e06..5cc0824d 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -344,7 +344,7 @@ "\n string EconomicBasis => GetContext();", "\n private double[] CurrentValues => GetScope(Identity).Values;", "\n ", - "\n private double[] PreviousValues => (GetScope((Identity.Id, Identity.AmountType)))", + "\n private double[] PreviousValues => (GetScope((Identity.Id, Identity.AmountType, InputSource.Cashflow)))", "\n .Values", "\n .Select(aoc => GetScope((Identity.Id with {AocType = aoc.AocType, Novelty = aoc.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.Accidentyear)).Values)", "\n .Where(cf => cf.Count() > 0)", diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index bd518ecd..400a12d5 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -59,27 +59,27 @@ "\nstring canonicalAocConfig = ", "\n@\"@@AocConfiguration,,,,,,,,,,,", "\nAocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month", - "\nBOP,I,Optional,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1", - "\nMC,I,Optional,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1", - "\nRCU,I,Calculated,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1", - "\nCF,I,Calculated,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1", - "\nIA,I,Calculated,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1", - "\nAU,I,Optional,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1", - "\nYCU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1", - "\nCRU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1", - "\nEV,I,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1", - "\nBOP,N,Optional,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,95,1900,1", - "\nMC,N,Optional,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,100,1900,1", - "\nCF,N,Calculated,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1", - "\nIA,N,Calculated,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", - "\nAU,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", - "\nEV,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", - "\nCF,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1", - "\nWO,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1", - "\nCL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", - "\nEA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", - "\nAM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", - "\nEOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" + "\nBOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1", + "\nMC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1", + "\nRCU,I,4,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1", + "\nCF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1", + "\nIA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1", + "\nAU,I,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1", + "\nYCU,I,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1", + "\nCRU,I,8,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1", + "\nEV,I,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1", + "\nBOP,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,95,1900,1", + "\nMC,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,100,1900,1", + "\nCF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1", + "\nIA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", + "\nAU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", + "\nEV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1", + "\nWO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1", + "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", + "\nEA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", + "\nAM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", + "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 28a9fe07..22ef051f 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -46,11 +46,10 @@ { "cell_type": "code", "source": [ - "public static Dictionary> GetPreviousIdentities(IEnumerable aocSteps)", + "public static Dictionary> GetPreviousIdentities(IEnumerable aocSteps, IEnumerable novelties)", "\n{", "\n var bopNovelties = aocSteps.Where(id => id.AocType == AocTypes.BOP).Select(id => id.Novelty);", - "\n var previousStep = (new string[]{Novelties.N,Novelties.I,Novelties.C})", - "\n .ToDictionary(n => n, n => bopNovelties.Contains(n) ? new AocStep(AocTypes.BOP,n) : null);", + "\n var previousStep = novelties.ToDictionary(n => n, n => bopNovelties.Contains(n) ? new AocStep(AocTypes.BOP,n) : null);", "\n return aocSteps.Where(id => id.AocType != AocTypes.BOP)", "\n .ToDictionary(x => x, ", "\n x => {var isFirstCombined = x.Novelty == Novelties.C && (previousStep[Novelties.C] == null || previousStep[Novelties.C].AocType == AocTypes.BOP);", From 0605bc1a1eff195ca20667ba3096ec1730a44b67 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Fri, 7 Jul 2023 18:35:00 +0200 Subject: [PATCH 04/24] dimension --- ifrs17-template/Files/Dimensions.csv | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ifrs17-template/Files/Dimensions.csv b/ifrs17-template/Files/Dimensions.csv index ebdf7f14..81498bcb 100644 --- a/ifrs17-template/Files/Dimensions.csv +++ b/ifrs17-template/Files/Dimensions.csv @@ -45,27 +45,27 @@ EOP,Closing Balance,,170,,,,,,,, ,,,,,,,,,,, @@AocConfiguration,,,,,,,,,,, AocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month -BOP,I,Optional,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1 -MC,I,Optional,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1 -RCU,I,Calculated,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1 -CF,I,Calculated,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1 -IA,I,Calculated,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1 -AU,I,Optional,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1 -YCU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1 -CRU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1 -EV,I,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1 -BOP,N,Optional,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,100,1900,1 -MC,N,Optional,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,105,1900,1 -CF,N,Calculated,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1 -IA,N,Calculated,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1 -AU,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1 -EV,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1 -CF,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1 -WO,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1 -CL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1 -EA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1 -AM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1 -EOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1 +BOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1 +MC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1 +RCU,I,4,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1 +CF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1 +IA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1 +AU,I,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1 +YCU,I,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1 +CRU,I,8,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1 +EV,I,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1 +BOP,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,100,1900,1 +MC,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,105,1900,1 +CF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1 +IA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1 +AU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1 +EV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1 +CF,C,5,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1 +WO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1 +CL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1 +EA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1 +AM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1 +EOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1 ,,,,,,,,,,, @@CreditRiskRating,,,,,,,,,,, SystemName,DisplayName,,,,,,,,,, From 7389d93b5d579a114b8f3e67050e45af0ecdea71 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 11 Jul 2023 11:04:59 +0200 Subject: [PATCH 05/24] dimension --- ifrs17-template/Files/Dimensions.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ifrs17-template/Files/Dimensions.csv b/ifrs17-template/Files/Dimensions.csv index 81498bcb..e19aef07 100644 --- a/ifrs17-template/Files/Dimensions.csv +++ b/ifrs17-template/Files/Dimensions.csv @@ -60,10 +60,10 @@ CF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1 IA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1 AU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1 EV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1 -CF,C,5,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1 -WO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1 CL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1 EA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1 +CF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,193,1900,1 +WO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,195,1900,1 AM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1 EOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1 ,,,,,,,,,,, From 0790e195836e6378583f55d5f055db3308c061f7 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 11 Jul 2023 11:06:28 +0200 Subject: [PATCH 06/24] scopes and tests --- ifrs17/Import/1ImportScope-Identities.ipynb | 84 ++- ifrs17/Import/2ImportScope-PresentValue.ipynb | 15 +- ifrs17/Import/3ImportScope-Actuals.ipynb | 6 +- .../Import/4ImportScope-TechnicalMargin.ipynb | 2 +- ifrs17/Test/AocStructureTest.ipynb | 480 +++++++++++++----- ifrs17/Test/TechnicalMarginTest.ipynb | 56 +- ifrs17/Test/TestData.ipynb | 4 +- 7 files changed, 466 insertions(+), 181 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index cffee20a..acbf1e77 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -154,11 +154,9 @@ "\n private bool isReinsurance => GetStorage().DataNodeDataBySystemName[Identity].IsReinsurance;", "\n private IEnumerable ParsedIdentities => GetScope(Identity).Values.Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity});", "\n private IEnumerable rawVariableNovelties => GetStorage().GetRawVariables(Identity).Select(rv => rv.Novelty).Distinct().Concat(Novelties.C.RepeatOnce());", - "\n private IEnumerable calculatedAocSteps => GetStorage().AocConfigurationByAocStep.Values.Where(x => new DataType[]{DataType.Calculated, DataType.CalculatedTelescopic}.Contains(x.DataType) &&", + "\n private IEnumerable calculatedAocSteps => GetStorage().AocConfigurationByAocStep.Values.Where(x => (x.DataType.Contains(DataType.Calculated) || x.DataType.Contains(DataType.CalculatedTelescopic) ) &&", "\n (!isReinsurance ? !new []{AocTypes.CRU, AocTypes.RCU}.Contains(x.AocType) : true) && rawVariableNovelties.Contains(x.Novelty) ).Select(x => new AocStep(x.AocType, x.Novelty));", "\n private IEnumerable SpecialIdentities => calculatedAocSteps.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity })", - "\n .Concat(new ImportIdentity {AocType = AocTypes.CF, Novelty = Novelties.C,DataNode = Identity}.RepeatOnce()) //Add CF for Deferral - ", - "\n //.Concat(GetStorage().)", "\n .Concat(GetStorage().GetAllAocSteps(InputSource.Opening).Select(aocStep => new ImportIdentity {AocType = aocStep.AocType, Novelty = aocStep.Novelty, DataNode = Identity}));//Add BOP,I and IA,I", "\n", "\n IEnumerable GetIdentities.allIdentities => ParsedIdentities.Concat(SpecialIdentities).Distinct(); ", @@ -319,29 +317,33 @@ { "cell_type": "code", "source": [ - "public interface ReferenceAocStep : IScope ", - "\n{", - "\n // private ", - "\n IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", - "\n // private ", - "\n AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", - "\n // private ", - "\n AocStep GetReferenceAocStep(string aocType) { //TODO return Enumerable", - "\n return aocType switch {", - "\n AocTypes.RCU or AocTypes.CF or AocTypes.IA or AocTypes.YCU or AocTypes.CRU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep),", - "\n AocTypes.EA => new AocStep(AocTypes.CF, Identity.Novelty),", - "\n AocTypes.AM or AocTypes.EOP => new AocStep(AocTypes.CL, Novelties.C),", - "\n AocTypes.BOP => GetStorage().GetShift(Identity.ProjectionPeriod) >= MonthInAYear && Identity.Novelty == Novelties.I ? new AocStep(AocTypes.CL, Novelties.C) : new AocStep(default, default), //BOP, C has DataType == Calculated. See ReferenceAocStep condition.", - "\n _ => (AocStep)ApplicationMessage.Log(Error.NotSupportedAocStepReference, Identity.AocType),", - "\n };", - "\n }", + "// public interface ReferenceAocStep : IScope ", + "\n// {", + "\n// // private ", + "\n// IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", + "\n// // private ", + "\n// AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", + "\n// // private ", + "\n// AocStep GetReferenceAocStep(string aocType) { //TODO return Enumerable + rewrite without hardcoding: use previous filtered for NotCalculated or !Optional+Mandatory steps (?)", + "\n// return aocType switch {", + "\n// AocTypes.RCU or AocTypes.CF or AocTypes.IA or AocTypes.YCU or AocTypes.CRU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep),", + "\n// AocTypes.EA => new AocStep(AocTypes.CF, Identity.Novelty),", + "\n// AocTypes.AM or AocTypes.EOP => new AocStep(AocTypes.CL, Novelties.C),", + "\n// AocTypes.BOP => GetStorage().GetShift(Identity.ProjectionPeriod) >= MonthInAYear && Identity.Novelty == Novelties.I ", + "\n// ? new AocStep(AocTypes.CL, Novelties.C) ", + "\n// : new AocStep(default, default), //BOP, C has DataType == Calculated. See ReferenceAocStep condition.", + "\n// _ => (AocStep)ApplicationMessage.Log(Error.NotSupportedAocStepReference, Identity.AocType),", + "\n// };", + "\n// }", + "\n// //Calculated steps with Format.Cashflow => prev not calculated. Else take it from a dictionary", "\n", - "\n // The Reference AocStep from which get data (Nominal or PV) to compute", - "\n AocStep Value => GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated ", - "\n || GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic ", - "\n ? GetReferenceAocStep(Identity.AocType)", - "\n : identityAocStep;", - "\n}" + "\n", + "\n// // The Reference AocStep from which get data (Nominal or PV) to compute", + "\n// AocStep Value => GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated || ", + "\n// GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic ", + "\n// ? GetReferenceAocStep(Identity.AocType)", + "\n// : identityAocStep;", + "\n// }" ], "metadata": {}, "execution_count": 0, @@ -439,6 +441,38 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "public interface ReferenceAocStep : IScope ", + "\n{", + "\n // private ", + "\n //IEnumerable PreviousAocSteps => GetScope((Identity.Id, Identity.ScopeInputSource)).Values;", + "\n IEnumerable PreviousAocSteps => GetScope((Identity, InputSource.Cashflow)).Values;", + "\n private AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", + "\n // The Reference AocStep from which get data (Nominal or PV) to compute", + "\n IEnumerable Values => ( GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated ||", + "\n GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic, ", + "\n myDict.TryGetValue(identityAocStep, out var ret) ) switch {", + "\n (true, false) => PreviousAocSteps.GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", + "\n && GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic)),", + "\n (true, true) => ret,", + "\n (false, _) => identityAocStep.RepeatOnce(),", + "\n };", + "\n //IEnumerable GetFromMyDict(AocStep identityAocStep) => myDict.TryGetValue(identityAocStep, out var ret) ? ret : new AocStep(default,default).RepeatOnce();", + "\n Dictionary> myDict => new Dictionary>()", + "\n {", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")}},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")}}, ", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")}}, ", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"CL\",\"C\")}},//projections", + "\n };", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 5cc0824d..49bbfb04 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -168,14 +168,16 @@ "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", "\n .WithApplicability(x => x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty == Novelties.I));", "\n", - "\n AocStep referenceAocStep => GetScope(Identity.Id).Value;", - "\n double[] Values => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.AccidentYear);", + "\n IEnumerable referenceAocSteps => GetScope(Identity.Id).Values;", + "\n double[] Values => referenceAocSteps.Select(refAocStep => GetStorage().GetValues(Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.AccidentYear))", + "\n .AggregateDoubleArray();", "\n}", "\n", "\npublic interface CreditDefaultRiskNominalCashflow : NominalCashflow", "\n{", - "\n private double[] NominalClaimsCashflow => GetStorage().GetClaims()", - "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))", + "\n private double[] NominalClaimsCashflow => referenceAocSteps.SelectMany(refAocStep =>", + "\n GetStorage().GetClaims()", + "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear)))", "\n .AggregateDoubleArray();", "\n ", "\n private string cdrBasis => Identity.AmountType == AmountTypes.CDR ? EconomicBases.C : EconomicBases.L;", @@ -192,8 +194,9 @@ "\n", "\npublic interface AllClaimsCashflow : NominalCashflow", "\n{", - "\n double[] NominalCashflow.Values => GetStorage().GetClaims()", - "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))", + "\n double[] NominalCashflow.Values => referenceAocSteps.SelectMany(refAocStep =>", + "\n GetStorage().GetClaims()", + "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear)))", "\n .AggregateDoubleArray();", "\n}", "\n", diff --git a/ifrs17/Import/3ImportScope-Actuals.ipynb b/ifrs17/Import/3ImportScope-Actuals.ipynb index 241ef5f9..e6e485a9 100644 --- a/ifrs17/Import/3ImportScope-Actuals.ipynb +++ b/ifrs17/Import/3ImportScope-Actuals.ipynb @@ -439,7 +439,7 @@ "\n}", "\n", "\npublic interface DeferrableEa : DiscountedDeferrable {", - "\n private string referenceAocType => GetScope(Identity).Value.AocType;", + "\n private string referenceAocType => GetScope(Identity).Values.FirstOrDefault().AocType;", "\n double DiscountedDeferrable.Value => GetStorage().GetDeferrableExpenses().Sum(at =>", "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow)", "\n .Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) -", @@ -556,8 +556,8 @@ "\n}", "\n", "\npublic interface AmDeferrable : NominalDeferrable{", - "\n private AocStep referenceAocStep => GetScope(Identity.Id).Value; //CL,C", - "\n private double referenceCashflow => GetScope((Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, Identity.MonthlyShift)).Value;", + "\n private IEnumerable referenceAocSteps => GetScope(Identity.Id).Values; //CL,C", + "\n private double referenceCashflow => referenceAocSteps.Sum(refAocStep => GetScope((Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.MonthlyShift)).Value);", "\n", "\n double NominalDeferrable.Value => -1d * referenceCashflow * GetScope((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value;", "\n}", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index eaec870f..50025e4b 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -315,7 +315,7 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilderInner(ApplicabilityBuilder builder) => ", "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.IsReinsurance));", "\n ", - "\n private string referenceAocType => GetScope(Identity).Value.AocType;", + "\n private string referenceAocType => GetScope(Identity).Values.FirstOrDefault().AocType;", "\n ", "\n private double premiums => GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow)", "\n .Sum(n => GetScope(Identity with {AocType = referenceAocType, Novelty = n}).ByAmountType.Sum(sc => sc.Value)) -", diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index 500ca1b2..a103ff47 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -55,9 +55,12 @@ { "cell_type": "code", "source": [ - "await Import.FromString(novelties).WithType().WithTarget(DataSource).ExecuteAsync();", - "\nawait Import.FromString(canonicalAocTypes).WithType().WithTarget(DataSource).ExecuteAsync();", - "\nawait Import.FromString(canonicalAocConfig).WithFormat(ImportFormats.AocConfiguration).WithTarget(DataSource).ExecuteAsync();" + "await DataSource.DeleteAsync(DataSource.Query());", + "\nawait DataSource.DeleteAsync(DataSource.Query());", + "\n", + "\n((await Import.FromString(novelties).WithType().WithTarget(DataSource).ExecuteAsync()).Status,", + "\n(await Import.FromString(canonicalAocTypes).WithType().WithTarget(DataSource).ExecuteAsync()).Status,", + "\n(await Import.FromString(canonicalAocConfig).WithFormat(ImportFormats.AocConfiguration).WithTarget(DataSource).ExecuteAsync()).Status)" ], "metadata": {}, "execution_count": 0, @@ -136,7 +139,7 @@ "source": [ "public async Task CheckAocStepStructureAsync(IEnumerable inputVariables, ", "\n Dictionary> parentBm, ", - "\n Dictionary referenceBm, ", + "\n Dictionary> referenceBm, ", "\n Dictionary> fullAocBm,", "\n Dictionary> parentBmCdr = null)", "\n{", @@ -174,7 +177,7 @@ "\n //Assert Parents", "\n if (importFormat != ImportFormats.Actual)", "\n {", - "\n var parents = testUniverse.GetScopes(identities.Select(id => (object)(id, \"PR\")), o => o.WithStorage(testStorage)).Where(x => x.Values != Enumerable.Empty()).ToArray();", + "\n var parents = testUniverse.GetScopes(identities.Select(id => (object)(id, \"PR\",inputSource)), o => o.WithStorage(testStorage)).Where(x => x.Values.Any()).ToArray();", "\n if (parentBm.Count() != parents.Count()) ", "\n {", "\n var computedIds = parents.Select(s => $\"AocType:{s.Identity.Id.AocType}, Novelty:{s.Identity.Id.Novelty}\");", @@ -201,9 +204,9 @@ "\n //Parents for CDR", "\n if(isReinsurance)", "\n {", - "\n var parentsCdr = testUniverse.GetScopes(identities.Select(id => (object)(id, AmountTypes.CDR)), o => o.WithStorage(testStorage));", + "\n var parentsCdr = testUniverse.GetScopes(identities.Select(id => (object)(id, AmountTypes.CDR,inputSource)), o => o.WithStorage(testStorage));", "\n ", - "\n var countP = parentsCdr.Where(x => x.Values != Enumerable.Empty()).Count();", + "\n var countP = parentsCdr.Where(x => x.Values.Any()).Count();", "\n if (parentBmCdr.Count() != countP) ", "\n errors.Add( $\"Parent count for AmountType CDR does not match expected: \\n Computed {countP} \\n Expected {parentBm.Count()}.\" );", "\n ", @@ -229,19 +232,26 @@ "\n if (importFormat != ImportFormats.Actual)", "\n {", "\n var reference = testUniverse.GetScopes(identities, o => o.WithStorage(testStorage)).ToArray();", - "\n var countR = reference.Select(x => x.Value).Count();", + "\n var countR = reference.Select(x => x.Values).Count();", "\n if (referenceBm.Count() != countR) ", "\n errors.Add( $\"Reference count does not match expected: \\n Computed {countR} \\n Expected {referenceBm.Count()}.\" );", "\n ", "\n foreach(var kvp in referenceBm)", "\n {", "\n var scopeReferences = reference.Where(y => y.Identity.AocType == kvp.Key.AocType && y.Identity.Novelty == kvp.Key.Novelty);", - "\n if(scopeReferences.Count() != 1)", + "\n if(!scopeReferences.Any())", "\n errors.Add( $\"Reference not found for AocStep: {kvp.Key.AocType}, {kvp.Key.Novelty}.\");", "\n else{", "\n var scopeReference = scopeReferences.First();", - "\n if( kvp.Value.AocType != scopeReference.Value.AocType || kvp.Value.Novelty != scopeReference.Value.Novelty )", - "\n errors.Add( $\"Reference of {kvp.Key.AocType}, {kvp.Key.Novelty} do not match expected value: \\n Computed {scopeReference.Value} \\n Expected {kvp.Value}.\" );", + "\n if( kvp.Value.Intersect(scopeReference.Values).Count() != kvp.Value.Count() || ", + "\n kvp.Value.Intersect(scopeReference.Values).Count() != scopeReference.Values.Count() ){", + "\n var computedAocSteps = scopeReference.Values.Select(aoc => $\"AocType:{aoc.AocType}, Novelty:{aoc.Novelty}\");", + "\n var expectedAocSteps = kvp.Value.Select(aoc => $\"AocType:{aoc.AocType}, Novelty:{aoc.Novelty}\"); ", + "\n errors.Add( $\"Reference of {kvp.Key.AocType}, {kvp.Key.Novelty} do not match expected value: \\n Computed: \\n {string.Join(\"\\n\", computedAocSteps)} \\n Expected: \\n {string.Join(\"\\n\", expectedAocSteps)}.\" );", + "\n }", + "\n", + "\n // if( kvp.Value.AocType != scopeReference.Value.First().AocType || kvp.Value.Novelty != scopeReference.Value.First().Novelty ) //TODO FIrst are wrong here", + "\n // errors.Add( $\"Reference of {kvp.Key.AocType}, {kvp.Key.Novelty} do not match expected value: \\n Computed {scopeReference.Value} \\n Expected {kvp.Value}.\" );", "\n }", "\n }", "\n }", @@ -256,8 +266,7 @@ "\n errors.Add( $\"Full AoC count does not match expected: \\n Computed {count} \\n Expected {fullAocBm.Count()}.\" ); ", "\n errors.Add( $\"In particular, \\n Computed Identities \\n {string.Join(\"\\n\", computedAocSteps)} \\n Expected \\n {string.Join(\"\\n\", benchmarkKeys)}.\" ); ", "\n }", - "\n ", - "\n foreach(var kvp in fullAocBm)", + "\n else foreach(var kvp in fullAocBm)", "\n {", "\n var scopeAocFulls = fullAoc.Where(y => y.Identity.Id.AocType == kvp.Key.AocType && y.Identity.Id.Novelty == kvp.Key.Novelty);", "\n if(scopeAocFulls.Count() != 1){", @@ -333,22 +342,22 @@ { "cell_type": "code", "source": [ - "var referenceBm = new Dictionary()", + "var referenceBm = new Dictionary>()", "\n {", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep(\"BOP\",\"I\")},", - "\n {new AocStep(\"MC\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"CF\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"IA\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"YCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"BOP\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"CF\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"IA\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"EV\",\"N\"), new AocStep(\"EV\",\"N\")},", - "\n {new AocStep(\"CL\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EA\",\"C\"), new AocStep(\"CF\",\"C\")},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep(\"CF\",\"C\")},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} }, ", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"EV\",\"N\")} },", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")} },", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")} },", "\n };" ], "metadata": {}, @@ -369,7 +378,7 @@ "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\")}},", - "\n ", + "\n", "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", "\n }},", @@ -377,15 +386,18 @@ "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", "\n new AocStep(\"CL\",\"C\"),", "\n }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),}},", "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", - "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"CF\",\"C\")", "\n }},", + "\n", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", - "\n new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", "\n }},", - "\n //{new AocStep(\"CF\",\"C\"), Enumerable.Empty()},", "\n };", "\n" ], @@ -471,24 +483,24 @@ { "cell_type": "code", "source": [ - "referenceBm = new Dictionary()", + "referenceBm = new Dictionary>()", "\n {", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep(\"BOP\",\"I\")},", - "\n {new AocStep(\"MC\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"RCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"CF\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"IA\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"YCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"CRU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"BOP\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"CF\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"IA\",\"N\"), new AocStep(\"BOP\",\"N\")},", - "\n {new AocStep(\"EV\",\"N\"), new AocStep(\"EV\",\"N\")},", - "\n {new AocStep(\"CL\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EA\",\"C\"), new AocStep(\"CF\",\"C\")},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep(\"CF\",\"C\")},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"RCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"CRU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"EV\",\"N\") }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", "\n };" ], "metadata": {}, @@ -511,7 +523,6 @@ "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\")}},", - "\n ", "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"RCU\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"CRU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", "\n }},", @@ -519,16 +530,17 @@ "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", "\n new AocStep(\"CL\",\"C\"),", "\n }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"RCU\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),}},", "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"RCU\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"),new AocStep(\"YCU\",\"I\"), new AocStep(\"CRU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", - "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),", "\n }},", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"RCU\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"),new AocStep(\"YCU\",\"I\"), new AocStep(\"CRU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", - "\n new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", - "\n }},", - "\n //{new AocStep(\"CF\",\"C\"), Enumerable.Empty()},", - "\n ", + "\n new AocStep(\"CF\",\"C\"),new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n }}, ", "\n };" ], "metadata": {}, @@ -595,19 +607,19 @@ { "cell_type": "code", "source": [ - "referenceBm = new Dictionary()", + "referenceBm = new Dictionary>()", "\n {", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep(\"BOP\",\"I\")},", - "\n {new AocStep(\"MC\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"CF\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"IA\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"YCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"EV\",\"I\"), new AocStep(\"EV\",\"I\")}, ", - "\n {new AocStep(\"CL\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EA\",\"C\"), new AocStep(\"CF\",\"C\")},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep(\"CF\",\"C\")},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"EV\",\"I\"), new AocStep[]{new AocStep(\"EV\",\"I\") }}, ", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", "\n };" ], "metadata": {}, @@ -625,16 +637,17 @@ "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\")}},", "\n {new AocStep(\"EV\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\")}},", - "\n ", + "\n ", "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"I\"),", "\n }},", - "\n ", "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"I\"),", - "\n new AocStep(\"CL\",\"C\"),}},", + "\n new AocStep(\"CL\",\"C\"),}},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"I\"),", + "\n new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"),}},", "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"I\"),", - "\n new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"),}},", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"),}},", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"I\"),", - "\n new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"),}},", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"),}},", "\n //{new AocStep(\"CF\",\"C\"), Enumerable.Empty()},", "\n };" ], @@ -685,27 +698,27 @@ "string newAocConfig = ", "\n@\"@@AocConfiguration,,,,,,,,,,,", "\nAocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month", - "\nBOP,I,Optional,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1", - "\nMC,I,Optional,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1", - "\nRCU,I,Calculated,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1", - "\nCF,I,Calculated,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1", - "\nIA,I,Calculated,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1", - "\nAU,I,Optional,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1", - "\nYCU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1", - "\nCRU,I,CalculatedTelescopic,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1", - "\nEV,I,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1", - "\nBOP,N,Optional,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,95,1900,1", - "\nCF,N,Calculated,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1", - "\nIA,N,Calculated,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", - "\nAU,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", - "\nEV,N,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", - "\nCF,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1", - "\nWO,C,Optional,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1", - "\nEV,C,Optional,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,175,1900,1", - "\nCL,C,Mandatory,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", - "\nEA,C,Calculated,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", - "\nAM,C,Calculated,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", - "\nEOP,C,Calculated,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" + "\nBOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1", + "\nMC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1", + "\nRCU,I,4,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1", + "\nCF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1", + "\nIA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1", + "\nAU,I,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1", + "\nYCU,I,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1", + "\nCRU,I,8,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1", + "\nEV,I,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1", + "\nBOP,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,95,1900,1", + "\nCF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1", + "\nIA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", + "\nAU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", + "\nEV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", + "\nEV,C,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,175,1900,1", + "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", + "\nEA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,192,1900,1", + "\nWO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,195,1900,1", + "\nAM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", + "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], "metadata": {}, "execution_count": 0, @@ -762,19 +775,20 @@ { "cell_type": "code", "source": [ - "referenceBm = new Dictionary()", + "referenceBm = new Dictionary>()", "\n {", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep(\"BOP\",\"I\")},", - "\n {new AocStep(\"MC\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"CF\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"IA\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"YCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"EV\",\"C\"), new AocStep(\"EV\",\"C\")},", - "\n {new AocStep(\"CL\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EA\",\"C\"), new AocStep(\"CF\",\"C\")},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep(\"CF\",\"C\")},", + "\n {new AocStep(\"BOP\",\"I\"),new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"YCU\",\"I\"),new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\") }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n ", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"),new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", "\n };" ], "metadata": {}, @@ -790,17 +804,20 @@ "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\")}},", "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\")}},", - "\n ", + "\n ", "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), ", "\n }},", "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", - "\n new AocStep(\"EV\",\"C\"),}},", + "\n new AocStep(\"EV\",\"C\"),}},", "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"),}},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), ", + "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"),}}, ", "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", - "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\")}},", + "\n new AocStep(\"CF\",\"C\"),new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\")}},", + "\n ", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", - "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\")}},", + "\n new AocStep(\"CF\",\"C\"),new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\")}},", "\n };" ], "metadata": {}, @@ -870,23 +887,23 @@ { "cell_type": "code", "source": [ - "referenceBm = new Dictionary()", + "referenceBm = new Dictionary>()", "\n {", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep(\"BOP\",\"I\")},", - "\n {new AocStep(\"MC\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"CF\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"IA\",\"I\"), new AocStep(\"MC\",\"I\")},", - "\n {new AocStep(\"YCU\",\"I\"), new AocStep(\"MC\",\"I\")}, ", - "\n {new AocStep(\"BOP\",\"N\"), new AocStep(\"BOP\",\"N\")}, ", - "\n {new AocStep(\"CF\",\"N\"), new AocStep(\"BOP\",\"N\")}, ", - "\n {new AocStep(\"IA\",\"N\"), new AocStep(\"BOP\",\"N\")}, ", - "\n {new AocStep(\"AU\",\"N\"), new AocStep(\"AU\",\"N\")}, ", - "\n {new AocStep(\"EV\",\"C\"), new AocStep(\"EV\",\"C\")},", - "\n {new AocStep(\"CL\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EA\",\"C\"), new AocStep(\"CF\",\"C\")},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep(\"CL\",\"C\")},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep(\"CF\",\"C\")},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"AU\",\"N\"), new AocStep[]{new AocStep(\"AU\",\"N\") }}, ", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\") }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", "\n };" ], "metadata": {}, @@ -906,7 +923,7 @@ "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\")}},", "\n {new AocStep(\"AU\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\")}},", - "\n", + "\n ", "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), ", "\n new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\"),new AocStep(\"AU\",\"N\"),", "\n }},", @@ -916,12 +933,15 @@ "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\"),new AocStep(\"AU\",\"N\"),", "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"),}},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"), ", "\n new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\"),new AocStep(\"AU\",\"N\"),", "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\")}},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\"),new AocStep(\"AU\",\"N\"),", + "\n new AocStep(\"CF\",\"C\"),new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\")}},", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", "\n new AocStep(\"BOP\",\"N\"),new AocStep(\"CF\",\"N\"),new AocStep(\"IA\",\"N\"),new AocStep(\"AU\",\"N\"),", - "\n new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\")}},", + "\n new AocStep(\"CF\",\"C\"),new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\")}},", "\n };" ], "metadata": {}, @@ -1013,9 +1033,9 @@ "fullAocBm = new Dictionary>()", "\n {", "\n //{new AocStep(\"BOP\",\"I\"), Enumerable.Empty()},", - "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),}},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), }},", "\n {new AocStep(\"WO\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"CF\",\"C\"),}},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"CF\",\"C\"), new AocStep(\"WO\",\"C\"),}},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"WO\",\"C\"),new AocStep(\"CF\",\"C\"),}},", "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"CF\",\"C\"), new AocStep(\"WO\",\"C\"), new AocStep(\"AM\",\"C\"),}},", "\n };" ], @@ -1042,6 +1062,206 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Add a Novelty" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Preparation" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "// await DataSource.DeleteAsync(DataSource.Query());", + "\n// await DataSource.DeleteAsync(DataSource.Query());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "// await DataSource.DeleteAsync(DataSource.Query());", + "\n// await DataSource.DeleteAsync(DataSource.Query());", + "\n// await Import.FromString(newAocTypes).WithType().WithTarget(DataSource).ExecuteAsync();", + "\n// await Import.FromString(newAocConfiguration).WithType().WithTarget(DataSource).ExecuteAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# New Aoc Configuration" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Preparation" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "string newAocTypes = ", + "\n@\"@@AocType", + "\nSystemName,DisplayName,Parent,Order", + "\nBOP,Opening Balance,,10", + "\nMC,Model Correction,,20", + "\nCF,Cash flow,,30", + "\nIA,Interest Accretion,,40", + "\nAU,Assumption Update,,50", + "\nYCU,Yield Curve Update,,60", + "\nEV,Experience Variance,,70", + "\nCL,Combined Liabilities,,80", + "\nAM,Amortization,,85", + "\nEOP,Closing Balance,,90\";", + "\n", + "\nstring newAocConfiguration = ", + "\n@\"@@AocConfiguration,,,,,,,,,,,", + "\nAocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month", + "\nBOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,2017,12", + "\nMC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,2017,12", + "\nCF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,30,2017,12", + "\nIA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,40,2017,12", + "\nBOP,N,1,4,Average,BeginningOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,50,2017,12", + "\nCF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,60,2017,12", + "\nIA,N,4,4,Average,BeginningOfPeriod,EndOfPeriod,Delta,EndOfPeriod,70,2017,12", + "\nAU,C,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,80,2017,12", + "\nYCU,C,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,90,2017,12", + "\nEV,C,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,100,2017,12", + "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,110,2017,12", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,115,2017,12", + "\nAM,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,120,2017,12", + "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,2017,12", + "\n\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.DeleteAsync(DataSource.Query());", + "\nawait DataSource.DeleteAsync(DataSource.Query());", + "\nawait Import.FromString(newAocTypes).WithType().WithTarget(DataSource).ExecuteAsync();", + "\nawait Import.FromString(newAocConfiguration).WithType().WithTarget(DataSource).ExecuteAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## UseCase" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var inputVariables = new RawVariable[]{", + "\n new RawVariable{AocType = \"BOP\", Novelty = \"N\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n new RawVariable{AocType = \"EV\", Novelty = \"C\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n new RawVariable{AocType = \"CL\", Novelty = \"C\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n};" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var parentBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"YCU\",\"C\")}},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\"),}},", + "\n };", + "\nvar referenceBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\") }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\") , new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"IA\",\"I\") , new AocStep[]{new AocStep(\"BOP\",\"I\") }},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\") }},", + "\n };", + "\nvar fullAocBm = new Dictionary>()", + "\n {", + "\n //{new AocStep(\"BOP\",\"N\"), Enumerable.Empty()},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", + "\n ", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n }},", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"YCU\",\"C\"),", + "\n }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\")", + "\n }}, ", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\")", + "\n }}, ", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"AM\",\"C\"),", + "\n }}, ", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckAocStepStructureAsync(inputVariables, parentBm, referenceBm, fullAocBm);", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Test/TechnicalMarginTest.ipynb b/ifrs17/Test/TechnicalMarginTest.ipynb index f18841c3..5e599287 100644 --- a/ifrs17/Test/TechnicalMarginTest.ipynb +++ b/ifrs17/Test/TechnicalMarginTest.ipynb @@ -332,9 +332,16 @@ "\n {new AocStep(\"EA\",\"C\"), (0d, -8.0)},", "\n {new AocStep(\"AM\",\"C\"), (0d, -153.5)},", "\n {new AocStep(\"EOP\",\"C\"),(0d, 153.5)},", - "\n };", - "\n", - "\nvar activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", "\nactivity" ], "metadata": {}, @@ -381,9 +388,16 @@ "\n {new AocStep(\"EA\",\"C\"), (8d, 0d)},", "\n {new AocStep(\"AM\",\"C\"), (-146.5d, 0d)},", "\n {new AocStep(\"EOP\",\"C\"),(146.5d, 0d)},", - "\n };", - "\n", - "\nvar activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", "\nactivity" ], "metadata": {}, @@ -426,8 +440,16 @@ "\n {new AocStep(\"EA\",\"C\"), (8d, 0d)},", "\n {new AocStep(\"AM\",\"C\"), (-29d, 0d)},", "\n {new AocStep(\"EOP\",\"C\"),(29d, 0d)},", - "\n };", - "\n", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "", "\nvar activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", "\nactivity" ], @@ -486,9 +508,16 @@ "\n {new AocStep(\"EA\",\"C\"), ( -8d, 0d)},", "\n {new AocStep(\"AM\",\"C\"), ( -11d, 0d)},", "\n {new AocStep(\"EOP\",\"C\"),( 11d, 0d)},", - "\n };", - "\n", - "\nvar activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckSwitchLogicAsync(inputDataSet, csmLcSwitch_benchmark);", "\nactivity" ], "metadata": {}, @@ -549,8 +578,7 @@ "\n {new AocStep(\"CL\",\"C\"), (+30d, 0d)},", "\n {new AocStep(\"AM\",\"C\"), (+30d, 0d)},", "\n {new AocStep(\"EOP\",\"C\"),(-30d, 0d)},", - "\n };", - "\n" + "\n };" ], "metadata": {}, "execution_count": 0, @@ -589,7 +617,7 @@ "source": [ "var reinsBasicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfReinsuranceContracts, AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\", EconomicBasis = \"L\"};", "\nvar grossBasicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\", EconomicBasis = \"L\"};", - "\nvar basicIfrsVariable = new IfrsVariable{Partition = previousPeriodPartition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\", EconomicBasis = \"L\"};", + "\n", "\nvar inputDataSet = new IfrsVariable[]{", "\n grossBasicIfrsVariable with {AocType = \"BOP\", Novelty = \"N\", Values = new double[] {100.0}},", "\n grossBasicIfrsVariable with {AocType = \"CF\", Novelty = \"N\", Values = new double[] {-10.0}},", diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index 400a12d5..c148bb4a 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -74,10 +74,10 @@ "\nIA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", "\nAU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", "\nEV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", - "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,160,1900,1", - "\nWO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,170,1900,1", "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", "\nEA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,193,1900,1", + "\nWO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,195,1900,1", "\nAM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], From bc23ff73498d48193b4edf5162e96c9d948407cb Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 11 Jul 2023 13:53:14 +0200 Subject: [PATCH 07/24] clean up --- ifrs17/Import/1ImportScope-Identities.ipynb | 234 ++++++-------------- ifrs17/Utils/ImportCalculationMethods.ipynb | 7 + 2 files changed, 76 insertions(+), 165 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index acbf1e77..70561f05 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -223,142 +223,18 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "## Parent AoC Step ", - "\nThe **ParentAocStep** scope computes and provides an important piece of information for each [Identity](../DataModel/DataStructure#import-identity), i.e. for a certain [AoC Type](../DataModel/DataStructure#aoc-type) and [Novelty](../DataModel/DataStructure#novelty).", - "\n", - "\nIt provides the list of the adjacent AoC Steps prior to Identity one. It can be more than one only for the step **CL** where a parent for each novelty is considered.", - "\nParentAocStep is critical when computing the *telescoping* differences. ", - "\n", - "\nThey are defined as follows:", - "\n", - "\n$$", - "\n\\text{ParentAocStep}(\\text{AoC Step}) = \\left\\{", - "\n\\begin{array}{cl}", - "\n\\text{AoC Step with AoC Type YCU and Novelty I} & \\text{if AoC Type CRU} \\\\", - "\n\\text{The last AoC Step with Data Type != Calculated and same Novelty as the AoC Step} & \\text{if AoC Type YCU} \\\\", - "\n\\text{The AoC Step which comes before in terms of order (as defined by AoC Type)} & \\text{otherwise} \\\\", - "\n\\end{array}", - "\n\\right.", - "\n$$", - "\n" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "// public interface ParentAocStep : IScope<(ImportIdentity Id, string AmountType), ImportStorage>", - "\n// {", - "\n// static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", - "\n// builder.ForScope(s => s.WithApplicability(x => x.Identity.AmountType != AmountTypes.CDR));", - "\n ", - "\n// private IEnumerable ParsedAocSteps => GetScope(Identity.Id.DataNode).Values;", - "\n// //private ", - "\n// IEnumerable OrderedParsedAocSteps => ParsedAocSteps.Concat(CalculatedTelescopicAocStep).OrderBy(x => GetStorage().AocConfigurationByAocStep[x].Order);", - "\n ", - "\n// //private ", - "\n// Dictionary> ParentParsedIdentities => GetPreviousIdentities(OrderedParsedAocSteps, GetStorage().GetNovelties());", - "\n// //private ", - "\n// AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", - "\n ", - "\n// IEnumerable CalculatedTelescopicAocStep => GetStorage().GetCalculatedTelescopicAocSteps();", - "\n// // calculated step => empty, _ => PreviousAocSteps, Ordered, last not calculated (but calc telescopic)", - "\n// IEnumerable Values => ", - "\n// Identity.Id.AocType switch {", - "\n// AocTypes.CRU => new AocStep(AocTypes.YCU, Novelties.I).RepeatOnce(),", - "\n// AocTypes.YCU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep).RepeatOnce(),", - "\n// _ => ParentParsedIdentities.TryGetValue(identityAocStep, out var parents) ? parents : Enumerable.Empty(),", - "\n// };", - "\n// }", - "\n", - "\n// public interface ParentAocStepForCreditRisk : ParentAocStep", - "\n// {", - "\n// IEnumerable ParentAocStep.CalculatedTelescopicAocStep => ", - "\n// GetStorage().GetCalculatedTelescopicAocSteps().Where(aoc => aoc.AocType != AocTypes.CRU);", - "\n// }" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## Reference AoC Step", - "\n", - "\nThe **ReferenceAocStep** scope provides the AoC Step from which to retrieve the data in order to compute its value (e.g. AoC Step EA retrieves Present Values, while AoC Step YCU retrieves Nominal).", - "\n", - "\nThey are defined as follows:", - "\n", - "\n$$", - "\n\\text{ReferenceAocStep}(\\text{AoC Step}) = \\left\\{", - "\n\\begin{array}{cl}", - "\n\\text{self} & \\text{if AoC Step InputSource is not Calculated} \\\\", - "\n\\text{The last AoC Step with Data Type != Calculated and same Novelty as the input AoC Step} ~, & \\text{if AoC Type } \\in \\text{\\{RCU, CF, IA, YCU, CRU\\}} \\\\", - "\n\\text{AoC Step with AoC Type CF and Novelty as the AoC Step} & \\text{if AoC Type EA} \\\\", - "\n\\text{AoC Step with AoC Type CL and Novelty C} & \\text{if AoC Type $\\in$ \\{AM, EOP\\}} \\\\", - "\n\\text{empty} & \\text{if AoC Type is BOP} \\\\", - "\n\\text{log NotSupportedAocStepReference error} & \\text{otherwise} \\\\", - "\n\\end{array}", - "\n\\right.", - "\n$$", - "\n", - "\nwhere the last AoC Step is obtained by ordering the AoC Steps according to their order (as defined by its AoC Type) and taking the last one." - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "// public interface ReferenceAocStep : IScope ", - "\n// {", - "\n// // private ", - "\n// IEnumerable OrderedParsedAocSteps => GetScope(Identity.DataNode).Values.OrderBy(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].Order);", - "\n// // private ", - "\n// AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", - "\n// // private ", - "\n// AocStep GetReferenceAocStep(string aocType) { //TODO return Enumerable + rewrite without hardcoding: use previous filtered for NotCalculated or !Optional+Mandatory steps (?)", - "\n// return aocType switch {", - "\n// AocTypes.RCU or AocTypes.CF or AocTypes.IA or AocTypes.YCU or AocTypes.CRU => OrderedParsedAocSteps.GetReferenceAocStepForCalculated(GetStorage().AocConfigurationByAocStep, identityAocStep),", - "\n// AocTypes.EA => new AocStep(AocTypes.CF, Identity.Novelty),", - "\n// AocTypes.AM or AocTypes.EOP => new AocStep(AocTypes.CL, Novelties.C),", - "\n// AocTypes.BOP => GetStorage().GetShift(Identity.ProjectionPeriod) >= MonthInAYear && Identity.Novelty == Novelties.I ", - "\n// ? new AocStep(AocTypes.CL, Novelties.C) ", - "\n// : new AocStep(default, default), //BOP, C has DataType == Calculated. See ReferenceAocStep condition.", - "\n// _ => (AocStep)ApplicationMessage.Log(Error.NotSupportedAocStepReference, Identity.AocType),", - "\n// };", - "\n// }", - "\n// //Calculated steps with Format.Cashflow => prev not calculated. Else take it from a dictionary", - "\n", - "\n", - "\n// // The Reference AocStep from which get data (Nominal or PV) to compute", - "\n// AocStep Value => GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated || ", - "\n// GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic ", - "\n// ? GetReferenceAocStep(Identity.AocType)", - "\n// : identityAocStep;", - "\n// }" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ "## Previous AoC Steps", - "\nThe **PreviousAocSteps** scope computes and provides another important piece of information for each [Identity](../DataModel/DataStructure#import-identity), i.e. for a certain [AoC Type](../DataModel/DataStructure#aoc-type) and [Novelty](../DataModel/DataStructure#novelty).", + "\nThe **PreviousAocSteps** scope computes and provides an important piece of information for each [Identity](../DataModel/DataStructure#import-identity), i.e. for a certain [AoC Type](../DataModel/DataStructure#aoc-type) and [Novelty](../DataModel/DataStructure#novelty).", "\n", "\nIt provides the list of all previous AoC Steps up to the **BOP** step, whereby a Combined novelty will branch into the InForce and New Business AoC Types.", "\n", "\nPreviousAocSteps is critical when computing aggregated values along the various dimensions (such as for example Line of Business) and ", - "\nis formed by the ParentAocStep and its parent and so on until there is no parent.", + "\nis used to compute the Parent AoC Steps and the Reference AoC Steps.", + "\n", + "\nThe adjacent AoC Steps prior to Identity one is called Parent Aoc Step (PAS). Thus the PreviousAocSteps is the collection of the identity parents and their parents and so on until there is no parent.", "\n", "\n$$", "\n\\text{PreviousAocSteps}(\\rm{AocStep}) = \\{PAS_1, PAS_2, \\ldots\\}", @@ -371,7 +247,9 @@ "\n\\rm{PAS}_2 = \\rm{ParentAocStep}(\\rm{PAS}_1).", "\n$$", "\n", - "\nThis scope depends on the InputSource (Actual or Cashflow) for which the PreviousSteps are requested due to the AocChain differences between Actual reports and the rest." + "\nThis scope depends on the InputSource (Actual or Cashflow) for which the PreviousSteps are requested due to the Aoc Chain differences between Actual reports and the rest.", + "\n", + "\nThe exact structure being return depends on the **order** of the AoC Steps (which is set by the [AoC Step Configuration](../DataModel/DataStructure#aoc-configuration)), and on which AoC steps exist." ], "metadata": {}, "execution_count": 0, @@ -382,12 +260,9 @@ "source": [ "public interface PreviousAocSteps : IScope<(ImportIdentity Id, InputSource ScopeInputSource), ImportStorage> ", "\n{ ", - "\n // private ", - "\n AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", - "\n // private ", - "\n int aocStepOrder => GetStorage().AocConfigurationByAocStep[identityAocStep].Order;", - "\n // private ", - "\n HashSet allAocSteps => GetStorage().GetAllAocSteps(Identity.ScopeInputSource).ToHashSet();", + "\n private AocStep identityAocStep => new AocStep(Identity.Id.AocType, Identity.Id.Novelty);", + "\n private int aocStepOrder => GetStorage().AocConfigurationByAocStep[identityAocStep].Order;", + "\n private HashSet allAocSteps => GetStorage().GetAllAocSteps(Identity.ScopeInputSource).ToHashSet();", "\n IEnumerable Values => allAocSteps.Contains(identityAocStep)", "\n ? GetScope(Identity.Id.DataNode).Identities.Select(id => new AocStep(id.AocType, id.Novelty)).Distinct()", "\n .Where(aoc => allAocSteps.Contains(aoc) && ", @@ -404,7 +279,27 @@ { "cell_type": "markdown", "source": [ - "The exact structure being return depends on the **order** of the AoC Steps (which is set by the [AoC Step Configuration](../DataModel/DataStructure#aoc-configuration)), and on which AoC steps exist." + "## Parent AoC Step ", + "\nThe **ParentAocStep** scope computes and provides an important piece of information for each [Identity](../DataModel/DataStructure#import-identity), i.e. for a certain [AoC Type](../DataModel/DataStructure#aoc-type) and [Novelty](../DataModel/DataStructure#novelty).", + "\n", + "\nIt provides the list of the adjacent AoC Steps prior to Identity one. It can be more than one only for the step **CL** where a parent for each novelty is considered.", + "\nParentAocStep is critical when computing the *telescoping* differences. ", + "\n", + "\nThey are defined as follows:", + "\n", + "\n$$", + "\n\\text{ParentAocStep}(\\text{AoC Step}) = \\left\\{", + "\n\\begin{array}{cl}", + "\n\\text{empty} & \\text{if AoC Type BOP or is of DataType Calculated} \\\\", + "\n\\text{Last of previous AoC Step for each Novelty} & \\text{if not BOP or Calculated but it is the first Combined AoC Step} \\\\", + "\n\\text{Last of previous AoC Step of the same Novelty} & \\text{if not BOP or Calculated and not the first Combined AoC Step} \\\\", + "\n\\end{array}", + "\n\\right.", + "\n$$", + "\n", + "\nwhere the last AoC Step is obtained by ordering the AoC Steps according to their order (as defined by its AoC Type) and taking the last one.", + "\nNote that the DataType of an AocStep is defined in the [AoC Step Configuration](../DataModel/DataStructure#aoc-configuration) table.", + "\n" ], "metadata": {}, "execution_count": 0, @@ -415,20 +310,12 @@ "source": [ "public interface ParentAocStep : IScope<(ImportIdentity Id, string AmountType, InputSource ScopeInputSource), ImportStorage>", "\n{", - "\n // calculated step => empty, _ => PreviousAocSteps, Ordered, last not calculated (but calc telescopic)", - "\n IEnumerable CalculatedAocStep => GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType.Contains(DataType.Calculated)).Select(kvp => kvp.Key);", - "\n // private ", - "\n IEnumerable PreviousAocSteps => GetScope((Identity.Id, Identity.ScopeInputSource)).Values;", - "\n", - "\n", - "\n // private ", - "\n IEnumerable TelescopicStepToBeRemoved => Identity.AmountType == AmountTypes.CDR ? Enumerable.Empty() : GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.AocType == AocTypes.CRU).Select(kvp => kvp.Key);", - "\n // private ", - "\n IEnumerable PreviousAocStepsNotCalculated => PreviousAocSteps.Where(aoc => !CalculatedAocStep.Concat(TelescopicStepToBeRemoved).Contains(aoc));", - "\n // private ", - "\n bool IsFirstCombinedStep => Identity.Id.Novelty == Novelties.C && !PreviousAocStepsNotCalculated.Any(aoc => aoc.Novelty == Novelties.C);", - "\n // private ", - "\n bool IsCalculatedStep => CalculatedAocStep.Contains(new AocStep(Identity.Id.AocType, Identity.Id.Novelty));//Would be nice to use Identity.AocStep", + "\n private IEnumerable CalculatedAocStep => GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType.Contains(DataType.Calculated)).Select(kvp => kvp.Key);", + "\n ", + "\n private IEnumerable TelescopicStepToBeRemoved => Identity.AmountType == AmountTypes.CDR ? Enumerable.Empty() : GetStorage().AocConfigurationByAocStep.Where(kvp => kvp.Value.AocType == AocTypes.CRU).Select(kvp => kvp.Key);", + "\n private IEnumerable PreviousAocStepsNotCalculated => GetScope((Identity.Id, Identity.ScopeInputSource)).Values.Where(aoc => !CalculatedAocStep.Concat(TelescopicStepToBeRemoved).Contains(aoc));", + "\n private bool IsFirstCombinedStep => Identity.Id.Novelty == Novelties.C && !PreviousAocStepsNotCalculated.Any(aoc => aoc.Novelty == Novelties.C);", + "\n private bool IsCalculatedStep => CalculatedAocStep.Contains(new AocStep(Identity.Id.AocType, Identity.Id.Novelty));", "\n", "\n IEnumerable Values => (Identity.Id.AocType == AocTypes.BOP || IsCalculatedStep, IsFirstCombinedStep) switch {", "\n (true, _ ) => Enumerable.Empty(),", @@ -441,32 +328,49 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Reference AoC Step", + "\n", + "\nThe **ReferenceAocStep** scope provides the AoC Step from which to retrieve the data in order to compute its value (e.g. AoC Step EA retrieves Present Values, while AoC Step YCU retrieves Nominal).", + "\n", + "\nThey are defined as follows:", + "\n", + "\n$$", + "\n\\text{ReferenceAocStep}(\\text{AoC Step}) = \\left\\{", + "\n\\begin{array}{cl}", + "\n\\text{The last AoC Step with Data Type != Calculated} ~, & \\text{if AoC Step is of DataType Calculated or CalculatedTelescopic} \\\\", + "\n\\text{As defined by a custom setting} & \\text{otherwise if provided custom settings} \\\\", + "\n\\text{self} & \\text{all other cases} \\\\", + "\n\\end{array}", + "\n\\right.", + "\n$$", + "\n", + "\nwhere the last AoC Step is obtained by ordering the AoC Steps according to their order (as defined by its AoC Type) and taking the last one.", + "\nCustom settings for the Reference AoC Step is given in [helper variables](../Utils/ImportCalculationMethods#helper-variables-used-in-calculation) and can be overwritten in custom projects. " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ - "public interface ReferenceAocStep : IScope ", + "// The Reference AocStep from which the data (Nominal or PV) is retrieved to to compute the current AoC Step", + "\npublic interface ReferenceAocStep : IScope ", "\n{", - "\n // private ", - "\n //IEnumerable PreviousAocSteps => GetScope((Identity.Id, Identity.ScopeInputSource)).Values;", - "\n IEnumerable PreviousAocSteps => GetScope((Identity, InputSource.Cashflow)).Values;", "\n private AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", - "\n // The Reference AocStep from which get data (Nominal or PV) to compute", + "\n ", "\n IEnumerable Values => ( GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated ||", "\n GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic, ", - "\n myDict.TryGetValue(identityAocStep, out var ret) ) switch {", - "\n (true, false) => PreviousAocSteps.GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", + "\n ComputationHelper.ReferenceAocSteps.TryGetValue(identityAocStep, out var ret) ) switch {", + "\n (true, false) => GetScope((Identity, InputSource.Cashflow)).Values", + "\n .GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", "\n && GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic)),", "\n (true, true) => ret,", "\n (false, _) => identityAocStep.RepeatOnce(),", "\n };", - "\n //IEnumerable GetFromMyDict(AocStep identityAocStep) => myDict.TryGetValue(identityAocStep, out var ret) ? ret : new AocStep(default,default).RepeatOnce();", - "\n Dictionary> myDict => new Dictionary>()", - "\n {", - "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")}},", - "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")}}, ", - "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")}}, ", - "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"CL\",\"C\")}},//projections", - "\n };", "\n}" ], "metadata": {}, diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 22ef051f..84abe315 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -422,6 +422,13 @@ "source": [ "public static class ComputationHelper{", "\n public static string [] AocTypeWithNoPv = new string[]{AocTypes.BOP, AocTypes.EA, AocTypes.AM, AocTypes.RCU};", + "\n public static Dictionary> ReferenceAocSteps => new Dictionary>()", + "\n {", + "\n {new AocStep(AocTypes.EA ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CF,Novelties.C)}},", + "\n {new AocStep(AocTypes.AM ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}}, ", + "\n {new AocStep(AocTypes.EOP ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}}, ", + "\n {new AocStep(AocTypes.BOP ,Novelties.I), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}},//projections //TODO is this needed?", + "\n };", "\n} " ], "metadata": {}, From 596c3528c440a35af62515ac26a53d8c9384a2f8 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 11 Jul 2023 14:37:50 +0200 Subject: [PATCH 08/24] test new novelty --- ifrs17/Test/AocStructureTest.ipynb | 184 +++++++++++++++++++++++++---- 1 file changed, 164 insertions(+), 20 deletions(-) diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index a103ff47..16ea99b3 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -1072,9 +1072,45 @@ "outputs": [] }, { - "cell_type": "markdown", + "cell_type": "code", "source": [ - "## Preparation" + "string newNovelties = ", + "\n@\"@@Novelty", + "\nSystemName,DisplayName,Parent,Order", + "\nI,In Force,,1", + "\nN,New Business,,10", + "\nA,Aquisition,,15", + "\nC,Combined,,20\";", + "\nstring newAocConfig = ", + "\n@\"@@AocConfiguration,,,,,,,,,,,", + "\nAocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month", + "\nBOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,1900,1", + "\nMC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,1900,1", + "\nRCU,I,4,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,30,1900,1", + "\nCF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,40,1900,1", + "\nIA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,50,1900,1", + "\nAU,I,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,60,1900,1", + "\nYCU,I,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,70,1900,1", + "\nCRU,I,8,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,80,1900,1", + "\nEV,I,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,90,1900,1", + "\nBOP,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,95,1900,1", + "\nMC,N,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,100,1900,1", + "\nCF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,110,1900,1", + "\nIA,N,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,120,1900,1", + "\nAU,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,1900,1", + "\nEV,N,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,140,1900,1", + "\nBOP,A,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,141,1900,1", + "\nMC,A,1,4,Average,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,142,1900,1", + "\nCF,A,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,143,1900,1", + "\nIA,A,4,4,Average,EndOfPeriod,EndOfPeriod,Delta,EndOfPeriod,144,1900,1", + "\nAU,A,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,145,1900,1", + "\nEV,A,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,146,1900,1", + "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,180,1900,1", + "\nEA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,190,1900,1", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,193,1900,1", + "\nWO,C,1,2,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,195,1900,1", + "\nAM,C,4,6,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,200,1900,1", + "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,220,1900,1\";" ], "metadata": {}, "execution_count": 0, @@ -1083,8 +1119,10 @@ { "cell_type": "code", "source": [ - "// await DataSource.DeleteAsync(DataSource.Query());", - "\n// await DataSource.DeleteAsync(DataSource.Query());" + "await DataSource.DeleteAsync(DataSource.Query());", + "\nawait DataSource.DeleteAsync(DataSource.Query());", + "\nawait Import.FromString(newNovelties).WithType().WithTarget(DataSource).ExecuteAsync();", + "\nawait Import.FromString(newAocConfig).WithType().WithTarget(DataSource).ExecuteAsync();" ], "metadata": {}, "execution_count": 0, @@ -1093,19 +1131,125 @@ { "cell_type": "code", "source": [ - "// await DataSource.DeleteAsync(DataSource.Query());", - "\n// await DataSource.DeleteAsync(DataSource.Query());", - "\n// await Import.FromString(newAocTypes).WithType().WithTarget(DataSource).ExecuteAsync();", - "\n// await Import.FromString(newAocConfiguration).WithType().WithTarget(DataSource).ExecuteAsync();" + "inputRawVariables = new RawVariable[]{", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"BOP\", Novelty = \"I\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"MC\", Novelty = \"I\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"BOP\", Novelty = \"N\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"EV\", Novelty = \"N\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"BOP\", Novelty = \"A\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"AU\", Novelty = \"A\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfInsuranceContracts, AocType = \"CL\", Novelty = \"C\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n};" ], "metadata": {}, "execution_count": 0, "outputs": [] }, { - "cell_type": "markdown", + "cell_type": "code", "source": [ - "# New Aoc Configuration" + "var parentBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")}}, ", + "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"AU\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\")}},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"YCU\",\"I\"), new AocStep(\"EV\",\"N\"), new AocStep(\"AU\",\"A\"),}},", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var referenceBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} },", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")} }, ", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"EV\",\"N\")} },", + "\n {new AocStep(\"BOP\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\")}},", + "\n {new AocStep(\"CF\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\")}},", + "\n {new AocStep(\"IA\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\")}},", + "\n {new AocStep(\"AU\",\"A\"), new AocStep[]{new AocStep(\"AU\",\"A\")} },", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")} },", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\")} },", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\")} },", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var fullAocBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\")}},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", + "\n {new AocStep(\"YCU\",\"I\"), new AocStep[]{new AocStep(\"IA\",\"I\"), new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", + "\n {new AocStep(\"EV\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\")}},", + "\n {new AocStep(\"CF\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\")}},", + "\n {new AocStep(\"IA\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\")}},", + "\n {new AocStep(\"AU\",\"A\"), new AocStep[]{new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\")}},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\"), new AocStep(\"AU\",\"A\"),", + "\n }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"),new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"),new AocStep(\"YCU\",\"I\"), ", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\"), new AocStep(\"AU\",\"A\"), ", + "\n new AocStep(\"CL\",\"C\"),", + "\n }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\"), new AocStep(\"AU\",\"A\"),", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),}},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"),", + "\n new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\"), new AocStep(\"AU\",\"A\"), ", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"CF\",\"C\")", + "\n }},", + "\n", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"YCU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), new AocStep(\"EV\",\"N\"), ", + "\n new AocStep(\"BOP\",\"A\"), new AocStep(\"CF\",\"A\"), new AocStep(\"IA\",\"A\"), new AocStep(\"AU\",\"A\"),", + "\n new AocStep(\"CF\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n }},", + "\n };", + "\n" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckAocStepStructureAsync(inputRawVariables, parentBm, referenceBm, fullAocBm);", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -1114,7 +1258,7 @@ { "cell_type": "markdown", "source": [ - "## Preparation" + "# New Aoc Configuration" ], "metadata": {}, "execution_count": 0, @@ -1172,15 +1316,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "## UseCase" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -1262,6 +1397,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ From 49a52bae7158096b219956ea44091822ca0fe78d Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 11 Jul 2023 15:23:53 +0200 Subject: [PATCH 09/24] remove hardcoded novelties.N --- ifrs17/Import/3ImportScope-Actuals.ipynb | 3 +- .../Import/4ImportScope-TechnicalMargin.ipynb | 12 +++--- ifrs17/Report/ReportScopes.ipynb | 38 +++++++++---------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/ifrs17/Import/3ImportScope-Actuals.ipynb b/ifrs17/Import/3ImportScope-Actuals.ipynb index e6e485a9..cd1dd61b 100644 --- a/ifrs17/Import/3ImportScope-Actuals.ipynb +++ b/ifrs17/Import/3ImportScope-Actuals.ipynb @@ -551,8 +551,7 @@ "\n ", "\n double NominalDeferrable.Value => referenceCashflow >= Precision //if no previous RawVariable, use IfrsVariable", "\n ? referenceCashflow ", - "\n : GetScope((Identity.Id with {AocType = AocTypes.BOP, Novelty = Novelties.I}, Identity.MonthlyShift)).Value +", - "\n GetScope((Identity.Id with {AocType = AocTypes.BOP, Novelty = Novelties.N}, Identity.MonthlyShift)).Value;", + "\n : GetStorage().GetNovelties(AocTypes.BOP, InputSource.Cashflow).Sum(n => GetScope((Identity.Id with {AocType = AocTypes.BOP, Novelty = n}, Identity.MonthlyShift)).Value);", "\n}", "\n", "\npublic interface AmDeferrable : NominalDeferrable{", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index 50025e4b..c689a68e 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -268,7 +268,7 @@ "\n .WithApplicability(x => x.Identity.AocType == AocTypes.EOP)", "\n );", "\n ", - "\n private string estimateType => GetContext();", + "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", "\n double Value => GetScope((Identity.DataNode, estimateType)).Values", "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +", @@ -342,12 +342,10 @@ "\n}", "\n", "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", - "\n double TechnicalMargin.Value => GetScope(Identity.DataNode).BeAmountTypes", - "\n .Except(GetStorage().GetNonAttributableAmountType())", - "\n .Sum(at => GetScope((Identity with {AocType = AocTypes.CF, Novelty = Novelties.I}, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value +", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = Novelties.N}, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value ) +", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = Novelties.I}, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value +", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = Novelties.N}, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value;", + "\n private IEnumerable novelties => GetStorage().GetNovelties(AocTypes.CF).Except(Novelties.C.RepeatOnce());", + "\n double TechnicalMargin.Value => GetScope((Identity.DataNode, 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}", "\n", "\npublic interface TechnicalMarginForEop : TechnicalMargin{", diff --git a/ifrs17/Report/ReportScopes.ipynb b/ifrs17/Report/ReportScopes.ipynb index c7422c32..5e818252 100644 --- a/ifrs17/Report/ReportScopes.ipynb +++ b/ifrs17/Report/ReportScopes.ipynb @@ -533,7 +533,7 @@ "\n private IDataCube licData => licActuarial + accrual;", "\n ", "\n private IDataCube bop => licData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", Novelties.I));", - "\n private IDataCube delta => (licData.Filter((\"VariableType\",\"!BOP\"),(\"VariableType\",\"!EOP\")) + licData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", Novelties.N)))", + "\n private IDataCube delta => (licData.Filter((\"VariableType\",\"!BOP\"),(\"VariableType\",\"!EOP\")) + licData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", \"!I\")))", "\n .AggregateOver(nameof(Novelty), nameof(VariableType))", "\n .SelectToDataCube(x => Math.Abs(x.Value) >= Precision, x => x with { Novelty = Novelties.C, VariableType = \"D\" });", "\n private IDataCube eop => licData.Filter((\"VariableType\",AocTypes.EOP));", @@ -594,7 +594,7 @@ "\n private IDataCube lrcData => lrcActuarial + accrual;", "\n ", "\n private IDataCube bop => lrcData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", Novelties.I));", - "\n private IDataCube delta => (lrcData.Filter((\"VariableType\",\"!BOP\"),(\"VariableType\",\"!EOP\")) + lrcData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", Novelties.N)))", + "\n private IDataCube delta => (lrcData.Filter((\"VariableType\",\"!BOP\"),(\"VariableType\",\"!EOP\")) + lrcData.Filter((\"VariableType\", AocTypes.BOP), (\"Novelty\", \"!I\")))", "\n .AggregateOver(nameof(Novelty), nameof(VariableType))", "\n .SelectToDataCube(x => Math.Abs(x.Value) >= Precision, x => x with { Novelty = Novelties.C, VariableType = \"D\" });", "\n private IDataCube eop => lrcData.Filter((\"VariableType\",AocTypes.EOP));", @@ -703,10 +703,10 @@ "source": [ "public interface FcfChangeInEstimate: IScope<(ReportIdentity Id, CurrencyType CurrencyType), ReportStorage>, IDataCube {", "\n private IDataCube FcfDeltas => GetScope(Identity).Fcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube CurrentFcfDeltas => GetScope(Identity).CurrentFcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).CurrentFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).CurrentFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n // Non-Financial Fp", "\n private string variableTypeNonFinancial => Identity.Id switch {", @@ -800,7 +800,7 @@ "\n };", "\n ", "\n private IDataCube Csm => GetScope(Identity).Csm.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Csm.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Csm.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n IDataCube Amortization => -1 * Csm.Filter((\"VariableType\", AocTypes.AM)).SelectToDataCube(v => v with { VariableType = variableType.amortization });", "\n ", @@ -849,7 +849,7 @@ "public interface LcChangeInEstimate: IScope<(ReportIdentity Id, CurrencyType CurrencyType), ReportStorage>, IDataCube {", "\n ", "\n private IDataCube Lc => GetScope(Identity).Lc.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n IDataCube Amortization => -1 * Lc.Filter((\"VariableType\", AocTypes.AM)).SelectToDataCube(v => v with { VariableType = \"ISE9\" });", "\n ", @@ -902,7 +902,7 @@ "public interface LorecoChangeInEstimate: IScope<(ReportIdentity Id, CurrencyType CurrencyType), ReportStorage>, IDataCube {", "\n ", "\n private IDataCube Loreco => GetScope(Identity).Loreco.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n IDataCube Amortization => -1 * Loreco.Filter((\"VariableType\", AocTypes.AM)).SelectToDataCube(v => v with { VariableType = \"ISE8\" });", "\n ", @@ -1278,10 +1278,10 @@ "\n", "\n // FCF Locked-In Interest Rate Correction", "\n private IDataCube FcfDeltas => GetScope(Identity).Fcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube LockedFcfDeltas => GetScope(Identity).LockedFcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).LockedFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).LockedFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n private IDataCube NonFinancialFcfDeltas => FcfDeltas", "\n .Filter((\"VariableType\", \"!IA\"), (\"VariableType\", \"!YCU\"), (\"VariableType\", \"!CRU\"), (\"VariableType\", \"!FX\"));", @@ -1345,7 +1345,7 @@ "\n", "\n // Loss Component", "\n private IDataCube Lc => GetScope(Identity).Lc.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube LcAmortization => -1 * Lc.Filter((\"VariableType\", AocTypes.AM)).SelectToDataCube(v => v with { VariableType = \"ISE9\" });", "\n ", @@ -1362,7 +1362,7 @@ "\n", "\n // Change in LIC", "\n private IDataCube FcfDeltas => (GetScope(Identity).Fcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N)))", + "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\")))", "\n .Filter((\"LiabilityType\", \"LIC\")); // TODO, extract the LIC to a dedicated scope (whole thing, actually)", "\n ", "\n private IDataCube NonFinancialFcfDeltas => FcfDeltas", @@ -1414,7 +1414,7 @@ "\n ", "\n // Loss Recovery Component (Amortization)", "\n private IDataCube Loreco => GetScope(Identity).Loreco.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n private IDataCube LorecoAmortization => -1 * Loreco", "\n .Filter((\"VariableType\", AocTypes.AM))", @@ -1457,10 +1457,10 @@ "\n", "\n // FCF Locked-In Interest Rate Correction", "\n private IDataCube FcfDeltas => GetScope(Identity).Fcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube LockedFcfDeltas => GetScope(Identity).LockedFcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).LockedFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).LockedFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n private IDataCube NonFinancialFcfDeltas => FcfDeltas", "\n .Filter((\"VariableType\", \"!IA\"), (\"VariableType\", \"!YCU\"), (\"VariableType\", \"!CRU\"), (\"VariableType\", \"!FX\"));", @@ -1489,10 +1489,10 @@ "public interface InsuranceFinanceIncomeExpenseOci: IScope<(ReportIdentity Id, CurrencyType CurrencyType), ReportStorage>, IDataCube {", "\n //FCF", "\n private IDataCube FcfDeltas => GetScope(Identity).Fcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Fcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube CurrentFcfDeltas => GetScope(Identity).CurrentFcf.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).CurrentFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).CurrentFcf.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n // Financial Fp", "\n private string variableTypeFpFinancial => Identity.Id switch {", @@ -1530,7 +1530,7 @@ "\n", "\n // CSM", "\n private IDataCube Csm => GetScope(Identity).Csm.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Csm.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Csm.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n private IDataCube CsmFx => -1 * Csm.Filter((\"VariableType\", AocTypes.FX))", "\n .AggregateOver(nameof(Novelty))", @@ -1544,7 +1544,7 @@ "\n", "\n // LC", "\n private IDataCube Lc => GetScope(Identity).Lc.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Lc.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n", "\n private IDataCube LcFx => -1 * Lc.Filter((\"VariableType\", AocTypes.FX))", "\n .AggregateOver(nameof(Novelty))", @@ -1558,7 +1558,7 @@ "\n", "\n // LoReCo", "\n private IDataCube Loreco => GetScope(Identity).Loreco.Filter((\"VariableType\", \"!BOP\"),(\"VariableType\", \"!EOP\")) +", - "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", Novelties.N));", + "\n GetScope(Identity).Loreco.Filter((\"VariableType\", AocTypes.BOP),(\"Novelty\", \"!I\"));", "\n ", "\n private IDataCube LorecoFx => -1 * Loreco.Filter((\"VariableType\", AocTypes.FX))", "\n .AggregateOver(nameof(Novelty))", From a40e84540f87c852504997c7474980f0b36330f3 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Wed, 12 Jul 2023 14:43:00 +0200 Subject: [PATCH 10/24] fix reference --- ifrs17/Import/1ImportScope-Identities.ipynb | 12 ++- ifrs17/Test/AocStructureTest.ipynb | 106 ++++++++++++++++++++ 2 files changed, 113 insertions(+), 5 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index 70561f05..0acf6485 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -358,16 +358,18 @@ "cell_type": "code", "source": [ "// The Reference AocStep from which the data (Nominal or PV) is retrieved to to compute the current AoC Step", - "\npublic interface ReferenceAocStep : IScope ", + "\npublic interface ReferenceAocStep : IScope", "\n{", "\n private AocStep identityAocStep => new AocStep(Identity.AocType, Identity.Novelty);", - "\n ", + "\n", + "\n private IEnumerable referenceForCalculated => GetScope((Identity, InputSource.Cashflow)).Values", + "\n .GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", + "\n && GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic));", + "\n", "\n IEnumerable Values => ( GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated ||", "\n GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic, ", "\n ComputationHelper.ReferenceAocSteps.TryGetValue(identityAocStep, out var ret) ) switch {", - "\n (true, false) => GetScope((Identity, InputSource.Cashflow)).Values", - "\n .GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", - "\n && GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic)),", + "\n (true, false) => referenceForCalculated.Any(x => x.Novelty == Novelties.C) ? referenceForCalculated.Where(x => x.Novelty == Novelties.C) : referenceForCalculated,", "\n (true, true) => ret,", "\n (false, _) => identityAocStep.RepeatOnce(),", "\n };", diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index 16ea99b3..314e47e7 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -1406,6 +1406,112 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## AU-C first C step" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var inputVariables = new RawVariable[]{", + "\n new RawVariable{AocType = \"BOP\", Novelty = \"N\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n new RawVariable{AocType = \"AU\", Novelty = \"C\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n new RawVariable{AocType = \"EV\", Novelty = \"C\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n new RawVariable{AocType = \"CL\", Novelty = \"C\", AccidentYear = null, AmountType = \"CL\", EstimateType = \"BE\", Partition = partition.Id, Values = new double[] {1.0}, DataNode = groupOfInsuranceContracts},", + "\n};" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var parentBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"AU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"AU\",\"C\"),}}, ", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"YCU\",\"C\")}},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\"),}},", + "\n };", + "\nvar referenceBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n", + "\n {new AocStep(\"AU\",\"C\"), new AocStep[]{new AocStep(\"AU\",\"C\")}},", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"AU\",\"C\") }},", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"EV\",\"C\") }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\") , new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"IA\",\"I\") , new AocStep[]{new AocStep(\"BOP\",\"I\") }},", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\") }},", + "\n };", + "\nvar fullAocBm = new Dictionary>()", + "\n {", + "\n //{new AocStep(\"BOP\",\"N\"), Enumerable.Empty()},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", + "\n ", + "\n {new AocStep(\"AU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n }},", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"AU\",\"C\"),}},", + "\n {new AocStep(\"EV\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"AU\",\"C\"),new AocStep(\"YCU\",\"C\"),", + "\n }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"AU\",\"C\"),new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\")", + "\n }}, ", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"AU\",\"C\"),new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"AU\",\"C\"),new AocStep(\"CF\",\"C\"), new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\")", + "\n }}, ", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"),new AocStep(\"IA\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"AU\",\"C\"),new AocStep(\"CF\",\"C\"), new AocStep(\"YCU\",\"C\"), new AocStep(\"EV\",\"C\"), new AocStep(\"CL\",\"C\"), new AocStep(\"AM\",\"C\"),", + "\n }}, ", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckAocStepStructureAsync(inputVariables, parentBm, referenceBm, fullAocBm);", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ From e73c7059eba8fe1ae4392e702d096500d4c6f04e Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 13 Jul 2023 09:46:01 +0200 Subject: [PATCH 11/24] AocConfiguration - remove compulsory requirements Add use case --- ifrs17/Import/Importers.ipynb | 8 +- ifrs17/Test/AocStructureTest.ipynb | 170 +++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 4 deletions(-) diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 5f4da2cc..44fb9688 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -796,10 +796,10 @@ "\n", "\n var aocTypes = await options.TargetDataSource.Query().OrderBy(x => x.Order).ToArrayAsync();", "\n var aocTypesCompulsory = typeof(AocTypes).GetFields().Select(x => (string)x.Name);", - "\n if(aocTypesCompulsory.Where(x => !aocTypes.Select(x => x.SystemName).Contains(x)).Any()) {", - "\n ApplicationMessage.Log(Error.AocTypeCompulsoryNotFound);", - "\n return Activity.Finish();", - "\n }", + "\n // if(aocTypesCompulsory.Where(x => !aocTypes.Select(x => x.SystemName).Contains(x)).Any()) {", + "\n // ApplicationMessage.Log(Error.AocTypeCompulsoryNotFound);", + "\n // return Activity.Finish();", + "\n // }", "\n ", "\n var logConfig = await Import.FromDataSet(dataSet).WithType().WithTarget(workspace).ExecuteAsync();", "\n if(logConfig.Errors.Any()) return Activity.Finish().Merge(logConfig); ", diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index 314e47e7..33a6bac6 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -1512,6 +1512,176 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Reinsurance " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "string newAocTypes = ", + "\n@\"@@AocType", + "\nSystemName,DisplayName,Parent,Order", + "\nBOP,Opening Balance,,10", + "\nMC,Model Correction,,20", + "\nCF,Cash flow,,30", + "\nIA,Interest Accretion,,40", + "\nCRU,Credit Risk Update,,45", + "\nAU,Assumption Update,,50", + "\nYCU,Yield Curve Update,,60", + "\nEV,Experience Variance,,70", + "\nCL,Combined Liabilities,,80", + "\nEA,Experience Adjustment,,81,", + "\nAM,Amortization,,85", + "\nEOP,Closing Balance,,90\";", + "\n", + "\nstring newAocConfiguration = ", + "\n@\"@@AocConfiguration,,,,,,,,,,,", + "\nAocType,Novelty,DataType,InputSource,FxPeriod,YcPeriod,CdrPeriod,ValuationPeriod,RcPeriod,Order,Year,Month", + "\nBOP,I,1,7,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,10,2017,12", + "\nMC,I,1,4,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,BeginningOfPeriod,20,2017,12", + "\nCF,I,4,4,Average,NotApplicable,BeginningOfPeriod,Delta,EndOfPeriod,30,2017,12", + "\nIA,I,4,5,Average,BeginningOfPeriod,BeginningOfPeriod,Delta,EndOfPeriod,40,2017,12", + "\nCRU,I,8,4,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,45,1900,1", + "\nBOP,N,1,4,Average,BeginningOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,50,2017,12", + "\nCF,N,4,4,Average,NotApplicable,EndOfPeriod,Delta,EndOfPeriod,60,2017,12", + "\nIA,N,4,4,Average,BeginningOfPeriod,EndOfPeriod,Delta,EndOfPeriod,70,2017,12", + "\nAU,C,1,4,EndOfPeriod,BeginningOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,80,2017,12", + "\nYCU,C,8,4,EndOfPeriod,EndOfPeriod,BeginningOfPeriod,EndOfPeriod,EndOfPeriod,90,2017,12", + "\nEV,C,1,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,100,2017,12", + "\nCL,C,2,4,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,110,2017,12", + "\nEA,C,4,4,EndOfPeriod,NotApplicable,NotApplicable,NotApplicable,EndOfPeriod,112,1900,1", + "\nCF,C,5,6,Average,NotApplicable,NotApplicable,NotApplicable,NotApplicable,115,2017,12", + "\nAM,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,120,2017,12", + "\nEOP,C,4,6,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,EndOfPeriod,130,2017,12", + "\n\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await DataSource.DeleteAsync(DataSource.Query());", + "\nawait DataSource.DeleteAsync(DataSource.Query());", + "\n((await Import.FromString(newAocTypes).WithType().WithTarget(DataSource).ExecuteAsync()).Status,", + "\n(await Import.FromString(newAocConfiguration).WithFormat(ImportFormats.AocConfiguration).WithTarget(DataSource).ExecuteAsync()).Status)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "inputRawVariables = new RawVariable[]{", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfReinsuranceContracts, AocType = \"BOP\", Novelty = \"I\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfReinsuranceContracts, AocType = \"MC\", Novelty = \"I\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfReinsuranceContracts, AocType = \"BOP\", Novelty = \"N\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n new RawVariable{Partition = partition.Id, Values = new []{1.0}, DataNode = groupOfReinsuranceContracts, AocType = \"CL\", Novelty = \"C\", AccidentYear = null, AmountType = \"PR\", EstimateType = \"BE\"},", + "\n};" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "parentBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"CRU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")}},", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"MC\",\"I\"), new AocStep(\"BOP\",\"N\"),}}, ", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"YCU\",\"C\"),}},", + "\n };", + "\nvar parentBm_CDR = new Dictionary>()", + "\n {", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"CRU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\")}}, ", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"CRU\",\"I\"), new AocStep(\"BOP\",\"N\")}}, ", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"YCU\",\"C\"),}},", + "\n };", + "\nreferenceBm = new Dictionary>()", + "\n {", + "\n {new AocStep(\"BOP\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }},", + "\n {new AocStep(\"CRU\",\"I\"), new AocStep[]{new AocStep(\"MC\",\"I\") }}, ", + "\n {new AocStep(\"BOP\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"MC\",\"I\"),new AocStep(\"BOP\",\"N\") }}, ", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"CL\",\"C\") }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"CF\",\"C\") }},", + "\n };", + "\nfullAocBm = new Dictionary>()", + "\n {", + "\n //{new AocStep(\"BOP\",\"I\"), Enumerable.Empty()},", + "\n {new AocStep(\"MC\",\"I\"), new AocStep[]{new AocStep(\"BOP\",\"I\")}},", + "\n {new AocStep(\"CF\",\"I\"), new AocStep[]{ new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\")}},", + "\n {new AocStep(\"IA\",\"I\"), new AocStep[]{ new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", + "\n {new AocStep(\"CRU\",\"I\"), new AocStep[]{new AocStep(\"IA\",\"I\"), new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\")}},", + "\n //{new AocStep(\"BOP\",\"N\"), Enumerable.Empty()},", + "\n {new AocStep(\"CF\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\")}},", + "\n {new AocStep(\"IA\",\"N\"), new AocStep[]{new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\")}},", + "\n ", + "\n {new AocStep(\"YCU\",\"C\"), new AocStep[]{new AocStep(\"IA\",\"I\"), new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"),new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), }},", + "\n {new AocStep(\"CL\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"YCU\",\"C\"),", + "\n }},", + "\n {new AocStep(\"EA\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"YCU\",\"C\"),new AocStep(\"CL\",\"C\"),", + "\n }},", + "\n {new AocStep(\"CF\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"EA\",\"C\"), new AocStep(\"YCU\",\"C\"), new AocStep(\"CL\",\"C\"),}},", + "\n {new AocStep(\"AM\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"),", + "\n new AocStep(\"YCU\",\"C\"),new AocStep(\"CF\",\"C\"), new AocStep(\"EA\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n }},", + "\n {new AocStep(\"EOP\",\"C\"), new AocStep[]{new AocStep(\"BOP\",\"I\"), new AocStep(\"MC\",\"I\"), new AocStep(\"CF\",\"I\"), new AocStep(\"IA\",\"I\"), new AocStep(\"CRU\",\"I\"),", + "\n new AocStep(\"BOP\",\"N\"), new AocStep(\"CF\",\"N\"), new AocStep(\"IA\",\"N\"), ", + "\n new AocStep(\"YCU\",\"C\"),new AocStep(\"CF\",\"C\"),new AocStep(\"EA\",\"C\"), new AocStep(\"AM\",\"C\"), new AocStep(\"CL\",\"C\"),", + "\n }}, ", + "\n };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var activity = await CheckAocStepStructureAsync(inputRawVariables, parentBm, referenceBm, fullAocBm, parentBm_CDR);", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ From fc446511d39999f3e4c952fff34017da4437f86d Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 13 Jul 2023 15:57:21 +0200 Subject: [PATCH 12/24] clean up --- ifrs17/Import/1ImportScope-Identities.ipynb | 19 +++--- ifrs17/Import/2ImportScope-PresentValue.ipynb | 8 +-- ifrs17/Test/AocConfigurationTest.ipynb | 9 +++ ifrs17/Utils/ImportCalculationMethods.ipynb | 63 ++----------------- 4 files changed, 27 insertions(+), 72 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index 0acf6485..4b2d87de 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -365,14 +365,17 @@ "\n private IEnumerable referenceForCalculated => GetScope((Identity, InputSource.Cashflow)).Values", "\n .GroupBy(g => g.Novelty, (g, val) => val.Last(aocStep => GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", "\n && GetStorage().AocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic));", - "\n", - "\n IEnumerable Values => ( GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated ||", - "\n GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic, ", - "\n ComputationHelper.ReferenceAocSteps.TryGetValue(identityAocStep, out var ret) ) switch {", - "\n (true, false) => referenceForCalculated.Any(x => x.Novelty == Novelties.C) ? referenceForCalculated.Where(x => x.Novelty == Novelties.C) : referenceForCalculated,", - "\n (true, true) => ret,", - "\n (false, _) => identityAocStep.RepeatOnce(),", - "\n };", + "\n private bool IsCalculatedAocStep => GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.Calculated || GetStorage().AocConfigurationByAocStep[identityAocStep].DataType == DataType.CalculatedTelescopic;", + "\n private bool IsProjectionBopI => Identity.AocType == AocTypes.BOP && Identity.Novelty == Novelties.I && GetStorage().GetShift(Identity.ProjectionPeriod) >= MonthInAYear;", + "\n ", + "\n IEnumerable Values => ( IsCalculatedAocStep, ", + "\n ComputationHelper.ReferenceAocSteps.TryGetValue(identityAocStep, out IEnumerable CustomDefinedReferenceAocStep), //IsCustomDefined", + "\n IsProjectionBopI ) switch {", + "\n (true, false, _) => referenceForCalculated.Any(x => x.Novelty == Novelties.C) ? referenceForCalculated.Where(x => x.Novelty == Novelties.C) : referenceForCalculated,", + "\n (true, true, _) => CustomDefinedReferenceAocStep,", + "\n (false, true, true) => CustomDefinedReferenceAocStep,", + "\n (false, _, _) => identityAocStep.RepeatOnce(),", + "\n };", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 49bbfb04..52c9d4dd 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -166,7 +166,7 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.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 .WithApplicability(x => x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty == Novelties.I));", + "\n );", "\n", "\n IEnumerable referenceAocSteps => GetScope(Identity.Id).Values;", "\n double[] Values => referenceAocSteps.Select(refAocStep => GetStorage().GetValues(Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.AccidentYear))", @@ -198,12 +198,6 @@ "\n GetStorage().GetClaims()", "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear)))", "\n .AggregateDoubleArray();", - "\n}", - "\n", - "\npublic interface ProjectionBopNominalCashflow : NominalCashflow", - "\n{ ", - "\n ImportIdentity subImportIdentity => Identity.Id with {AocType = AocTypes.CL, Novelty = Novelties.C};", - "\n double[] NominalCashflow.Values => GetStorage().GetValues(subImportIdentity, Identity.AmountType, Identity.EstimateType, Identity.AccidentYear);", "\n}" ], "metadata": {}, diff --git a/ifrs17/Test/AocConfigurationTest.ipynb b/ifrs17/Test/AocConfigurationTest.ipynb index 16274ad5..61f308a0 100644 --- a/ifrs17/Test/AocConfigurationTest.ipynb +++ b/ifrs17/Test/AocConfigurationTest.ipynb @@ -421,6 +421,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "workspace.Dispose()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 84abe315..bba0a271 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -34,61 +34,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "# Get Previous Identities" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public static Dictionary> GetPreviousIdentities(IEnumerable aocSteps, IEnumerable novelties)", - "\n{", - "\n var bopNovelties = aocSteps.Where(id => id.AocType == AocTypes.BOP).Select(id => id.Novelty);", - "\n var previousStep = novelties.ToDictionary(n => n, n => bopNovelties.Contains(n) ? new AocStep(AocTypes.BOP,n) : null);", - "\n return aocSteps.Where(id => id.AocType != AocTypes.BOP)", - "\n .ToDictionary(x => x, ", - "\n x => {var isFirstCombined = x.Novelty == Novelties.C && (previousStep[Novelties.C] == null || previousStep[Novelties.C].AocType == AocTypes.BOP);", - "\n var ret = isFirstCombined", - "\n ? previousStep.Where(kvp => kvp.Value != null).Select(kvp => kvp.Value).ToArray() ", - "\n : previousStep[x.Novelty].RepeatOnce();", - "\n previousStep[x.Novelty] = new AocStep(x.AocType, x.Novelty);", - "\n return ret;});", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Get Reference AoC Step for calculated steps" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public static AocStep GetReferenceAocStepForCalculated(this IEnumerable identities, Dictionary aocConfigurationByAocStep, AocStep identityAocStep)", - "\n{", - "\n return identities.LastOrDefault(aocStep => aocConfigurationByAocStep[aocStep].DataType != DataType.Calculated", - "\n && aocConfigurationByAocStep[aocStep].DataType != DataType.CalculatedTelescopic", - "\n && aocConfigurationByAocStep[aocStep].Order < aocConfigurationByAocStep[identityAocStep].Order", - "\n && aocStep.Novelty == identityAocStep.Novelty) ", - "\n ?? new AocStep(default, default);", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -411,7 +356,11 @@ { "cell_type": "markdown", "source": [ - "# Helper variables used in calculation" + "# Helper variables used in calculation", + "\n", + "\nVariables defined here and used in the calculation:", + "\n- AocTypeWithNoPv : used in [Present Value](../Import/2ImportScope-PresentValue#present-value-1) to trigger no calculation for some AoC Type.", + "\n- ReferenceAocSteps : used in [Reference AoC Step](../Import/1ImportScope-Identities#reference-aoc-step) to over rule the standard defition of reference AoC Step. " ], "metadata": {}, "execution_count": 0, @@ -427,7 +376,7 @@ "\n {new AocStep(AocTypes.EA ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CF,Novelties.C)}},", "\n {new AocStep(AocTypes.AM ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}}, ", "\n {new AocStep(AocTypes.EOP ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}}, ", - "\n {new AocStep(AocTypes.BOP ,Novelties.I), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}},//projections //TODO is this needed?", + "\n {new AocStep(AocTypes.BOP ,Novelties.I), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}},//for projections", "\n };", "\n} " ], From 859a3baddbb6c78ca19386d71e5724f3f3988fc2 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 13 Jul 2023 17:00:40 +0200 Subject: [PATCH 13/24] improvements --- ifrs17/Import/1ImportScope-Identities.ipynb | 3 +-- ifrs17/Import/Importers.ipynb | 2 +- ifrs17/Test/AocStructureTest.ipynb | 16 +++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index 4b2d87de..b9386ce0 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -372,8 +372,7 @@ "\n ComputationHelper.ReferenceAocSteps.TryGetValue(identityAocStep, out IEnumerable CustomDefinedReferenceAocStep), //IsCustomDefined", "\n IsProjectionBopI ) switch {", "\n (true, false, _) => referenceForCalculated.Any(x => x.Novelty == Novelties.C) ? referenceForCalculated.Where(x => x.Novelty == Novelties.C) : referenceForCalculated,", - "\n (true, true, _) => CustomDefinedReferenceAocStep,", - "\n (false, true, true) => CustomDefinedReferenceAocStep,", + "\n (true, true, _) or (_, true, true)=> CustomDefinedReferenceAocStep,", "\n (false, _, _) => identityAocStep.RepeatOnce(),", "\n };", "\n}" diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 66ac82ee..043c2961 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -796,7 +796,7 @@ "\n", "\n var aocTypes = await options.TargetDataSource.Query().OrderBy(x => x.Order).ToArrayAsync();", "\n var aocTypesCompulsory = typeof(AocTypes).GetFields().Select(x => (string)x.Name);", - "\n // if(aocTypesCompulsory.Where(x => !aocTypes.Select(x => x.SystemName).Contains(x)).Any()) {", + "\n // if(aocTypesCompulsory.Where(x => !aocTypes.Select(x => x.SystemName).Contains(x)).Any()) { //aocTypes const are not to be considered compulsory steps. ", "\n // ApplicationMessage.Log(Error.AocTypeCompulsoryNotFound);", "\n // return Activity.Finish();", "\n // }", diff --git a/ifrs17/Test/AocStructureTest.ipynb b/ifrs17/Test/AocStructureTest.ipynb index 33a6bac6..dd4af5a9 100644 --- a/ifrs17/Test/AocStructureTest.ipynb +++ b/ifrs17/Test/AocStructureTest.ipynb @@ -66,6 +66,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await Import.FromString(projectionConfiguration).WithType().WithTarget(DataSource).ExecuteAsync();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -204,7 +213,7 @@ "\n //Parents for CDR", "\n if(isReinsurance)", "\n {", - "\n var parentsCdr = testUniverse.GetScopes(identities.Select(id => (object)(id, AmountTypes.CDR,inputSource)), o => o.WithStorage(testStorage));", + "\n var parentsCdr = testUniverse.GetScopes(identities.Select(id => (object)(id, AmountTypes.CDR,inputSource)), o => o.WithStorage(testStorage)).ToArray();", "\n ", "\n var countP = parentsCdr.Where(x => x.Values.Any()).Count();", "\n if (parentBmCdr.Count() != countP) ", @@ -242,16 +251,13 @@ "\n if(!scopeReferences.Any())", "\n errors.Add( $\"Reference not found for AocStep: {kvp.Key.AocType}, {kvp.Key.Novelty}.\");", "\n else{", - "\n var scopeReference = scopeReferences.First();", + "\n var scopeReference = scopeReferences.First();", "\n if( kvp.Value.Intersect(scopeReference.Values).Count() != kvp.Value.Count() || ", "\n kvp.Value.Intersect(scopeReference.Values).Count() != scopeReference.Values.Count() ){", "\n var computedAocSteps = scopeReference.Values.Select(aoc => $\"AocType:{aoc.AocType}, Novelty:{aoc.Novelty}\");", "\n var expectedAocSteps = kvp.Value.Select(aoc => $\"AocType:{aoc.AocType}, Novelty:{aoc.Novelty}\"); ", "\n errors.Add( $\"Reference of {kvp.Key.AocType}, {kvp.Key.Novelty} do not match expected value: \\n Computed: \\n {string.Join(\"\\n\", computedAocSteps)} \\n Expected: \\n {string.Join(\"\\n\", expectedAocSteps)}.\" );", "\n }", - "\n", - "\n // if( kvp.Value.AocType != scopeReference.Value.First().AocType || kvp.Value.Novelty != scopeReference.Value.First().Novelty ) //TODO FIrst are wrong here", - "\n // errors.Add( $\"Reference of {kvp.Key.AocType}, {kvp.Key.Novelty} do not match expected value: \\n Computed {scopeReference.Value} \\n Expected {kvp.Value}.\" );", "\n }", "\n }", "\n }", From a7348faaee5c250c4339b53be39899f13c5bd493 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Fri, 14 Jul 2023 15:41:34 +0200 Subject: [PATCH 14/24] improvements --- ifrs17-template/Test/IfrsVariablesTest.ipynb | 11 ++-- ifrs17/Import/2ImportScope-PresentValue.ipynb | 14 ++--- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 62 ++++++++++++------- ifrs17/Import/Importers.ipynb | 2 +- ifrs17/Utils/ImportCalculationMethods.ipynb | 23 ++++++- 5 files changed, 74 insertions(+), 38 deletions(-) diff --git a/ifrs17-template/Test/IfrsVariablesTest.ipynb b/ifrs17-template/Test/IfrsVariablesTest.ipynb index 5506bba7..2aa378b8 100644 --- a/ifrs17-template/Test/IfrsVariablesTest.ipynb +++ b/ifrs17-template/Test/IfrsVariablesTest.ipynb @@ -281,9 +281,9 @@ "\n", "\n //CompareAgainstBm", "\n if(!computedVariables.Any() && bmVariables.Any())", - "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for EstimateType: \" + bmTableName));", + "\n errorList.Add(new BenchmarkTestResult(\"No variables are computed for: \"+reportingNode+year+month+scenario+\" and EstimateType: \" + bmTableName));", "\n if(computedVariables.Any() && !bmVariables.Any())", - "\n errorList.Add(new BenchmarkTestResult(\"Empty benchmark provided for EstimateType: \" + bmTableName));", + "\n errorList.Add(new BenchmarkTestResult(\"Empty benchmark provided for: \"+reportingNode+year+month+scenario+\" and EstimateType: \" + bmTableName));", "\n if(computedVariables.Any() && bmVariables.Any())", "\n errorList = errorList.Concat(CompareAgainstBm(errorList, bmVariables, computedVariables)).Distinct().ToList();", "\n }", @@ -428,16 +428,17 @@ "cell_type": "code", "source": [ "ProjectionCount = 5;", - "\nawait Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12_Projection.csv\")", + "\nvar activity1 = await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12_Projection.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", "\n .ExecuteAsync();", - "\nawait Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2021_3_Projection.csv\")", + "\nvar activity2 = await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2021_3_Projection.csv\")", "\n .WithFormat(ImportFormats.Cashflow)", "\n .WithTarget(DataSource)", "\n .WithActivityLog()", - "\n .ExecuteAsync();" + "\n .ExecuteAsync();", + "\n(Activity1: activity1.Status, Errors1:activity1.Errors, Activity2:activity2.Status, Errors2:activity2.Errors)" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 52c9d4dd..9e5db689 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -520,13 +520,13 @@ "public interface PresentValue : IWithGetValueFromValues { ", "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", - "\n .WithApplicability(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))", - "\n .WithApplicability(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)", - "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", - "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.IA)", - "\n .WithApplicability(x => ComputationHelper.AocTypeWithNoPv.Contains(x.Identity.Id.AocType) ||", - "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) )", - "\n );", + "\n .WithApplicability(x => x.GetStorage().ImportFormat != ImportFormats.Cashflow || x.GetStorage().IsSecondaryScope(x.Identity.Id.DataNode))", + "\n .WithApplicability(x => (x.Identity.Id.AocType == AocTypes.BOP && x.Identity.Id.Novelty != Novelties.C) || x.Identity.Id.AocType == AocTypes.EOP)", + "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.CF)", + "\n .WithApplicability(x => x.Identity.Id.AocType == AocTypes.IA)", + "\n .WithApplicability(x => ComputationHelper.AocStepWithNoPv.Contains(new AocStep(x.Identity.Id.AocType, x.Identity.Id.Novelty)) ||", + "\n (x.Identity.Id.AocType == AocTypes.CRU && !x.GetStorage().GetCdr().Contains(x.Identity.AmountType)) )", + "\n );", "\n ", "\n [NotVisible][IdentityProperty][Dimension(typeof(EconomicBasis))]", "\n string EconomicBasis => GetContext();", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 01f3c41c..7915458b 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -97,28 +97,36 @@ "source": [ "public interface PvToIfrsVariable: IScope", "\n{", - "\n IEnumerable PvLocked => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", + "\n builder.ForScope(s => s.WithApplicability(x => ComputationHelper.AocStepWithNoPv.Contains(new AocStep(x.Identity.AocType, x.Identity.Novelty))));", "\n", - "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", - "\n}" + "\n IEnumerable PvLocked => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.Identity.EstimateType, ", + "\n DataNode = x.Identity.Id.DataNode, ", + "\n AocType = x.Identity.Id.AocType, ", + "\n Novelty = x.Identity.Id.Novelty, ", + "\n AccidentYear = x.Identity.AccidentYear,", + "\n AmountType = x.Identity.AmountType,", + "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition });", + "\n}", + "\n", + "\npublic interface EmptyPvIfrsVariable: PvToIfrsVariable{", + "\n IEnumerable PvToIfrsVariable.PvLocked => Enumerable.Empty();", + "\n IEnumerable PvToIfrsVariable.PvCurrent => Enumerable.Empty();", + "\n}", + "\n" ], "metadata": {}, "execution_count": 0, @@ -444,7 +452,7 @@ { "cell_type": "markdown", "source": [ - "## Tm" + "## Techincal Margin" ], "metadata": {}, "execution_count": 0, @@ -455,6 +463,9 @@ "source": [ "public interface TmToIfrsVariable: IScope", "\n{", + "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", + "\n builder.ForScope(s => s.WithApplicability(x => ComputationHelper.AocStepWithNoCsm.Contains(new AocStep(x.Identity.AocType, x.Identity.Novelty))));", + "\n", "\n private string economicBasis => Identity.ValuationApproach == ValuationApproaches.VFA ? EconomicBases.C : EconomicBases.L;", "\n private IEnumerable amountTypesForTm =>GetScope((Identity.DataNode, EstimateTypes.C)).Values;", "\n private bool hasTechnicalMargin => GetStorage().GetRawVariables(Identity.DataNode).Any(x => x.EstimateType == EstimateTypes.RA || ", @@ -468,7 +479,7 @@ "\n DataNode = x.Identity.Id.DataNode,", "\n AocType = x.Identity.Id.AocType,", "\n Novelty = x.Identity.Id.Novelty,", - "\n AmountType = x.EffectiveAmountType, //??", + "\n AmountType = x.EffectiveAmountType,", "\n EconomicBasis = x.EconomicBasis,", "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition", @@ -508,6 +519,11 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition", "\n });", + "\n}", + "\n", + "\npublic interface EmptyTmIfrsVariable: TmToIfrsVariable {", + "\n IEnumerable TmToIfrsVariable.Csms => Enumerable.Empty();", + "\n IEnumerable TmToIfrsVariable.Loss => Enumerable.Empty();", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 043c2961..d61b9292 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1705,7 +1705,7 @@ "\n // Checking if there are inconsistencies in the TechnicalMarginEstimateTypes --> double entries in the steps where we expect to have unique values", "\n var invalidVariables = await workspace.Query()", "\n .Where(iv => parsingStorage.TechnicalMarginEstimateTypes.Contains(iv.EstimateType))", - "\n .Where(iv => iv.AocType == AocTypes.BOP || iv.AocType == AocTypes.EOP || iv.AocType == AocTypes.AM || iv.AocType == AocTypes.EA)", + "\n .Where(iv => GetAocTypeWithoutCsmSwitch().Contains(iv.AocType))", "\n .GroupBy(iv => new {iv.DataNode, iv.AocType, iv.Novelty})", "\n .Where(g => g.Count() > 1)", "\n .Select(g => g.Key)", diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index bba0a271..7f9eac53 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -356,7 +356,25 @@ { "cell_type": "markdown", "source": [ - "# Helper variables used in calculation", + "## Simple Value and Opening Importer" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static HashSet GetAocTypeWithoutCsmSwitch() => new []{AocTypes.BOP, AocTypes.EOP, AocTypes.AM, AocTypes.EA}.ToHashSet();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Helper variables used in import calculation", "\n", "\nVariables defined here and used in the calculation:", "\n- AocTypeWithNoPv : used in [Present Value](../Import/2ImportScope-PresentValue#present-value-1) to trigger no calculation for some AoC Type.", @@ -370,7 +388,8 @@ "cell_type": "code", "source": [ "public static class ComputationHelper{", - "\n public static string [] AocTypeWithNoPv = new string[]{AocTypes.BOP, AocTypes.EA, AocTypes.AM, AocTypes.RCU};", + "\n public static HashSet AocStepWithNoPv = new AocStep[]{new AocStep(AocTypes.EA, Novelties.C), new AocStep(AocTypes.AM, Novelties.C), new AocStep(AocTypes.RCU, Novelties.I),}.ToHashSet();", + "\n public static HashSet AocStepWithNoCsm = new AocStep[]{new AocStep(AocTypes.CF, Novelties.C),new AocStep(AocTypes.WO, Novelties.C)}.ToHashSet();", "\n public static Dictionary> ReferenceAocSteps => new Dictionary>()", "\n {", "\n {new AocStep(AocTypes.EA ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CF,Novelties.C)}},", From a2195b149c1886b63f979375b047c9a8c279278e Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 18 Jul 2023 09:51:39 +0200 Subject: [PATCH 15/24] improve GetReleasePattern + clear CSM-LC calc for PAA # Conflicts: # ifrs17/Import/5ImportScope-ToIfrsVar.ipynb --- ifrs17/Constants/Validations.ipynb | 3 +- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 89 +++++++++++----------- ifrs17/Import/ImportStorage.ipynb | 19 +++-- 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index e759d396..b85906dc 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -80,7 +80,7 @@ "\n ReinsuranceCoverageDataNode, DuplicateInterDataNode, DuplicateSingleDataNode, InvalidDataNode, InvalidDataNodeForOpening, InvalidCashFlowPeriodicity, MissingInterpolationMethod, InvalidInterpolationMethod, InvalidEconomicBasisDriver, InvalidReleasePattern,", "\n // Storage", "\n DataNodeNotFound, PartnerNotFound, PeriodNotFound, RatingNotFound, CreditDefaultRateNotFound, MissingPremiumAllocation, ReinsuranceCoverage, ", - "\n YieldCurveNotFound, YieldCurvePeriodNotApplicable, EconomicBasisNotFound, AccountingVariableTypeNotFound, InvalidGric, InvalidGic, ", + "\n YieldCurveNotFound, YieldCurvePeriodNotApplicable, EconomicBasisNotFound, AccountingVariableTypeNotFound, InvalidGric, InvalidGic, ReleasePatternNotFound,", "\n // Scopes", "\n NotSupportedAocStepReference, MultipleEoP,", "\n // Data completeness", @@ -176,6 +176,7 @@ "\n (Error.AccountingVariableTypeNotFound , 1) => $\"AccountingVariableType {s[0]} not found.\",", "\n (Error.InvalidGric , 1) => $\"Invalid Group of Reinsurance Contract {s[0]} has been requested during calculation.\",", "\n (Error.InvalidGic , 1) => $\"Invalid Group of Insurance Contract {s[0]} has been requested during calculation.\",", + "\n (Error.ReleasePatternNotFound , 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found during calculation.\",", "\n // Scopes", "\n (Error.NotSupportedAocStepReference , 1) => $\"Unsupported reference AoC Step for AoC Type {s[0]}.\",", "\n (Error.MultipleEoP , 0) => $\"Closing Balance for both Csm and Lc are computed.\",", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index f064fd31..dc20d475 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -473,52 +473,51 @@ "\n GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => GetTechnicalMarginEstimateType().Contains(x.EstimateType));", "\n", "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM", - "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis))", - "\n .RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AmountType = x.EffectiveAmountType,", - "\n EconomicBasis = x.EconomicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n })", - "\n : Enumerable.Empty();", - "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || ", - "\n (Identity.ValuationApproach == ValuationApproaches.PAA && !hasTechnicalMargin )", - "\n ? Enumerable.Empty()", - "\n : GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AmountType = x.EffectiveAmountType,", + "\n EconomicBasis = x.EconomicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n })", + "\n : Enumerable.Empty();", + "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || Identity.ValuationApproach == ValuationApproaches.PAA", + "\n ? Enumerable.Empty()", + "\n : GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n });", "\n", - "\n IEnumerable Loss => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC", - "\n ? Enumerable.Empty()", - "\n : Identity.IsReinsurance ", - "\n ? GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n })", - "\n : GetScope(Identity).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.DataNode,", - "\n AocType = x.Identity.AocType,", - "\n Novelty = x.Identity.Novelty,", - "\n EconomicBasis = economicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n });", + "\n IEnumerable Loss => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC ||", + "\n (Identity.ValuationApproach == ValuationApproaches.PAA && !hasTechnicalMargin )", + "\n ? Enumerable.Empty()", + "\n : Identity.IsReinsurance ", + "\n ? GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n })", + "\n : GetScope(Identity).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.DataNode,", + "\n AocType = x.Identity.AocType,", + "\n Novelty = x.Identity.Novelty,", + "\n EconomicBasis = economicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n });", "\n}", "\n", "\npublic interface EmptyTmIfrsVariable: TmToIfrsVariable {", diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index e4df433c..447948ff 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -403,14 +403,19 @@ "\n if (patternFromCashflow.Any())", "\n return (amountType, Enumerable.Repeat(0d, patternShift).Concat(patternFromCashflow).ToArray());", "\n ", - "\n double[] patternFromParameter = Enumerable.Empty().ToArray();", - "\n if(!SingleDataNodeParametersByGoc.TryGetValue(identity.DataNode, out var dataNodeParameterByPeriod))", - "\n return (null, patternFromParameter);", + "\n if(SingleDataNodeParametersByGoc.TryGetValue(identity.DataNode, out var dataNodeParameterByPeriod) && dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern != null){", + "\n var annualCohort = DataNodeDataBySystemName[identity.DataNode].AnnualCohort;", + "\n var skipMonthsToCurrentReportingPeriod = MonthInAYear * (CurrentReportingPeriod.Year - annualCohort);", + "\n var monthlyPattern = dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern.Interpolate(dataNodeParameterByPeriod[CurrentPeriod].CashFlowPeriodicity, dataNodeParameterByPeriod[CurrentPeriod].InterpolationMethod);", + "\n return (null, Enumerable.Repeat(0d, patternShift).Concat(monthlyPattern.Normalize()).Skip(skipMonthsToCurrentReportingPeriod).ToArray());", + "\n }", + "\n", + "\n var patternFromCoverageUnits = GetValues(identity with {AocType = AocTypes.CL, Novelty = Novelties.C}, AmountTypes.CU, EstimateTypes.P, (int?)null);", + "\n if (patternFromCoverageUnits.Any())", + "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n var annualCohort = DataNodeDataBySystemName[identity.DataNode].AnnualCohort;", - "\n var skipMonthsToCurrentReportingPeriod = MonthInAYear * (CurrentReportingPeriod.Year - annualCohort);", - "\n var monthlyPattern = dataNodeParameterByPeriod[CurrentPeriod].ReleasePattern.Interpolate(dataNodeParameterByPeriod[CurrentPeriod].CashFlowPeriodicity, dataNodeParameterByPeriod[CurrentPeriod].InterpolationMethod);", - "\n return (null, Enumerable.Repeat(0d, patternShift).Concat(monthlyPattern.Normalize()).Skip(skipMonthsToCurrentReportingPeriod).ToArray());", + "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ", "\n public double GetPremiumAllocationFactor(ImportIdentity id) => ", From e27a871fc6e9113192298592d7006e42ff6df79e Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 18 Jul 2023 22:02:50 +0200 Subject: [PATCH 16/24] merge issue --- ifrs17/Utils/ImportCalculationMethods.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 7f9eac53..082b74a1 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -397,6 +397,7 @@ "\n {new AocStep(AocTypes.EOP ,Novelties.C), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}}, ", "\n {new AocStep(AocTypes.BOP ,Novelties.I), new AocStep[]{new AocStep(AocTypes.CL,Novelties.C)}},//for projections", "\n };", + "\n public static HashSet ReinsuranceAocType = new []{AocTypes.CRU, AocTypes.RCU}.ToHashSet();", "\n} " ], "metadata": {}, From 1158e624cef358c2a9adfae2119e47d547b96c44 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Tue, 18 Jul 2023 22:14:10 +0200 Subject: [PATCH 17/24] wip --- ifrs17-template/Test/ReimportTest.ipynb | 1 + ifrs17/Import/3ImportScope-Actuals.ipynb | 6 +-- .../Import/4ImportScope-TechnicalMargin.ipynb | 10 +++-- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 38 +++++++++++-------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ifrs17-template/Test/ReimportTest.ipynb b/ifrs17-template/Test/ReimportTest.ipynb index 13952d0b..0a886ea3 100644 --- a/ifrs17-template/Test/ReimportTest.ipynb +++ b/ifrs17-template/Test/ReimportTest.ipynb @@ -308,6 +308,7 @@ "\n@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20", "\nDTR1.1,PR,BE,CL,C,,0,-57.5,0,0,-57.5,0,0,-57.5,0,0,-57.5,0,0,0,0,0,0,0,0,0,0", + "\nDTR1.1,CU,P,CL,C,,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0", "\nDTR1.1,NIC,BE,CL,C,,15,15,15,15,15,15,15,15,15,15,15,15,0,0,0,0,0,0,0,0,0", "\nDTR1.1,,RA,CL,C,,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,0,0,0,0,0,0,0,0,0\";" ], diff --git a/ifrs17/Import/3ImportScope-Actuals.ipynb b/ifrs17/Import/3ImportScope-Actuals.ipynb index 3df31969..ed072c6a 100644 --- a/ifrs17/Import/3ImportScope-Actuals.ipynb +++ b/ifrs17/Import/3ImportScope-Actuals.ipynb @@ -348,7 +348,7 @@ "\n private double AmortizationFactor => GetScope(Identity, o => o.WithContext(EconomicBasis)).Value;", "\n private double AggregatedDeferrable => GetScope((Identity, InputSource.Actual)).Values", "\n .Sum(aocStep => GetScope(Identity with {AocType = aocStep.AocType, Novelty = aocStep.Novelty}).Value);", - "\n double DeferrableActual.Value => -1d * AggregatedDeferrable * AmortizationFactor;", + "\n double DeferrableActual.Value => Math.Abs(AggregatedDeferrable) > Precision ? -1d * AggregatedDeferrable * AmortizationFactor : default;", "\n}", "\n", "\npublic interface EndOfPeriodDeferrable : DeferrableActual{", @@ -450,7 +450,7 @@ "\n private double AmortizationFactor => GetScope(Identity, o => o.WithContext(EconomicBasis)).Value;", "\n private double AggregatedValue => GetScope((Identity, InputSource.Cashflow)).Values", "\n .Sum(aocStep => GetScope(Identity with {AocType = aocStep.AocType, Novelty = aocStep.Novelty}).Value);", - "\n double DiscountedDeferrable.Value => -1d * AggregatedValue * AmortizationFactor;", + "\n double DiscountedDeferrable.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * AmortizationFactor : default;", "\n}", "\n", "\npublic interface DeferrableEoP : DiscountedDeferrable {", @@ -558,7 +558,7 @@ "\n private IEnumerable referenceAocSteps => GetScope(Identity.Id).Values; //Reference step of AM,C is CL,C", "\n private double referenceCashflow => referenceAocSteps.Sum(refAocStep => GetScope((Identity.Id with {AocType = refAocStep.AocType, Novelty = refAocStep.Novelty}, Identity.MonthlyShift)).Value);", "\n", - "\n double NominalDeferrable.Value => -1d * referenceCashflow * GetScope((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value;", + "\n double NominalDeferrable.Value => Math.Abs(referenceCashflow) > Precision ? -1d * referenceCashflow * GetScope((Identity.Id, AmountTypes.DAE, Identity.MonthlyShift), o => o.WithContext(EconomicBasis)).Value : default;", "\n}", "\n", "\npublic interface EopDeferrable : NominalDeferrable{", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index b2ca659d..0de9785b 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -270,7 +270,7 @@ "\n ", "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", - "\n double Value => GetScope((Identity.DataNode, estimateType)).Values", + "\n double Value => GetScope((Identity.DataNode, estimateType)).Values ////TODO. PAA should use PR-Revenue and DAE-Allocated (allocated to the period)? ", "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +", "\n GetScope((Identity, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value;", "\n ", @@ -338,7 +338,9 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.ValuationApproach == ValuationApproaches.PAA)); ", "\n ", - "\n double TechnicalMargin.Value => -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value;", + "\n double TechnicalMargin.Value => Math.Abs(AggregatedValue) > Precision", + "\n ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value", + "\n : default;", "\n}", "\n", "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", @@ -769,7 +771,9 @@ "\n", "\npublic interface LossRecoveryComponentForAm : LossRecoveryComponent{", "\n private string economicBasis => GetScope(Identity).EconomicBasis;", - "\n double LossRecoveryComponent.Value => -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value;", + "\n double LossRecoveryComponent.Value => Math.Abs(AggregatedValue) > Precision ", + "\n ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value", + "\n : default;", "\n}", "\n", "\npublic interface LossRecoveryComponentForEop : LossRecoveryComponent{", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index dc20d475..7c9100ae 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -366,9 +366,12 @@ "public interface DeferrableAmortizationFactorToIfrsVariable: IScope", "\n{", "\n private string EconomicBasis => GetStorage().GetEconomicBasisDriver(Identity.DataNode);", + "\n private bool hasAmortizationStep => GetStorage().DataNodeDataBySystemName[Identity.DataNode].ValuationApproach == ValuationApproaches.PAA", + "\n ? GetScope(Identity).Deferrable.Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n : GetScope(Identity).DeferrableActual.Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision);", "\n", - "\n IEnumerable DeferrableAmFactor => (GetStorage().GetEconomicBasisDriver(Identity.DataNode), Identity.AocType) switch {", - "\n (EconomicBases.N, AocTypes.AM) => GetScope(Identity).Deferrable", + "\n IEnumerable DeferrableAmFactor => (hasAmortizationStep, GetStorage().GetEconomicBasisDriver(Identity.DataNode), Identity.AocType, GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType) switch {", + "\n (true, EconomicBases.N, AocTypes.AM, LiabilityTypes.LRC) => GetScope(Identity).Deferrable", "\n .Where(x => x.Values != null && Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) >= Precision)", "\n .Select(x => x.AccidentYear.Value).SelectMany(shift => ", "\n GetScope((Identity, AmountTypes.DAE, shift), o => o.WithContext(EconomicBases.N)).RepeatOnce() //hardcoded AmountType: DAE for pattern", @@ -382,7 +385,7 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }", "\n )),", - "\n (_, AocTypes.AM) => GetScope(Identity, o => o.WithContext(EconomicBasis)).RepeatOnce()", + "\n (true, _, AocTypes.AM, LiabilityTypes.LRC) => GetScope(Identity, o => o.WithContext(EconomicBasis)).RepeatOnce()", "\n .Select(x => new IfrsVariable{ EstimateType = EstimateTypes.F,", "\n EconomicBasis = EconomicBasis,", "\n DataNode = x.Identity.DataNode,", @@ -392,7 +395,7 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }", "\n ),", - "\n (_, _) => Enumerable.Empty(),", + "\n (_, _, _, _) => Enumerable.Empty(),", "\n };", "\n}" ], @@ -472,18 +475,6 @@ "\n (x.EstimateType == EstimateTypes.BE && amountTypesForTm.Contains(x.AmountType))) || ", "\n GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => GetTechnicalMarginEstimateType().Contains(x.EstimateType));", "\n", - "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM", - "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", - "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", - "\n DataNode = x.Identity.Id.DataNode,", - "\n AocType = x.Identity.Id.AocType,", - "\n Novelty = x.Identity.Id.Novelty,", - "\n AmountType = x.EffectiveAmountType,", - "\n EconomicBasis = x.EconomicBasis,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition", - "\n })", - "\n : Enumerable.Empty();", "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || Identity.ValuationApproach == ValuationApproaches.PAA", "\n ? Enumerable.Empty()", "\n : GetScope(Identity).RepeatOnce()", @@ -518,6 +509,21 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition", "\n });", + "\n ", + "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM && Loss.Concat(Csms).Any(x => Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n && GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC && ", + "\n (Identity.ValuationApproach != ValuationApproaches.PAA || hasTechnicalMargin )", + "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", + "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", + "\n DataNode = x.Identity.Id.DataNode,", + "\n AocType = x.Identity.Id.AocType,", + "\n Novelty = x.Identity.Id.Novelty,", + "\n AmountType = x.EffectiveAmountType,", + "\n EconomicBasis = x.EconomicBasis,", + "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition", + "\n })", + "\n : Enumerable.Empty();", "\n}", "\n", "\npublic interface EmptyTmIfrsVariable: TmToIfrsVariable {", From a6559ff4b9f9180ca6b040431b5f4ac52f194b26 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Wed, 19 Jul 2023 15:28:01 +0200 Subject: [PATCH 18/24] fixes AMF calc and fix test --- .../Test/ScenarioYieldCurveImportTest.ipynb | 7 ++++++- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb index f5f92327..c0c31c3f 100644 --- a/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb +++ b/ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb @@ -634,8 +634,13 @@ "\n@@Cashflow", "\nDataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23", "\nDT1.1,PR,BE,CL,C,,80,0,0,80,0,0,80,0,0,80,0,0,0,80,0,0,80,0,0,80,0,0,80,0", + "\nDT1.1,CU,P,CL,C,,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0", "\nDT1.1,NIC,BE,CL,C,,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3,-22.3", - "\nDT1.1,,RA,CL,C,,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40\";" + "\nDT1.1,,RA,CL,C,,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40,-2.40", + "\nDTR1.1,PR,BE,CL,C,,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0", + "\nDTR1.1,NIC,BE,CL,C,,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5", + "\nDTR1.1,CU,P,CL,C,,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5", + "\nDTR1.1,,RA,CL,C,,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25\";" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 7c9100ae..89f0a5a2 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -471,9 +471,12 @@ "\n", "\n private string economicBasis => Identity.ValuationApproach == ValuationApproaches.VFA ? EconomicBases.C : EconomicBases.L;", "\n private IEnumerable amountTypesForTm =>GetScope((Identity.DataNode, EstimateTypes.C)).Values;", - "\n private bool hasTechnicalMargin => GetStorage().GetRawVariables(Identity.DataNode).Any(x => x.EstimateType == EstimateTypes.RA || ", - "\n (x.EstimateType == EstimateTypes.BE && amountTypesForTm.Contains(x.AmountType))) || ", - "\n GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => GetTechnicalMarginEstimateType().Contains(x.EstimateType));", + "\n private bool hasTechnicalMargin => GetStorage().ImportFormat switch {", + "\n ImportFormats.Cashflow => GetStorage().GetRawVariables(Identity.DataNode).Any(x => x.EstimateType == EstimateTypes.RA || ", + "\n (x.EstimateType == EstimateTypes.BE && amountTypesForTm.Contains(x.AmountType))),", + "\n _ => GetStorage().GetIfrsVariables(Identity.DataNode).Any(x => !GetStorage().EstimateTypesByImportFormat[ImportFormats.Actual].Contains(x.EstimateType) && ", + "\n amountTypesForTm.Contains(x.AmountType))", + "\n };", "\n", "\n IEnumerable Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC || Identity.ValuationApproach == ValuationApproaches.PAA", "\n ? Enumerable.Empty()", @@ -511,7 +514,7 @@ "\n });", "\n ", "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM && Loss.Concat(Csms).Any(x => Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", - "\n && GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC && ", + "\n && GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LRC && ", "\n (Identity.ValuationApproach != ValuationApproaches.PAA || hasTechnicalMargin )", "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", "\n .Select(x => new IfrsVariable{ EstimateType = x.EstimateType,", From d6d7447fcee3b37fdd39a4a45a1be8101d663162 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Wed, 19 Jul 2023 17:28:21 +0200 Subject: [PATCH 19/24] update bm iv --- .../Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv | 4 ---- .../Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv | 4 ---- 2 files changed, 8 deletions(-) diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv index 2bbd39c7..db445632 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2020_12__F.csv @@ -4,14 +4,10 @@ Month,ReportingNode,Scenario,Year @@F AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Values0 ,CU,AM,DT1.1,L,F,C,0.65623 -,,AM,DT1.2,L,F,C,1 ,CU,AM,DT1.3,L,F,C,0.65623 ,CU,AM,DT2.1,L,F,C,0.65623 -,,AM,DT2.2,L,F,C,1 ,CU,AM,DTR1.1,L,F,C,0.65623 -,,AM,DTR1.2,L,F,C,1 ,CU,AM,DTR2.1,L,F,C,0.65623 -,,AM,DTR2.2,L,F,C,1 ,CU,AM,DT3.1,L,F,C,0.65623 ,CU,AM,DT4.1,L,F,C,0.65623 ,CU,AM,DT1.4,L,F,C,0.65623 diff --git a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv index e8653719..348f71d1 100644 --- a/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv +++ b/ifrs17-template/Test/Data/IfrsVariableBenchmarks/BM_CH_2021_3__F.csv @@ -4,14 +4,10 @@ Month,ReportingNode,Scenario,Year @@F AccidentYear,AmountType,AocType,DataNode,EconomicBasis,EstimateType,Novelty,Values0 ,CU,AM,DT1.1,L,F,C,0.32249 -,,AM,DT1.2,L,F,C,1 ,CU,AM,DT1.3,L,F,C,0.32249 ,CU,AM,DT2.1,L,F,C,0.32249 -,,AM,DT2.2,L,F,C,1 ,CU,AM,DTR1.1,L,F,C,0.32249 -,,AM,DTR1.2,L,F,C,1 ,CU,AM,DTR2.1,L,F,C,0.32249 -,,AM,DTR2.2,L,F,C,1 ,,AM,DT3.1,L,F,C,1 ,CU,AM,DT4.1,L,F,C,0.32249 ,CU,AM,DT1.4,L,F,C,0.32249 From d9fd79ce7657ee3a7b37f1e34529e9da61db57b6 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Wed, 19 Jul 2023 17:28:52 +0200 Subject: [PATCH 20/24] filter for null --- ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 89f0a5a2..0dbdc0a3 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -367,8 +367,8 @@ "\n{", "\n private string EconomicBasis => GetStorage().GetEconomicBasisDriver(Identity.DataNode);", "\n private bool hasAmortizationStep => GetStorage().DataNodeDataBySystemName[Identity.DataNode].ValuationApproach == ValuationApproaches.PAA", - "\n ? GetScope(Identity).Deferrable.Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", - "\n : GetScope(Identity).DeferrableActual.Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision);", + "\n ? GetScope(Identity).Deferrable.Where(iv => iv.Values != null).Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n : GetScope(Identity).DeferrableActual.Where(iv => iv.Values != null).Any(iv => Math.Abs(iv.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision);", "\n", "\n IEnumerable DeferrableAmFactor => (hasAmortizationStep, GetStorage().GetEconomicBasisDriver(Identity.DataNode), Identity.AocType, GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType) switch {", "\n (true, EconomicBases.N, AocTypes.AM, LiabilityTypes.LRC) => GetScope(Identity).Deferrable", @@ -513,7 +513,7 @@ "\n Partition = GetStorage().TargetPartition", "\n });", "\n ", - "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM && Loss.Concat(Csms).Any(x => Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", + "\n IEnumerable AmortizationFactor => Identity.AocType == AocTypes.AM && Loss.Concat(Csms).Where(x => x.Values != null).Any(x => Math.Abs(x.Values.GetValidElement(Identity.ProjectionPeriod)) > Precision)", "\n && GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LRC && ", "\n (Identity.ValuationApproach != ValuationApproaches.PAA || hasTechnicalMargin )", "\n ? GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).RepeatOnce()", @@ -532,6 +532,7 @@ "\npublic interface EmptyTmIfrsVariable: TmToIfrsVariable {", "\n IEnumerable TmToIfrsVariable.Csms => Enumerable.Empty();", "\n IEnumerable TmToIfrsVariable.Loss => Enumerable.Empty();", + "\n IEnumerable TmToIfrsVariable.AmortizationFactor => Enumerable.Empty();", "\n}" ], "metadata": {}, From 04e0b502000c0c281c68f544d2aaa04e0131b10a Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 20 Jul 2023 08:27:24 +0200 Subject: [PATCH 21/24] adjust amf from ifrsvariable --- ifrs17/Import/2ImportScope-PresentValue.ipynb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 9e5db689..7858b533 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -903,10 +903,16 @@ "\npublic interface AmfFromIfrsVariable : CurrentPeriodAmortizationFactor{", "\n private double amortizationFactorForAmountType => GetStorage().GetValue(Identity.Id, Identity.AmountType, EstimateType, EconomicBasis, ", "\n Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod); //TODO shift of 0 is a valid value", - "\n double CurrentPeriodAmortizationFactor.Value => Math.Abs(amortizationFactorForAmountType) >= Precision", - "\n ? amortizationFactorForAmountType ", - "\n : GetStorage().GetValue(Identity.Id, null, EstimateType, EconomicBasis, Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", - "\n string CurrentPeriodAmortizationFactor.EffectiveAmountType => Math.Abs(amortizationFactorForAmountType) >= Precision ? Identity.AmountType : null;", + "\n ", + "\n private double amortizationFactorFromPattern => GetStorage().GetValue(Identity.Id, null, EstimateType, EconomicBasis, Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", + "\n ", + "\n private double amortizationFactorForCu => GetStorage().GetValue(Identity.Id, AmountTypes.CU, EstimateType, EconomicBasis, ", + "\n Identity.patternShift == 0 ? null : Identity.patternShift, Identity.Id.ProjectionPeriod);", + "\n", + "\n double CurrentPeriodAmortizationFactor.Value => Math.Abs(amortizationFactorForAmountType) >= Precision ? amortizationFactorForAmountType ", + "\n : Math.Abs(amortizationFactorFromPattern) >= Precision ? amortizationFactorFromPattern : amortizationFactorForCu;", + "\n string CurrentPeriodAmortizationFactor.EffectiveAmountType => Math.Abs(amortizationFactorForAmountType) >= Precision ? Identity.AmountType ", + "\n : Math.Abs(amortizationFactorFromPattern) >= Precision ? null : AmountTypes.CU;", "\n}" ], "metadata": {}, From d3911bc311e856bebee4d6d14a2d3b05728f2361 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 20 Jul 2023 09:35:53 +0200 Subject: [PATCH 22/24] resolve conflict --- ifrs17/Utils/ImportCalculationMethods.ipynb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ifrs17/Utils/ImportCalculationMethods.ipynb b/ifrs17/Utils/ImportCalculationMethods.ipynb index 8b19aea4..e6daa007 100644 --- a/ifrs17/Utils/ImportCalculationMethods.ipynb +++ b/ifrs17/Utils/ImportCalculationMethods.ipynb @@ -252,6 +252,24 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Extend Parsed Raw Variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task ExtendParsedVariables (this IWorkspace workspace, Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache) {}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -357,7 +375,6 @@ "cell_type": "markdown", "source": [ "## Simple Value and Opening Importer" - "## Extend Parsed Variables" ], "metadata": {}, "execution_count": 0, @@ -367,7 +384,6 @@ "cell_type": "code", "source": [ "public static HashSet GetAocTypeWithoutCsmSwitch() => new []{AocTypes.BOP, AocTypes.EOP, AocTypes.AM, AocTypes.EA}.ToHashSet();" - "\npublic static async Task ExtendParsedVariables (this IWorkspace workspace, Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache) {}" ], "metadata": {}, "execution_count": 0, From 8050fadcf070522141e2f8fe4c7660310d64272d Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 20 Jul 2023 09:36:30 +0200 Subject: [PATCH 23/24] validate missing previous period data --- ifrs17/Constants/Validations.ipynb | 2 ++ ifrs17/Import/ImportStorage.ipynb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index b85906dc..e15f5a0f 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -81,6 +81,7 @@ "\n // Storage", "\n DataNodeNotFound, PartnerNotFound, PeriodNotFound, RatingNotFound, CreditDefaultRateNotFound, MissingPremiumAllocation, ReinsuranceCoverage, ", "\n YieldCurveNotFound, YieldCurvePeriodNotApplicable, EconomicBasisNotFound, AccountingVariableTypeNotFound, InvalidGric, InvalidGic, ReleasePatternNotFound,", + "\n MissingPreviousPeriodData,", "\n // Scopes", "\n NotSupportedAocStepReference, MultipleEoP,", "\n // Data completeness", @@ -177,6 +178,7 @@ "\n (Error.InvalidGric , 1) => $\"Invalid Group of Reinsurance Contract {s[0]} has been requested during calculation.\",", "\n (Error.InvalidGic , 1) => $\"Invalid Group of Insurance Contract {s[0]} has been requested during calculation.\",", "\n (Error.ReleasePatternNotFound , 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found during calculation.\",", + "\n (Error.MissingPreviousPeriodData , 3) => $\"Data for previous period (Year: {s[0]}, Month: {s[1]}) is missing for Group of contracts: {s[2]}.\",", "\n // Scopes", "\n (Error.NotSupportedAocStepReference , 1) => $\"Unsupported reference AoC Step for AoC Type {s[0]}.\",", "\n (Error.MultipleEoP , 0) => $\"Closing Balance for both Csm and Lc are computed.\",", diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 447948ff..6077aeed 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -256,7 +256,8 @@ "\n if(allImportScopesNotAtInceptionYear.Any()) {", "\n PreviousPeriodPartition = (await querySource.Query()", "\n .Where(p => p.ReportingNode == args.ReportingNode && p.Year == PreviousReportingPeriod.Year ", - "\n && p.Month == PreviousReportingPeriod.Month && p.Scenario == null).ToArrayAsync()).Single().Id;", + "\n && p.Month == PreviousReportingPeriod.Month && p.Scenario == null).ToArrayAsync()).SingleOrDefault()?.Id ?? ", + "\n (Guid)ApplicationMessage.Log(Error.MissingPreviousPeriodData, PreviousReportingPeriod.Year.ToString(), PreviousReportingPeriod.Month.ToString(), string.Join(\"\",allImportScopesNotAtInceptionYear));", "\n ", "\n await querySource.Partition.SetAsync(PreviousPeriodPartition);", "\n ", From 5a00fd006bae2850795a62712322f22d6cc92c59 Mon Sep 17 00:00:00 2001 From: Davide Colleoni Date: Thu, 20 Jul 2023 10:12:37 +0200 Subject: [PATCH 24/24] pr comments --- ifrs17/Constants/Validations.ipynb | 2 +- ifrs17/Import/4ImportScope-TechnicalMargin.ipynb | 8 ++------ ifrs17/Import/5ImportScope-ToIfrsVar.ipynb | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index e15f5a0f..70075269 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -177,7 +177,7 @@ "\n (Error.AccountingVariableTypeNotFound , 1) => $\"AccountingVariableType {s[0]} not found.\",", "\n (Error.InvalidGric , 1) => $\"Invalid Group of Reinsurance Contract {s[0]} has been requested during calculation.\",", "\n (Error.InvalidGic , 1) => $\"Invalid Group of Insurance Contract {s[0]} has been requested during calculation.\",", - "\n (Error.ReleasePatternNotFound , 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found during calculation.\",", + "\n (Error.ReleasePatternNotFound , 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found.\",", "\n (Error.MissingPreviousPeriodData , 3) => $\"Data for previous period (Year: {s[0]}, Month: {s[1]}) is missing for Group of contracts: {s[2]}.\",", "\n // Scopes", "\n (Error.NotSupportedAocStepReference , 1) => $\"Unsupported reference AoC Step for AoC Type {s[0]}.\",", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index 0de9785b..34f9f1a4 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -338,9 +338,7 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.WithApplicability(x => x.Identity.ValuationApproach == ValuationApproaches.PAA)); ", "\n ", - "\n double TechnicalMargin.Value => Math.Abs(AggregatedValue) > Precision", - "\n ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value", - "\n : default;", + "\n double TechnicalMargin.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(EconomicBasis)).Value : default;", "\n}", "\n", "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", @@ -771,9 +769,7 @@ "\n", "\npublic interface LossRecoveryComponentForAm : LossRecoveryComponent{", "\n private string economicBasis => GetScope(Identity).EconomicBasis;", - "\n double LossRecoveryComponent.Value => Math.Abs(AggregatedValue) > Precision ", - "\n ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value", - "\n : default;", + "\n double LossRecoveryComponent.Value => Math.Abs(AggregatedValue) > Precision ? -1d * AggregatedValue * GetScope((Identity, AmountTypes.CU, 0), o => o.WithContext(economicBasis)).Value : default;", "\n}", "\n", "\npublic interface LossRecoveryComponentForEop : LossRecoveryComponent{", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index 0dbdc0a3..5045632c 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -395,7 +395,7 @@ "\n Values = SetProjectionValue(x.Value, x.Identity.ProjectionPeriod),", "\n Partition = GetStorage().TargetPartition }", "\n ),", - "\n (_, _, _, _) => Enumerable.Empty(),", + "\n (_) => Enumerable.Empty(),", "\n };", "\n}" ],