diff --git a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb index 09cabff5..8c8824e0 100644 --- a/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb +++ b/ifrs17-template/Import/InteractWithImportScopes/EvaluateImportScopes.ipynb @@ -307,53 +307,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Temporary test of DAC for PAA" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var iv = Enumerable.Range(0,5).SelectMany(p=>", - "\n Scopes.ForIdentities(identities.Select(id => id with {ProjectionPeriod=p}), storage)", - "\n .ToScopes().SelectMany(x => x.Deferrable))", - "\n.AggregateProjections().Where(x => x.Values.Any(v => Math.Abs(v) > Precision ))", - "\n.ToArray();", - "\n", - "\nvar eops= iv.Where(x => x.AocType == \"EOP\");", - "\nvar ams = iv.Where(x => x.AocType == \"AM\" && x.EstimateType == \"DA\");", - "\n", - "\niv" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "//Testing", - "\n(Math.Abs(eops.Single(x => x.AccidentYear == 0).Values.First() - 647.5)< Precision, Math.Abs(eops.Single(x => x.AccidentYear == 2).Values.First() - 918.125)< Precision, ", - "\nMath.Abs(ams.Single(x => x.AccidentYear == 0).Values.First() - -352.5)< Precision, Math.Abs(ams.Single(x => x.AccidentYear == 2).Values.First() - -381.87499999999994)< Precision)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 8e654e7d..4c8d05b8 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -75,6 +75,10 @@ "\n public static readonly Warning VariablesAlreadyCalculated = new Warning(nameof(VariablesAlreadyCalculated));", "\n public static readonly Warning ScenarioReCalculations = new Warning(nameof(ScenarioReCalculations));", "\n public static readonly Warning MandatoryAocStepMissing = new Warning(nameof(MandatoryAocStepMissing));", + "\n", + "\n // ImportStorage", + "\n public static readonly Warning ReleasePatternNotFound = new Warning(nameof(ReleasePatternNotFound));", + "\n", "\n public static readonly Warning Generic = new Warning(nameof(Generic));", "\n", "\n public override string GetMessage(params string[] s) => (MessageCode, s.Length) switch{", @@ -82,6 +86,8 @@ "\n (nameof(VariablesAlreadyImported), 0) => $\"The import of the current file does not contain any new data. Hence, no data will be saved or calculations will be performed.\",", "\n (nameof(MandatoryAocStepMissing), 3) => $\"The AoC step ({s[0]}, {s[1]}) is not imported for ({s[2]}).\",", "\n (nameof(ScenarioReCalculations), 1) => $\"The present Best Estimate import makes the result of dependent Scenarios out of date. Hence, the following Scenarios are re-calculated: {s[0]}.\", ", + "\n // ImportStorage", + "\n (nameof(ReleasePatternNotFound), 2) => $\"Release pattern for Group of Contract {s[0]} and AmountType {s[1]} is not found.\",", "\n // Default", "\n (nameof(Generic), _) => $\"{s[0]}\",", "\n _ => DefaultMessage", diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 0c70abf5..9bed0249 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -1873,6 +1873,9 @@ "\n ", "\n [NotVisible]", "\n public string ValuationApproach { get; init; }", + "\n", + "\n [NotVisible]", + "\n public string LiabilityType { get; init; }", "\n ", "\n [NotVisible]", "\n public int ProjectionPeriod { get; init; }", diff --git a/ifrs17/Import/1ImportScope-Identities.ipynb b/ifrs17/Import/1ImportScope-Identities.ipynb index c20a14d0..63470857 100644 --- a/ifrs17/Import/1ImportScope-Identities.ipynb +++ b/ifrs17/Import/1ImportScope-Identities.ipynb @@ -146,7 +146,8 @@ "\n protected IEnumerable allIdentities => GetStorage().AocConfigurationByAocStep.Values.Select(x => new ImportIdentity {AocType = x.AocType, Novelty = x.Novelty, DataNode = Identity });", "\n", "\n IEnumerable Identities => allIdentities.Select(id => id with { IsReinsurance = GetStorage().DataNodeDataBySystemName[id.DataNode].IsReinsurance,", - "\n ValuationApproach = GetStorage().DataNodeDataBySystemName[id.DataNode].ValuationApproach});", + "\n ValuationApproach = GetStorage().DataNodeDataBySystemName[id.DataNode].ValuationApproach,", + "\n LiabilityType = GetStorage().DataNodeDataBySystemName[id.DataNode].LiabilityType });", "\n}", "\n", "\npublic interface GetCashflowIdentities : GetIdentities", diff --git a/ifrs17/Import/2ImportScope-PresentValue.ipynb b/ifrs17/Import/2ImportScope-PresentValue.ipynb index 65f4017d..c01e0b1b 100644 --- a/ifrs17/Import/2ImportScope-PresentValue.ipynb +++ b/ifrs17/Import/2ImportScope-PresentValue.ipynb @@ -166,16 +166,35 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if it is NOT CL AND NOT EOP AND", - "\n x.Identity.Id.Novelty != Novelties.I && // if it is NOT inforce", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", - "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (LRC OR LIC with AY < than projected FY)", + "\n (x.Identity.Id.AocType != AocTypes.CL && x.Identity.Id.AocType != AocTypes.EOP) && // if AocType is NOT CL AND NOT EOP AND", + "\n x.Identity.Id.Novelty != Novelties.I && // if Novelty is NOT inforce AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n !(x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES NOT (have AY and with AY >= than projected FY)", "\n )", "\n .WithApplicability(x =>", - "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if it is BOP, CF or IA (or not in telescopic) AND", - "\n x.Identity.Id.Novelty == Novelties.I && // if it is inforce", - "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection > 1 Year AND", - "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it is (LIC AND AY is >= than projected FY)", + "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if AocType is BOP, CF or IA (or not in telescopic) AND", + "\n x.Identity.Id.Novelty == Novelties.I && // if Novelty is inforce AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LIC && // if LiabilityType is LIC AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY >= than projected FY)", + "\n )", + "\n .WithApplicability(x =>", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && // if LiabilityType is LRC", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear < (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY < than projected FY)", + "\n )", + "\n .WithApplicability(x =>", + "\n (x.Identity.Id.AocType == AocTypes.BOP || x.Identity.Id.AocType == AocTypes.CF || x.Identity.Id.AocType == AocTypes.IA) && // if AocType is BOP, CF or IA (or not in telescopic) AND", + "\n (x.Identity.Id.Novelty != Novelties.I && x.Identity.Id.Novelty != Novelties.C) && // if Novelty is NOT inforce AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && // if LiabilityType is LRC AND", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) >= MonthInAYear && // if it is projection >= 1 Year AND", + "\n (x.Identity.AccidentYear.HasValue && MonthInAYear * x.Identity.AccidentYear >= (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if it DOES (have AY and with AY >= than projected FY)", + "\n )", + "\n .WithApplicability(x =>", + "\n (x.Identity.Id.AocType == AocTypes.CF) && // if AocType is CF AND", + "\n x.Identity.Id.LiabilityType == LiabilityTypes.LRC && x.Identity.AccidentYear.HasValue && // if LiabilityType is LRC with AY defined", + "\n x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod) == 0 && // if it is projection == 0 AND", + "\n !(MonthInAYear * x.Identity.AccidentYear == (MonthInAYear * x.GetStorage().CurrentReportingPeriod.Year + x.GetStorage().GetShift(x.Identity.Id.ProjectionPeriod))) // if AY == projected FY", "\n )", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType) && x.Identity.Id.AocType == AocTypes.CF)", "\n .WithApplicability(x => x.GetStorage().GetCdr().Contains(x.Identity.AmountType))", @@ -375,7 +394,7 @@ { "cell_type": "markdown", "source": [ - "## Present Value", + "## Valuation Period ", "\n", "\nThe present value ($\\rm{PV}$) can be determined by taking the appropriate elements of the cumulated discounted cash flows. This is done as function of the two [projection parameters](../DataModel/DataStructure#projection-configuration) $\\rm{Shift}$ ($S$) and $\\rm{TimeStep}$ ($TS$):", "\n", @@ -405,8 +424,13 @@ "public interface IWithGetValueFromValues : IScope<(ImportIdentity Id, string AmountType, string EstimateType, int? AccidentYear), ImportStorage>", "\n{", "\n private int shift => GetStorage().GetShift(Identity.Id.ProjectionPeriod);", - "\n private int timeStep => GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", - "\n ", + "\n private int timeStep => ", + "\n Identity.Id.LiabilityType == LiabilityTypes.LRC && ", + "\n Identity.AccidentYear.HasValue && ", + "\n (MonthInAYear * Identity.AccidentYear == (MonthInAYear * GetStorage().CurrentReportingPeriod.Year + GetStorage().GetShift(Identity.Id.ProjectionPeriod)))", + "\n ? int.MaxValue", + "\n : GetStorage().GetTimeStep(Identity.Id.ProjectionPeriod);", + "\n", "\n public double GetValueFromValues(double[] Values, string overrideValuationPeriod = null)", "\n {", "\n var valuationPeriod = Enum.TryParse(overrideValuationPeriod, out ValuationPeriod ret) ? ret : GetStorage().GetValuationPeriod(Identity.Id);", @@ -622,11 +646,50 @@ { "cell_type": "markdown", "source": [ - "## Current and Locked", - "\n", - "\nPV Current and PV Locked below basically hold the Present Values [PV](#present-value) computed using the **Current** yield curves and the **Locked** yield curves, respectively.", + "## Wrapper over Accident Year", + "\nPresent Value are here collected for all available Accident Year for any combination of [Amount Type](../DataModel/DataStructure#amount-type) and [Estimate Type](../DataModel/DataStructure#estimate-type) specified in input (scope identity). In addition, the sum of present values over the available Accident Years is also provided. " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public interface PvAggregatedOverAccidentYear : IScope<(ImportIdentity Id, string AmountType, string EstimateType), ImportStorage>", + "\n{ ", + "\n [IdentityProperty][NotVisible][Dimension(typeof(EconomicBasis))]", + "\n string EconomicBasis => GetContext();", + "\n ", + "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.Id.DataNode, Identity.Id.ProjectionPeriod).ToArray(); ", + "\n ", + "\n [NotVisible]", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => accidentYears.Select(ay => ", + "\n (Identity.AmountType, Identity.EstimateType, ay, GetScope((Identity.Id, Identity.AmountType, Identity.EstimateType, ay), o => o.WithContext(EconomicBasis)).Value))", + "\n .ToArray();", + "\n ", + "\n double Value => PresentValues.Sum(pv => pv.Value);", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Best Estimate" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "PV Current and PV Locked below basically hold the Present Values [PV](#present-value) computed using the **Current** yield curves and the **Locked** yield curves, respectively.", "\n", - "\nValues are available for each AmountType (by calling PvLocked.ByAmountType):", + "\nValues are available for each AmountType and AccidentYear (by calling PvLocked.PresentValues):", "\n", "\n$$", "\n\\text{PV Locked}(\\text{AoC step}, \\text{Amount Type}) = \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = L}}", @@ -636,18 +699,9 @@ "\n\\text{PV Current}(\\text{AoC step}, \\text{Amount Type}) = \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = C}}", "\n$$", "\n", + "\nAggregated present values are also available through summing over Amount Types and Accident Year (by calling PvLocked.PresentValues.Sum(pv => pv.Value)).", "\n", - "\nAnd aggregated values are also available as the sum over all [Amount Types](../DataModel/DataStructure#amount-type) (by calling PvLocked.Value):", - "\n", - "\n$$", - "\n\\text{PV Locked}(\\text{AoC step}) = \\sum_{\\text{Amount Types}} \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = L}}", - "\n$$", - "\n", - "\n$$", - "\n\\text{PV Current}(\\text{AoC step}) = \\sum_{\\text{Amount Types}} \\text{PV}(\\text{AoC step}, \\text{Amount Type})|_{\\text{Economic Base = C}}", - "\n$$", - "\n", - "\nThese are used in the BBA methodology, whereby in the CSM calculations only PV Locked is used, and both of them are stored in the database under the [IfrsVariable](../DataModel/DataStructure#ifrs-variable) data structure." + "\nPV Current and PV Locked are both computed in the BBA methodology, although the CSM calculations uses only PV Locked for BBA valuation approach and PV Current for VFA valuation approach. Depending on the valuation approach Present Values Locked and/or Present Values current are stored in the database under the [IfrsVariable](../DataModel/DataStructure#ifrs-variable) data structure." ], "metadata": {}, "execution_count": 0, @@ -663,15 +717,11 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", + "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", "\n}" ], "metadata": {}, @@ -688,31 +738,17 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", + "\n", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", "\n}" ], "metadata": {}, "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "## Nominal" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -723,15 +759,10 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.BE;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", - "\n .SelectMany(at => accidentYears", - "\n .Select(ay => GetScope((Identity, at, EstimateType, ay), o => o.WithContext(EconomicBasis))))", - "\n .ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope(Identity.DataNode).BeAmountTypes", + "\n .SelectMany(at => GetScope((Identity, at, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues", + "\n ).ToArray();", "\n}" ], "metadata": {}, @@ -769,12 +800,9 @@ "\n ", "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", - "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n", + "\n [NotVisible]", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", "\n}" ], "metadata": {}, @@ -792,11 +820,8 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray(); ", - "\n ", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray(); ", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n [NotVisible]", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", "\n}" ], "metadata": {}, @@ -813,12 +838,8 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(EstimateType))]", "\n string EstimateType => EstimateTypes.RA;", "\n ", - "\n private int?[] accidentYears => GetStorage().GetAccidentYears(Identity.DataNode, Identity.ProjectionPeriod).ToArray();", - "\n ", "\n [NotVisible]", - "\n PresentValue[] PresentValues => accidentYears.Select(ay => GetScope((Identity, (string)null, EstimateType, ay), o => o.WithContext(EconomicBasis))).ToArray();", - "\n ", - "\n double Value => PresentValues.Aggregate().Value;", + "\n (string AmountType, string EstimateType, int? AccidentYear, double Value)[] PresentValues => GetScope((Identity, (string)null, EstimateType), o => o.WithContext(EconomicBasis)).PresentValues;", "\n}" ], "metadata": {}, @@ -839,7 +860,7 @@ { "cell_type": "markdown", "source": [ - "## Amortization Factor" + "## Monthly AM Factor" ], "metadata": {}, "execution_count": 0, @@ -911,7 +932,8 @@ { "cell_type": "markdown", "source": [ - "For a certain projection period - defined by the Shift, $S$, and the Time-Step, $TS$, parameters - the Amortization Factor is then given by the product of the corresponding monthly amortization factors:", + "## Current Period AM actor", + "\nFor a certain projection period - defined by the Shift, $S$, and the Time-Step, $TS$, parameters - the Amortization Factor is then given by the product of the corresponding monthly amortization factors:", "\n", "\n$$", "\nAF = 1 - \\prod _{i = S}^{S + TS - 1} \\text{Monthly }AF_i ~.", diff --git a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb index f7bd8d39..cd4d2957 100644 --- a/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb +++ b/ifrs17/Import/4ImportScope-TechnicalMargin.ipynb @@ -120,7 +120,7 @@ "\n [IdentityProperty][NotVisible][Dimension(typeof(AmountType))] string AmountType => AmountTypes.PR;", "\n", "\n double Value => GetStorage().GetPremiumAllocationFactor(Identity) * ", - "\n GetStorage().GetPremiums().Sum(pr => GetScope((Identity, pr, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value);", + "\n GetStorage().GetPremiums().Sum(pr => GetScope((Identity, pr, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value);", "\n}", "\n", "\npublic interface DefaultValueBeExperienceAdjustmentForPremium : BeExperienceAdjustmentForPremium{", @@ -280,8 +280,8 @@ "\n protected string estimateType => GetContext();", "\n [NotVisible] string EconomicBasis => EconomicBases.L;", "\n double Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +", - "\n GetScope((Identity, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value;", + "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value;", "\n ", "\n double AggregatedValue => GetScope((Identity, InputSource.Cashflow)).Values", "\n .Sum(aoc => GetScope(Identity with {AocType = aoc.AocType, Novelty = aoc.Novelty}).Value);", @@ -294,8 +294,8 @@ "\npublic interface TechnicalMarginForPaa : TechnicalMargin{", "\n [NotVisible] string TechnicalMargin.EconomicBasis => EconomicBases.C;", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) +", - "\n GetScope((Identity, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value +", + "\n .Sum(at => GetScope((Identity, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) +", + "\n GetScope((Identity, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value +", "\n GetScope(Identity).Value + GetScope(Identity).Value;", "\n}", "\n", @@ -330,10 +330,10 @@ "\n .Sum(n => GetScope(Identity with {AocType = referenceAocType, Novelty = n}, o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope(Identity with {AocType = referenceAocType, Novelty = Novelties.C}).Value;", "\n protected double deferrable => GetStorage().GetDeferrableExpenses().Sum(d =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, d, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, d, EstimateTypes.A, (int?)null)).Value);", "\n protected double investmentClaims => GetStorage().GetInvestmentClaims().Sum(ic =>", - "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value) -", + "\n GetStorage().GetNovelties(referenceAocType, InputSource.Cashflow).Sum(n => GetScope((Identity with {AocType = referenceAocType, Novelty = n}, ic, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value) -", "\n GetScope((Identity with {AocType = referenceAocType, Novelty = Novelties.C}, ic, EstimateTypes.A, (int?)null)).Value);", "\n ", "\n double TechnicalMargin.Value => premiums + deferrable + investmentClaims;", @@ -354,8 +354,8 @@ "\npublic interface TechnicalMarginForAmForPaa : TechnicalMargin{", "\n private IEnumerable novelties => GetStorage().GetNovelties(AocTypes.CF).Where(novelty => novelty != Novelties.C);", "\n double TechnicalMargin.Value => GetScope((Identity, estimateType)).Values", - "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE, (int?)null), o => o.WithContext(EconomicBasis)).Value + ", - "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA, (int?)null), o => o.WithContext(EconomicBasis)).Value));", + "\n .Sum(at => novelties.Sum(n => GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, at, EstimateTypes.BE), o => o.WithContext(EconomicBasis)).Value + ", + "\n GetScope((Identity with {AocType = AocTypes.CF, Novelty = n}, (string)null, EstimateTypes.RA), o => o.WithContext(EconomicBasis)).Value));", "\n//+ Revenue AM + Deferral AM", "\n", "\n}", diff --git a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb index fcf8696d..aa0ebe69 100644 --- a/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb +++ b/ifrs17/Import/5ImportScope-ToIfrsVar.ipynb @@ -100,26 +100,28 @@ "\n static ApplicabilityBuilder ScopeApplicabilityBuilder(ApplicabilityBuilder builder) =>", "\n builder.ForScope(s => s.WithApplicability(x => ComputationHelper.AocStepWithNoPv.Contains(new AocStep(x.Identity.AocType, x.Identity.Novelty))));", "\n", - "\n IEnumerable PvLocked => GetScope(Identity).PresentValues.Select(x => ", + "\n IEnumerable PvLocked => GetScope(Identity).RepeatOnce().SelectMany(x =>", + "\n x.PresentValues.Select(pv =>", "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", - "\n IEnumerable PvCurrent => GetScope(Identity).PresentValues.Select(x => ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition }));", + "\n IEnumerable PvCurrent => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv =>", "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition }));", "\n}", "\n", "\npublic interface EmptyPvIfrsVariable: PvToIfrsVariable{", @@ -146,17 +148,28 @@ "source": [ "public interface NominalToIfrsVariable: IScope", "\n{", - "\n IEnumerable CumulatedNominal => GetScope(Identity).PresentValues", - "\n .Concat(GetScope(Identity).PresentValues)", - "\n .Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = x.Identity.AmountType,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod), ", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable CumulatedNominal => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}))", + "\n .Concat(GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition})));", "\n}" ], "metadata": {}, @@ -177,27 +190,29 @@ "source": [ "public interface RaToIfrsVariable: IScope", "\n{", - "\n IEnumerable RaCurrent => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable RaCurrent => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}));", "\n ", - "\n IEnumerable RaLocked => GetScope(Identity).PresentValues.Select(x => ", - "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", - "\n EstimateType = x.Identity.EstimateType, ", - "\n DataNode = x.Identity.Id.DataNode, ", - "\n AocType = x.Identity.Id.AocType, ", - "\n Novelty = x.Identity.Id.Novelty, ", - "\n AccidentYear = x.Identity.AccidentYear,", - "\n AmountType = null,", - "\n Values = SetProjectionValue(x.Value, x.Identity.Id.ProjectionPeriod),", - "\n Partition = GetStorage().TargetPartition });", + "\n IEnumerable RaLocked => GetScope(Identity).RepeatOnce().SelectMany(x => ", + "\n x.PresentValues.Select(pv => ", + "\n new IfrsVariable{ EconomicBasis = x.EconomicBasis, ", + "\n EstimateType = x.EstimateType, ", + "\n DataNode = x.Identity.DataNode, ", + "\n AocType = x.Identity.AocType, ", + "\n Novelty = x.Identity.Novelty, ", + "\n AccidentYear = pv.AccidentYear,", + "\n AmountType = pv.AmountType,", + "\n Values = SetProjectionValue(pv.Value, x.Identity.ProjectionPeriod),", + "\n Partition = GetStorage().TargetPartition}));", "\n}" ], "metadata": {}, diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 7fb36376..19dca75c 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -348,7 +348,6 @@ "\n ? ct.PeriodType : PeriodType.EndOfPeriod;", "\n", "\n //Variables and Cash flows", - "\n ", "\n public IEnumerable GetRawVariables(string dataNode) => RawVariablesByImportIdentity.TryGetValue(dataNode, out var variableCollection) ? variableCollection : Enumerable.Empty();", "\n public IEnumerable GetIfrsVariables(string dataNode) => IfrsVariablesByImportIdentity.TryGetValue(dataNode, out var variableCollection) ? variableCollection : Enumerable.Empty();", "\n ", @@ -366,13 +365,20 @@ "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", "\n ", "\n //Accident years", - "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet() : new int?[] { default };", + "\n public IEnumerable GetAccidentYears(string dataNode, int projectionPeriod) { ", + "\n if(!DataNodeDataBySystemName.TryGetValue(dataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, dataNode);", + "\n if (AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYears))", + "\n return dataNodeData.LiabilityType == LiabilityTypes.LIC", + "\n ? accidentYears.Where(ay => MonthInAYear * ay <= (MonthInAYear * args.Year + GetShift(projectionPeriod)) || ay == default).ToHashSet()", + "\n : accidentYears;", + "\n return new int?[] { default };", + "\n }", "\n ", "\n //Parameters", "\n public double GetNonPerformanceRiskRate (ImportIdentity identity, string cdrBasis)", "\n {", - "\n if(!DataNodeDataBySystemName.TryGetValue(identity.DataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, identity.DataNode);", - "\n if(dataNodeData.Partner == null) ApplicationMessage.Log(Error.PartnerNotFound, identity.DataNode);", + "\n if(!DataNodeDataBySystemName.TryGetValue(identity.DataNode, out var dataNodeData)) ApplicationMessage.Log(Error.DataNodeNotFound, identity.DataNode);", + "\n if(dataNodeData.Partner == null) ApplicationMessage.Log(Error.PartnerNotFound, identity.DataNode);", "\n ", "\n double rate;", "\n if(cdrBasis == EconomicBases.C)", @@ -409,7 +415,10 @@ "\n if (patternFromCoverageUnits.Any())", "\n return (AmountTypes.CU, Enumerable.Repeat(0d, patternShift).Concat(patternFromCoverageUnits).ToArray());", "\n", - "\n ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n if(DataNodeDataBySystemName[identity.DataNode].ValuationApproach == ValuationApproaches.PAA && DataNodeDataBySystemName[identity.DataNode].LiabilityType == LiabilityTypes.LRC)", + "\n ApplicationMessage.Log(Warning.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n else ApplicationMessage.Log(Error.ReleasePatternNotFound, identity.DataNode, amountType);", + "\n ", "\n return (null, Enumerable.Empty().ToArray());", "\n }", "\n ",