diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 58885725..c506b1a3 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -231,59 +231,58 @@ "\n var openingIfrsVariables = Enumerable.Empty();", "\n", "\n var allImportScopesAtInceptionYear = allImportScopes.Select(dn => DataNodeDataBySystemName[dn]).Where(dnd => dnd.Year == args.Year).Select(x => x.DataNode).ToHashSet();", - "\n var allImportScopesNotAtInceptionYear = allImportScopes.Except(allImportScopesAtInceptionYear);", + "\n var allImportScopesNotAtInceptionYear = allImportScopes.Except(allImportScopesAtInceptionYear).ToHashSet();", + "\n", + "\n if(allImportScopesAtInceptionYear.Any()) {", + "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScopeFromParsedVariables.Contains(dn));", + "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScopeFromLinkedReinsurance.Contains(dn) || secondaryScope.Contains(dn));", + "\n", + "\n openingIfrsVariables = await querySource.Query()", + "\n .Where(iv => iv.Partition == TargetPartition && iv.AocType == AocTypes.BOP && iv.Novelty == Novelties.I)", + "\n .Where(iv => primaryScopeAtInceptionYear.Contains(iv.DataNode) && ImportFormat != ImportFormats.Opening", + "\n && EstimateTypesByImportFormat[InputSource.Opening.ToString()].Contains(iv.EstimateType) ", + "\n || secondaryScopeAtInceptionYear.Contains(iv.DataNode)).ToArrayAsync();", + "\n }", "\n", "\n if(allImportScopesNotAtInceptionYear.Any()) {", - "\n PreviousPeriodPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", - "\n p.Year == PreviousReportingPeriod.Year &&", - "\n p.Month == PreviousReportingPeriod.Month &&", - "\n p.Scenario == null).ToArrayAsync()).Single().Id;", + "\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 ", "\n await querySource.Partition.SetAsync(PreviousPeriodPartition);", "\n ", "\n //Perform queries to previous Period", "\n openingRawVariables = (await querySource.Query()", "\n .Where(rv => rv.Partition == PreviousPeriodPartition && rv.AocType == AocTypes.CL)", - "\n .Where(v => primaryScope.Contains(v.DataNode))", - "\n .ToArrayAsync())", - "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", + "\n .Where(v => primaryScope.Contains(v.DataNode)).ToArrayAsync())", + "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, ", + "\n Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", "\n ", - "\n openingIfrsVariables = (await querySource.Query()", + "\n openingIfrsVariables = openingIfrsVariables.Union((await querySource.Query()", "\n .Where(iv => iv.Partition == PreviousPeriodPartition && iv.AocType == AocTypes.EOP)", - "\n .Where(v => allImportScopesNotAtInceptionYear.Contains(v.DataNode))", - "\n .ToArrayAsync())", - "\n .Select(iv => iv with {AocType = AocTypes.BOP, Novelty = Novelties.I, Partition = TargetPartition});", + "\n .Where(v => allImportScopesNotAtInceptionYear.Contains(v.DataNode)).ToArrayAsync())", + "\n .Select(iv => iv with {AocType = AocTypes.BOP, Novelty = Novelties.I, Partition = TargetPartition}),", + "\n EqualityComparer.Instance);", "\n ", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n", "\n // TODO: print error if ", "\n //openingRawVariables.Select(x => x.DataNode).ToHashSet() != dataNodesWithPreviousPeriod", "\n }", "\n ", - "\n //SetPartition to current Period", - "\n await querySource.Partition.SetAsync(TargetPartition);", - "\n", - "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", - "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => secondaryScope.Contains(dn)); ", - "\n if(allImportScopesAtInceptionYear.Any() && ImportFormat != ImportFormats.Opening) ", - "\n openingIfrsVariables = openingIfrsVariables.Concat(await querySource.Query()", - "\n .Where(iv => iv.Partition == TargetPartition && iv.AocType == AocTypes.BOP && iv.Novelty == Novelties.I)", - "\n .Where(iv => primaryScopeAtInceptionYear.Contains(iv.DataNode) ", - "\n && EstimateTypesByImportFormat[InputSource.Opening.ToString()].Contains(iv.EstimateType) ", - "\n || secondaryScopeAtInceptionYear.Contains(iv.DataNode))", - "\n .ToArrayAsync());", - "\n ", "\n //Variables", "\n var rawVariables = parsedRawVariables.Concat(openingRawVariables)", "\n .Concat(await querySource.Query()", "\n .Where(rv => rv.Partition == TargetPartition)", "\n .Where(rv => primaryScopeFromLinkedReinsurance.Contains(rv.DataNode)).ToArrayAsync()); ", "\n ", - "\n var ifrsVariables = parsedIfrsVariables.Concat(openingIfrsVariables)", + "\n var ifrsVariables = parsedIfrsVariables.Union(openingIfrsVariables, EqualityComparer.Instance)", "\n .Concat(await querySource.Query()", "\n .Where(iv => iv.Partition == TargetPartition && !(iv.AocType == AocTypes.BOP && iv.Novelty == Novelties.I))", "\n .Where(iv => primaryScopeFromParsedVariables.Contains(iv.DataNode) ", "\n && !EstimateTypesByImportFormat[ImportFormat].Contains(iv.EstimateType) ", "\n || primaryScopeFromLinkedReinsurance.Contains(iv.DataNode) ", - "\n || secondaryScope.Contains(iv.DataNode)).ToArrayAsync());", + "\n || secondaryScope.Contains(iv.DataNode)).ToArrayAsync()); ", "\n", "\n if(DefaultPartition != TargetPartition) {", "\n await querySource.Partition.SetAsync(DefaultPartition);", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 5633d094..ab7a2c6f 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1509,7 +1509,7 @@ { "cell_type": "code", "source": [ - "public async Task ParseSimpleValueToWorkspaceAsync(IDataSet dataSet, ImportArgs args, Guid targetPartitionByReportingNodeAndPeriodId, IWorkspace workspace, IDataSource targetDataSource)", + "public async Task ParseSimpleValueToWorkspaceAsync(IDataSet dataSet, ImportArgs args, IWorkspace workspace, IDataSource targetDataSource)", "\n{", "\n workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());", "\n workspace.Initialize(x => x.FromSource(targetDataSource)", @@ -1565,7 +1565,6 @@ "\n ApplicationMessage.Log(Error.MultipleTechnicalMarginOpening, $\"{iv.DataNode},{iv.AocType},{iv.Novelty}\");", "\n ", "\n await workspace.ValidateForDataNodeStateActiveAsync(parsingStorage.DataNodeDataBySystemName);", - "\n targetPartitionByReportingNodeAndPeriodId = parsingStorage.TargetPartitionByReportingNodeAndPeriod.Id;", "\n return Activity.Finish().Merge(importLog);", "\n}" ], @@ -1583,16 +1582,16 @@ "\n await DataNodeFactoryAsync(dataSet, ImportFormats.SimpleValue, args, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n Guid partitionId = new Guid();", "\n var workspace = Workspace.CreateNew();", - "\n var parsingLog = await ParseSimpleValueToWorkspaceAsync(dataSet, args, partitionId, workspace, options.TargetDataSource);", + "\n var parsingLog = await ParseSimpleValueToWorkspaceAsync(dataSet, args, workspace, options.TargetDataSource);", "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", "\n", "\n workspace.Query().Select(v => new {v.DataNode, v.AccidentYear}).Distinct();", "\n", "\n var targetDataNodes = workspace.Query().Select(v => v.DataNode).Distinct().ToArray();", - "\n await workspace.CommitToAsync(options.TargetDataSource, partitionId, snapshot : true,", - "\n filter : x => targetDataNodes.Contains(x.DataNode));", + "\n await workspace.CommitToAsync(", + "\n options.TargetDataSource, (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(args)),", + "\n snapshot : true, filter : x => targetDataNodes.Contains(x.DataNode));", "\n return Activity.Finish().Merge(parsingLog);", "\n});" ], @@ -1616,22 +1615,26 @@ "source": [ "Import.DefineFormat(ImportFormats.Opening, async (options, dataSet) => {", "\n Activity.Start();", - "\n var args = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Opening};", + "\n var primaryArgs = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Opening};", "\n if(Activity.HasErrors()) return Activity.Finish();", - "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, args, options.TargetDataSource);", + "\n", + "\n var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Opening);", + "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, primaryArgs, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n Guid partitionId = new Guid();", "\n var workspace = Workspace.CreateNew();", - "\n var parsingLog = await ParseSimpleValueToWorkspaceAsync(dataSet, args, partitionId, workspace, options.TargetDataSource);", - "\n if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", + "\n var log = await ParseSimpleValueToWorkspaceAsync(dataSet, primaryArgs, workspace, options.TargetDataSource);", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n", "\n var workspaceToCompute = Workspace.CreateNew();", "\n workspaceToCompute.Initialize(x => x.FromSource(options.TargetDataSource));", - "\n var calculationLog = await ComputeAsync(args, workspace, workspaceToCompute, false); ", - "\n if(calculationLog.Errors.Any()) return Activity.Finish().Merge(calculationLog);", + "\n foreach (var args in allArgs) {", + "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false)); ", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n }", "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource, x => x.SnapshotMode());", - "\n return Activity.Finish().Merge(parsingLog).Merge(calculationLog);", + "\n return Activity.Finish().Merge(log);", + "\n", "\n})" ], "metadata": {}, diff --git a/ifrs17/Test/ImportStorageTest.ipynb b/ifrs17/Test/ImportStorageTest.ipynb index b6827a63..960b5c26 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -48,7 +48,8 @@ "cell_type": "code", "source": [ "await DataSource.SetAsync();", - "\nDataSource.Reset(x => x.ResetCurrentPartitions());" + "\nDataSource.Reset(x => x.ResetCurrentPartitions());", + "\nWorkspace.Reset(x => x.ResetCurrentPartitions());" ], "metadata": {}, "execution_count": 0, @@ -136,34 +137,39 @@ { "cell_type": "code", "source": [ - "public async Task CheckIfrsVariablesFromImportStorageAsync(string importFormat, IEnumerable inputDataSetForWorkspace, IEnumerable inputDataSetForDataSource, IEnumerable ivsBenchmark, ImportArgs args)", - "\n{", - "\n Activity.Start();", + "public async Task StorageInitializeAsync(ImportStorage storage, IEnumerable inputForWorkspace, IEnumerable inputForDataSource, ImportArgs args) {", "\n //Prepare Workspace and DataSource", - "\n await Workspace.UpdateAsync(inputDataSetForWorkspace);", - "\n await DataSource.UpdateAsync(inputDataSetForDataSource);", - "\n ", + "\n await Workspace.UpdateAsync(inputForWorkspace);", + "\n await DataSource.UpdateAsync(inputForDataSource);", "\n //Set up import storage and test universe", - "\n var testStorage = new ImportStorage(args with {ImportFormat = importFormat}, DataSource, Workspace);", - "\n await testStorage.InitializeAsync();", - "\n ", - "\n var ivs = testStorage.IfrsVariablesByImportIdentity.SelectMany(x => x.Value);", - "\n ", - "\n //Clean up Workspace", - "\n //Workspace.Reset(); ", - "\n await Workspace.DeleteAsync(inputDataSetForWorkspace); ", - "\n await DataSource.DeleteAsync(inputDataSetForDataSource); ", - "\n ", + "\n await storage.InitializeAsync();", + "\n //Clean up ", + "\n await Workspace.DeleteAsync(inputForWorkspace); ", + "\n await DataSource.DeleteAsync(inputForDataSource); ", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CheckIfrsVariableImportStorageAsync(IfrsVariable[] inputForWorkspace, IfrsVariable[] inputForDataSource, IfrsVariable[] benchmark, ImportArgs args)", + "\n{", + "\n Activity.Start();", + "\n var storage = new ImportStorage(args, DataSource, Workspace);", + "\n await StorageInitializeAsync(storage, inputForWorkspace, inputForDataSource, args);", + "\n var variables = storage.IfrsVariablesByImportIdentity.SelectMany(x => x.Value);", "\n var errors = new List();", "\n ", - "\n var extraVariablesInStorage = ivs.Except(ivsBenchmark).Select(x => x.ToIdentityString()).ToArray();", + "\n var extraVariablesInStorage = variables.Except(benchmark).Select(x => x.ToIdentityString()+\" Value: \"+x.Value.ToString()).ToArray();", "\n if(extraVariablesInStorage.Any()) errors.Add( $\"IfrsVariables in the storage contain the following items that are not present in the benchmark:\\n{string.Join(\"\\n\",extraVariablesInStorage)}.\" );", "\n ", - "\n var extraVariablesInBenchmark = ivsBenchmark.Except(ivs).Select(x => x.ToIdentityString()).ToArray();", - "\n if(extraVariablesInBenchmark.Count() > 0) errors.Add( $\"IfrsVariables in the benchmark contain the following items that are not present in the storage:\\n{string.Join(\"\\n\",extraVariablesInBenchmark)}.\" );", - "\n ", - "\n //find duplicates in storage", - "\n var ivsByIdentityString = ivs.GroupBy(x => x.ToIdentityString()).Where(x => x.Count() > 1).Select(x => x.Key);", + "\n var extraVariablesInBenchmark = benchmark.Except(variables).Select(x => x.ToIdentityString()+\" Value: \"+x.Value.ToString()).ToArray();", + "\n if(extraVariablesInBenchmark.Any()) errors.Add( $\"IfrsVariables in the benchmark contain the following items that are not present in the storage:\\n{string.Join(\"\\n\",extraVariablesInBenchmark)}.\" );", + "\n", + "\n var ivsByIdentityString = variables.GroupBy(x => x.ToIdentityString()).Where(x => x.Count() > 1).Select(x => x.Key);", "\n if(ivsByIdentityString.Any()) errors.Add($\"IfrsVariables in the storage have duplicated items for:\\n{string.Join(\"\\n\",ivsByIdentityString)}.\");", "\n ", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors));", @@ -174,6 +180,34 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "public async Task CheckRawVariableImportStorageAsync(RawVariable[] inputForWorkspace, RawVariable[] inputForDataSource, RawVariable[] benchmark, ImportArgs args)", + "\n{", + "\n Activity.Start();", + "\n var storage = new ImportStorage(args, DataSource, Workspace);", + "\n await StorageInitializeAsync(storage, inputForWorkspace, inputForDataSource, args);", + "\n var variables = storage.RawVariablesByImportIdentity.SelectMany(x => x.Value);", + "\n var errors = new List();", + "\n ", + "\n var extraVariablesInStorage = variables.Except(benchmark, RawVariableComparer.Instance()).Select(x => x.ToIdentityString()+\" Values: \"+String.Join(\",\", x.Values)).ToArray();", + "\n if(extraVariablesInStorage.Any()) errors.Add( $\"RawVariables in the storage contain the following items that are not present in the benchmark:\\n{string.Join(\"\\n\",extraVariablesInStorage)}.\" );", + "\n ", + "\n var extraVariablesInBenchmark = benchmark.Except(variables, RawVariableComparer.Instance()).Select(x => x.ToIdentityString()+\" Values: \"+String.Join(\",\", x.Values)).ToArray();", + "\n if(extraVariablesInBenchmark.Any()) errors.Add( $\"RawVariables in the benchmark contain the following items that are not present in the storage:\\n{string.Join(\"\\n\",extraVariablesInBenchmark)}.\" );", + "\n", + "\n var ivsByIdentityString = variables.GroupBy(x => x.ToIdentityString()).Where(x => x.Count() > 1).Select(x => x.Key);", + "\n if(ivsByIdentityString.Any()) errors.Add($\"RawVariables in the storage have duplicated items for:\\n{string.Join(\"\\n\",ivsByIdentityString)}.\");", + "\n ", + "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors));", + "\n return Activity.Finish();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -186,7 +220,7 @@ { "cell_type": "markdown", "source": [ - "## A", + "## Actuals Import 1", "\n", "\nThere is a previous year, and it's the first time Actuals are imported for the current year." ], @@ -199,12 +233,12 @@ "source": [ "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\nvar inputForDataSource = new IfrsVariable[]{", "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 100.0},", "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\nvar inputForWorkspace = new IfrsVariable[]{", "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -10.0},", "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 15.0},", "\n };", @@ -215,7 +249,7 @@ "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -10.0},", "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 15.0},", "\n };", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -234,9 +268,9 @@ { "cell_type": "markdown", "source": [ - "## B", + "## Actuals Import 2", "\n", - "\nThere is a previous year, and it's the second time Actuals are imported for the current year (reimport)." + "\nThere is a previous year, cash flow were already imported and actuals are imported for the first time." ], "metadata": {}, "execution_count": 0, @@ -245,31 +279,33 @@ { "cell_type": "code", "source": [ - "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.I, EstimateType = EstimateTypes.BE};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 100.0},", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.DA, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 100.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", - "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 200.0},", - "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 450.0},", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = 100.0},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.IA, Value = 1500.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 2500.0},", + "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 5000.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", - "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CF, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -15.0},", + "\n basicIfrsVariable with {AocType = AocTypes.WO, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -20.0},", "\n };", "\n", "\nvar ivsBenchmark = new IfrsVariable[]{", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.DA, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 100.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", - "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.IA, Value = 1500.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 2500.0},", + "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 5000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.AA, Value = 100.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -15.0},", + "\n basicIfrsVariable with {AocType = AocTypes.WO, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -20.0},", "\n };", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -288,9 +324,9 @@ { "cell_type": "markdown", "source": [ - "## C", + "## Actuals Reimport", "\n", - "\nThere is a previous year, cash flow were already imported and actuals are imported for the first time." + "\nThere is a previous year, and it's the second time Actuals are imported for the current year (reimport)." ], "metadata": {}, "execution_count": 0, @@ -299,33 +335,31 @@ { "cell_type": "code", "source": [ - "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.I, EstimateType = EstimateTypes.BE};", + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = 100.0},", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.IA, Value = 1500.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 2500.0},", - "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 5000.0},", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 100.0},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.DA, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 100.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", + "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 200.0},", + "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 450.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {AocType = AocTypes.CF, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -15.0},", - "\n basicIfrsVariable with {AocType = AocTypes.WO, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -20.0},", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", "\n };", "\n", "\nvar ivsBenchmark = new IfrsVariable[]{", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 1000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.IA, Value = 1500.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 2500.0},", - "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 5000.0},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.AA, Value = 100.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CF, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -15.0},", - "\n basicIfrsVariable with {AocType = AocTypes.WO, EstimateType = EstimateTypes.AA, Novelty = Novelties.C, Value = -20.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.DA, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 100.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", "\n };", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -344,7 +378,7 @@ { "cell_type": "markdown", "source": [ - "## D", + "## Actuals Reimport with CF", "\n", "\nThere is a previous year, Cash flows and Actuals were already imported and Actuals are imported again." ], @@ -358,7 +392,7 @@ "var basicAdvanceActualIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", "\nvar basicBeIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.I, EstimateType = EstimateTypes.BE};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\nvar inputForDataSource = new IfrsVariable[]{", "\n basicBeIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 1000.0},", "\n basicBeIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 1000.0},", "\n basicBeIfrsVariable with {AocType = AocTypes.IA, Value = 1500.0},", @@ -373,7 +407,7 @@ "\n basicAdvanceActualIfrsVariable with {AocType = AocTypes.EOP, Value = 450.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\nvar inputForWorkspace = new IfrsVariable[]{", "\n basicAdvanceActualIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", "\n basicAdvanceActualIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", "\n };", @@ -389,7 +423,7 @@ "\n basicAdvanceActualIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", "\n };", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -408,7 +442,7 @@ { "cell_type": "markdown", "source": [ - "## E", + "## Actuals Reimport with Primary Secondary Scope", "\n", "\nThere is a previous year for Primary Scope (GRIC10) ", "\n", @@ -425,7 +459,7 @@ "source": [ "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfReinsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\nvar inputForDataSource = new IfrsVariable[]{", "\n //Year", "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Value = 100.0},", "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", @@ -439,7 +473,7 @@ "\n basicIfrsVariable with {AocType = AocTypes.CF, Novelty = Novelties.I, DataNode = groupOfInsuranceContracts, EstimateType = EstimateTypes.BE, EconomicBasis = EconomicBases.L, Value = 10.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\nvar inputForWorkspace = new IfrsVariable[]{", "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -10.0},", "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 15.0},", "\n };", @@ -464,7 +498,7 @@ "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = 15.0},", "\n };", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -480,6 +514,150 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Openings Reimport for Gross", + "\n", + "\nThere are openings for GIC and for the correlated GRIC. ", + "\n", + "\nThe Openings for the GIC are re-imported and the GRIC must be loaded in the storage. Both are at inception year." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait Workspace.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});", + "\nawait DataSource.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", + "\n", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.0},", + "\n };", + "\n", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 91.0},", + "\n };", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 91.0},", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.0},", + "\n };", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Opening});", + "\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": [ + "// Restore workspace", + "\nawait Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait DataSource.UpdateAsync(new[]{ dt11State, dtr11State });", + "\nawait Workspace.UpdateAsync(new[]{ dt11State, dtr11State });" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Openings Reimport for Reinsurance", + "\n", + "\nThere are openings for GIC and for the correlated GRIC. ", + "\n", + "\nThe Openings for the GRIC are re-imported and the GIC must be loaded in the storage. Both are at inception year." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait Workspace.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});", + "\nawait DataSource.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", + "\n", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.0},", + "\n };", + "\n", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 91.0},", + "\n };", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 91.0},", + "\n };", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Opening});", + "\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": [ + "// Restore workspace", + "\nawait Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait DataSource.UpdateAsync(new[]{ dt11State, dtr11State });", + "\nawait Workspace.UpdateAsync(new[]{ dt11State, dtr11State });" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -492,7 +670,7 @@ { "cell_type": "markdown", "source": [ - "## A", + "## Relaxed query", "\n", "\nFor the current year Actuals are imported for Best Estimate and a given Scenario. The Relaxed query should return the union of the 2 giving priority to scenario data. " ], @@ -503,27 +681,27 @@ { "cell_type": "code", "source": [ - "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\nvar inputForDataSource = new IfrsVariable[]{", "\n basicIfrsVariable with {AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", "\n basicIfrsVariable with {AocType = AocTypes.BOP, Value = 100.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CL, Value = 150.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AmountType = AmountTypes.CL, AocType = AocTypes.CL, Value = -99.0},", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AmountType = AmountTypes.CL, AocType = AocTypes.CF, Value = -99.0},", "\n };", "\n", "\nvar ivsBenchmark = new IfrsVariable[]{", "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.BOP, Value = 100.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AmountType = AmountTypes.CL, AocType = AocTypes.CL, Value = -99.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AmountType = AmountTypes.CL, AocType = AocTypes.CF, Value = -99.0},", "\n };", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -542,7 +720,7 @@ { "cell_type": "markdown", "source": [ - "## B", + "## Secondary scope", "\n", "\nThe primary scope is a GRIC scenario while the underlying GIC is Best Estimate." ], @@ -553,28 +731,311 @@ { "cell_type": "code", "source": [ - "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.AA};", + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", "\n", - "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\nvar inputForDataSource = new IfrsVariable[]{", "\n basicIfrsVariable with {AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", "\n basicIfrsVariable with {AocType = AocTypes.BOP, Value = 100.0},", - "\n basicIfrsVariable with {AocType = AocTypes.CL, Value = 150.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", "\n};", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.CL, Value = -15.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, AocType = AocTypes.CL, Value = -99.0},", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, AocType = AocTypes.CF, Value = -99.0},", "\n};", "\n", "\nvar ivsBenchmark = new IfrsVariable[]{", "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.BOP, Value = 100.0},", - "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.CL, Value = 150.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.CL, Value = -15.0},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, AocType = AocTypes.CL, Value = -99.0},", + "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.CF, Value = 150.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.CF, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, AocType = AocTypes.CF, Value = -99.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario Actuals Import 1", + "\n", + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Data Node is not at inception year." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", + "\n", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.7},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", + "\n basicIfrsVariable with {Partition = previousPeriodPartitionScenarioMTUP.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partition.Id, AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0}, ", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5}, ", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario Actuals Import 2", + "\n", + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Data Node is at inception year." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait Workspace.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});", + "\nawait DataSource.UpdateAsync(new[]{dt11State with {Year = args.Year, Month = args.Month}, dtr11State with {Year = args.Year, Month = args.Month}});" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", + "\n", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.7},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", + "\n basicIfrsVariable with {Partition = previousPeriodPartitionScenarioMTUP.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0}, ", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario Actuals Import 3", + "\n", + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Only the GRIC is at inception year." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait Workspace.UpdateAsync(new[]{dt11State, dtr11State with {Year = args.Year, Month = args.Month}});", + "\nawait DataSource.UpdateAsync(new[]{dt11State, dtr11State with {Year = args.Year, Month = args.Month}});" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicIfrsVariable = new IfrsVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, EstimateType = EstimateTypes.A};", + "\n", + "\nvar inputForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = 150.0},", + "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.7},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, DataNode = groupOfInsuranceContracts, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", + "\n basicIfrsVariable with {Partition = previousPeriodPartitionScenarioMTUP.Id, DataNode = groupOfInsuranceContracts, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\nvar inputForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.7},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", + "\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": [ + "// Restore workspace", + "\nawait Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "\nawait DataSource.DeleteAsync(await DataSource.Query().ToArrayAsync());", + "\nawait DataSource.UpdateAsync(new[]{ dt11State, dtr11State });", + "\nawait Workspace.UpdateAsync(new[]{ dt11State, dtr11State });" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario CF Import 1", + "\n", + "\nImport of a CF Scenario1 having BE and Scenario2 in the DataSource." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicRawVariable = new RawVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, AocType = AocTypes.CL, EstimateType = EstimateTypes.BE};", + "\n", + "\nvar inputForDataSource = new RawVariable[]{", + "\n basicRawVariable with {Values = new[]{150.0}},", + "\n basicRawVariable with {AmountType = AmountTypes.CL, Values = new[]{99.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTDOWN.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Values = new[]{130.0}}", + "\n};", + "\n", + "\nvar inputForWorkspace = new RawVariable[]{", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", + "\n};", + "\n", + "\nvar ivsBenchmark = new RawVariable[]{", + "\n basicRawVariable with {AmountType = AmountTypes.CL, Values = new[]{99.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", + "\n};", + "\n", + "\nvar activity = await CheckRawVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Cashflow});", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Scenario CF Import 2", + "\n", + "\nImport of a CF Scenario1 having (ifrsVar incl Opening) BE and Scenario1 in the DataSource." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var basicRawVariable = new RawVariable{Partition = partition.Id, DataNode = groupOfInsuranceContracts, AccidentYear = null, AmountType = AmountTypes.PR, Novelty = Novelties.C, AocType = AocTypes.CL, EstimateType = EstimateTypes.BE};", + "\n", + "\nvar inputForDataSource = new RawVariable[]{", + "\n basicRawVariable with {Values = new[]{150.0}},", + "\n basicRawVariable with {AmountType = AmountTypes.CL, Values = new[]{99.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, AmountType = AmountTypes.CL, Values = new[]{130.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, Values = new[]{125.0}}", + "\n};", + "\n", + "\nvar inputForWorkspace = new RawVariable[]{", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", + "\n};", + "\n", + "\nvar ivsBenchmark = new RawVariable[]{", + "\n basicRawVariable with {AmountType = AmountTypes.CL, Values = new[]{99.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, DataNode = groupOfReinsuranceContracts, AmountType = AmountTypes.CL, Values = new[]{125.0}},", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", "\n};", "\n", - "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\nvar activity = await CheckRawVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Cashflow});", "\nactivity" ], "metadata": {}, @@ -734,7 +1195,7 @@ "\n errors.Add( $\"Underlying Gics for DataNode {dn} not matching with BM. Computed: \\n{string.Join(\"\\n\",testStorage.GetUnderlyingGic(id))} \\n Expected : \\n{string.Join(\"\\n\",underlyingGicBm[dn])}\" );", "\n }", "\n ", - "\n await Workspace.DeleteAsync(Workspace.Query());", + "\n await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", "\n await CleanWorkspaceDataNodes();", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors));", "\n return Activity.Finish();", @@ -846,7 +1307,7 @@ "\n }", "\n }", "\n ", - "\n await Workspace.DeleteAsync(Workspace.Query());", + "\n await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", "\n await CleanWorkspaceDataNodes();", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors));", "\n return Activity.Finish();", @@ -931,7 +1392,7 @@ "\n errors.Add( $\"DataNode {dn} is added to the secondary scope but should have not.\" );", "\n }", "\n ", - "\n await Workspace.DeleteAsync(Workspace.Query());", + "\n await Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", "\n await CleanWorkspaceDataNodes();", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors));", "\n return Activity.Finish();", diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index e660e2a6..10f8a38c 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -223,7 +223,8 @@ "\nvar groupOfReinsuranceContracts = \"DTR1.1\";", "\nvar reportingNode = \"CH\";", "\nvar scenarioBestEstimate = (string)null;", - "\nvar scenarioMortalityUp = \"MTUP\";" + "\nvar scenarioMortalityUp = \"MTUP\";", + "\nvar scenarioMortalityDown = \"MTDOWN\";" ], "metadata": {}, "execution_count": 0, @@ -235,7 +236,9 @@ "var args = new ImportArgs(reportingNode, 2021, 3, Periodicity.Quarterly, scenarioBestEstimate, ImportFormats.Actual);", "\nvar previousArgs = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioBestEstimate, ImportFormats.Actual);", "\nvar argsScenarioMTUP = new ImportArgs(reportingNode, 2021, 3, Periodicity.Quarterly, scenarioMortalityUp, ImportFormats.Actual);", - "\nvar previousScenarioArgsMTUP = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioMortalityUp, ImportFormats.Actual);" + "\nvar previousScenarioArgsMTUP = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioMortalityUp, ImportFormats.Actual);", + "\nvar argsScenarioMTDOWN = new ImportArgs(reportingNode, 2021, 3, Periodicity.Quarterly, scenarioMortalityDown, ImportFormats.Actual);", + "\nvar previousScenarioArgsMTDOWN = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioMortalityDown, ImportFormats.Actual);" ], "metadata": {}, "execution_count": 0, @@ -282,7 +285,17 @@ "\n ReportingNode = reportingNode, ", "\n Scenario = scenarioMortalityUp, ", "\n Year = previousScenarioArgsMTUP.Year,", - "\n Month = previousScenarioArgsMTUP.Month };" + "\n Month = previousScenarioArgsMTUP.Month };", + "\nvar partitionScenarioMTDOWN = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsScenarioMTUP)),", + "\n ReportingNode = reportingNode, ", + "\n Scenario = scenarioMortalityDown, ", + "\n Year = args.Year,", + "\n Month = args.Month };", + "\nvar previousPeriodPartitionScenarioMTDOWN = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(previousScenarioArgsMTUP)),", + "\n ReportingNode = reportingNode, ", + "\n Scenario = scenarioMortalityDown, ", + "\n Year = previousScenarioArgsMTDOWN.Year,", + "\n Month = previousScenarioArgsMTDOWN.Month };" ], "metadata": {}, "execution_count": 0, @@ -347,6 +360,7 @@ "\n SystemName = \"DTR1.1\",", "\n DisplayName = \"DTR1.1 OCI LRC PA 0.8\"", "\n};", + "\n", "\nvar dt11State = new DataNodeState {", "\n DataNode = \"DT1.1\",", "\n State = State.Active,",