Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 122 additions & 37 deletions ifrs17/Import/ImportScopeCalculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@
"source": [
"## Computing All Scopes",
"\n",
"\nSince all the calculations defined in the various scopes are to be performed together, it is useful to introduce the scope <code>ComputeAllScopes</code> below, which given a certain Import Identity and Import Storage, performs all the calculations (defined above) based on the corresponding data:"
"\nSince all the calculations defined in the various scopes are to be performed together, it is useful to introduce the scopes: <code>ComputeIfrsVarsActuals</code>, <code>ComputeIfrsVarsCashflows</code> and the <code>ComputeIfrsVarsOpenings</code> below, which given a certain Import Format and Import Storage, performs all the calculations (defined above) based on the corresponding data:"
],
"metadata": {},
"execution_count": 0,
Expand All @@ -2051,9 +2051,9 @@
{
"cell_type": "code",
"source": [
"public interface ComputeAllScopes: IScope<ImportIdentity, ImportStorage> //ComputeIfrsVariable",
"public interface PvToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n IEnumerable<IfrsVariable> PvLocked => GetScope<PvLocked>(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ",
"\n IEnumerable<IfrsVariable> PvLocked => GetScope<PvLocked>(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ",
"\n EstimateType = x.Identity.EstimateType, ",
"\n DataNode = x.Identity.Id.DataNode, ",
"\n AocType = x.Identity.Id.AocType, ",
Expand All @@ -2073,6 +2073,17 @@
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface RaToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n IEnumerable<IfrsVariable> RaCurrent => GetScope<RaCurrent>(Identity).PresentValues.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EconomicBasis = x.EconomicBasis, ",
"\n EstimateType = x.Identity.EstimateType, ",
"\n DataNode = x.Identity.Id.DataNode, ",
Expand All @@ -2093,20 +2104,17 @@
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n private string EconomicBasis => Identity.ValuationApproach == ValuationApproaches.VFA ? EconomicBases.C : EconomicBases.L;",
"\n private IEnumerable<IfrsVariable> amortizationFactor => Identity.AocType == AocTypes.AM",
"\n ? GetScope<CurrentPeriodAmortizationFactor>(Identity, o => o.WithContext(EconomicBasis))",
"\n .RepeatOnce()",
"\n .Where(x => Math.Abs(x.Value) >= Precision)",
"\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 = x.EconomicBasis,",
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n })",
"\n : Enumerable.Empty<IfrsVariable>();",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface ActualToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n IEnumerable<IfrsVariable> Actual => GetScope<Actual>(Identity).Actuals.Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.Identity.EstimateType,",
"\n DataNode = x.Identity.Id.DataNode,",
"\n AocType = x.Identity.Id.AocType,",
Expand Down Expand Up @@ -2134,15 +2142,36 @@
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface DeferrableToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n IEnumerable<IfrsVariable> DeferrableActual => GetScope<DeferrableActual>(Identity).RepeatOnce().Where(x => Math.Abs(x.Value) >= Precision).Select(x => new IfrsVariable{ EstimateType = x.EstimateType,",
"\n DataNode = x.Identity.DataNode,",
"\n AocType = x.Identity.AocType,",
"\n Novelty = x.Identity.Novelty,",
"\n AccidentYear = null,",
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n ",
"\n DataNode = x.Identity.DataNode,",
"\n AocType = x.Identity.AocType,",
"\n Novelty = x.Identity.Novelty,",
"\n AccidentYear = null,",
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface EaForPremiumToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n IEnumerable<IfrsVariable> BeEAForPremium => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC",
"\n || Identity.IsReinsurance",
"\n ? Enumerable.Empty<IfrsVariable>()",
Expand Down Expand Up @@ -2174,7 +2203,31 @@
"\n AmountType = sc.Identity.AmountType,",
"\n Value = sc.Value,",
"\n Partition = GetStorage().TargetPartition });",
"\n ",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface TmToIfrsVariable: IScope<ImportIdentity, ImportStorage>",
"\n{",
"\n private string EconomicBasis => Identity.ValuationApproach == ValuationApproaches.VFA ? EconomicBases.C : EconomicBases.L;",
"\n IEnumerable<IfrsVariable> AmortizationFactor => Identity.AocType == AocTypes.AM",
"\n ? GetScope<CurrentPeriodAmortizationFactor>(Identity, o => o.WithContext(EconomicBasis))",
"\n .RepeatOnce()",
"\n .Where(x => Math.Abs(x.Value) >= Precision)",
"\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 = x.EconomicBasis,",
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n })",
"\n : Enumerable.Empty<IfrsVariable>();",
"\n IEnumerable<IfrsVariable> Csms => GetStorage().DataNodeDataBySystemName[Identity.DataNode].LiabilityType == LiabilityTypes.LIC",
"\n ? Enumerable.Empty<IfrsVariable>()",
"\n : GetScope<ContractualServiceMargin>(Identity).RepeatOnce()",
Expand Down Expand Up @@ -2208,16 +2261,6 @@
"\n Value = x.Value,",
"\n Partition = GetStorage().TargetPartition",
"\n });",
"\n ",
"\n IEnumerable<IfrsVariable> CalculatedIfrsVariables => GetStorage().ImportFormat switch {",
"\n ImportFormats.Actual => Actual.Concat(AdvanceActual).Concat(OverdueActual).Concat(ActEAForPremium)",
"\n .Concat(DeferrableActual).Concat(Csms).Concat(Loss),",
"\n ImportFormats.Cashflow => PvLocked.Concat(PvCurrent).Concat(RaCurrent).Concat(RaLocked)",
"\n .Concat(amortizationFactor).Concat(BeEAForPremium)",
"\n .Concat(DeferrableActual).Concat(Csms).Concat(Loss),",
"\n ImportFormats.Opening => AdvanceActual.Concat(OverdueActual).Concat(DeferrableActual)",
"\n .Concat(Csms).Concat(Loss),",
"\n };",
"\n}"
],
"metadata": {},
Expand All @@ -2227,7 +2270,49 @@
{
"cell_type": "code",
"source": [
""
"public interface ComputeIfrsVarsActuals : ActualToIfrsVariable, DeferrableToIfrsVariable, EaForPremiumToIfrsVariable, TmToIfrsVariable",
"\n{",
"\n IEnumerable<IfrsVariable> CalculatedIfrsVariables => Actual.Concat(AdvanceActual)",
"\n .Concat(OverdueActual)",
"\n .Concat(ActEAForPremium)",
"\n .Concat(DeferrableActual)",
"\n .Concat(Csms)",
"\n .Concat(Loss);",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface ComputeIfrsVarsCashflows : PvToIfrsVariable, RaToIfrsVariable, DeferrableToIfrsVariable, EaForPremiumToIfrsVariable, TmToIfrsVariable",
"\n{",
"\n IEnumerable<IfrsVariable> CalculatedIfrsVariables => PvLocked.Concat(PvCurrent)",
"\n .Concat(RaCurrent)",
"\n .Concat(RaLocked)",
"\n .Concat(amortizationFactor)",
"\n .Concat(BeEAForPremium)",
"\n .Concat(DeferrableActual)",
"\n .Concat(Csms)",
"\n .Concat(Loss);",
"\n}"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public interface ComputeIfrsVarsOpenings : ActualToIfrsVariable, DeferrableToIfrsVariable, TmToIfrsVariable",
"\n{",
"\n IEnumerable<IfrsVariable> CalculatedIfrsVariables => AdvanceActual.Concat(OverdueActual)",
"\n .Concat(DeferrableActual)",
"\n .Concat(Csms)",
"\n .Concat(Loss);",
"\n} "
],
"metadata": {},
"execution_count": 0,
Expand Down
6 changes: 3 additions & 3 deletions ifrs17/Import/Importers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
"\n ",
"\n var universe = Scopes.ForStorage(storage).ToScope<IModel>();",
"\n var identities = universe.GetScopes<GetIdentities>(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);",
"\n var ivs = universe.GetScopes<ComputeAllScopes>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n var ivs = universe.GetScopes<ComputeIfrsVarsCashflows>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);",
"\n ",
"\n await workspace.UpdateAsync<IfrsVariable>(ivs);",
Expand Down Expand Up @@ -1120,7 +1120,7 @@
"\n",
"\n var universe = Scopes.ForStorage(storage).ToScope<IModel>();",
"\n var identities = universe.GetScopes<GetIdentities>(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);",
"\n var ivs = universe.GetScopes<ComputeAllScopes>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n var ivs = universe.GetScopes<ComputeIfrsVarsActuals>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);",
"\n",
"\n await workspace.UpdateAsync<IfrsVariable>(ivs);",
Expand Down Expand Up @@ -1275,7 +1275,7 @@
"\n ",
"\n var universe = Scopes.ForStorage(storage).ToScope<IModel>();",
"\n var identities = universe.GetScopes<GetIdentities>(storage.DataNodesByImportScope[ImportScope.Primary]).SelectMany(s => s.Identities);",
"\n var ivs = universe.GetScopes<ComputeAllScopes>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n var ivs = universe.GetScopes<ComputeIfrsVarsOpenings>(identities).SelectMany(x => x.CalculatedIfrsVariables);",
"\n if(Activity.HasErrors()) return Activity.Finish().Merge(parsingLog);",
"\n",
"\n await workspace.UpdateAsync<IfrsVariable>(ivs);",
Expand Down