diff --git a/ifrs17-template/Test/Data/NominalCashflows_CH_2020_12_DT1.1NoPrem.csv b/ifrs17-template/Test/Data/NominalCashflows_CH_2020_12_DT1.1NoPrem.csv new file mode 100644 index 00000000..885890c3 --- /dev/null +++ b/ifrs17-template/Test/Data/NominalCashflows_CH_2020_12_DT1.1NoPrem.csv @@ -0,0 +1,11 @@ +@@Main,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +ReportingNode,Year,Month,Scenario,,,,,,,,,,,,,,,,,,,,,,,,,, +CH,2020,12,,,,,,,,,,,,,,,,,,,,,,,,,,, +@@Cashflow,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +DataNode,AmountType,EstimateType,AocType,Novelty,AccidentYear,Values0,Values1,Values2,Values3,Values4,Values5,Values6,Values7,Values8,Values9,Values10,Values11,Values12,Values13,Values14,Values15,Values16,Values17,Values18,Values19,Values20,Values21,Values22,Values23 +DT1.1,NIC,BE,BOP,N,,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25 +DT1.1,,CU,BOP,N,,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3 +DT1.1,,RA,BOP,N,,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5 +DT1.1,NIC,BE,CL,C,,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25 +DT1.1,,CU,CL,C,,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3 +DT1.1,,RA,CL,C,,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5,-2.5 diff --git a/ifrs17-template/Test/ReimportWithDifferentScopeTest.ipynb b/ifrs17-template/Test/ReimportWithDifferentScopeTest.ipynb new file mode 100644 index 00000000..7e911369 --- /dev/null +++ b/ifrs17-template/Test/ReimportWithDifferentScopeTest.ipynb @@ -0,0 +1,198 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "

Reimport With Different Scope Test

" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Cash flow Import", + "\n", + "\nImporting a file with N GICs and GRICs." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"../Files/TransactionalData/NominalCashflows_CH_2020_12.csv\")", + "\n .WithFormat(ImportFormats.Cashflow)", + "\n .WithTarget(DataSource)", + "\n .WithActivityLog(Session, DataSource, DataSetReader)", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var ifrsVars1 = await DataSource.Query().ToArrayAsync();", + "\nvar dn1 = ifrsVars1.Select(x => x.DataNode).ToHashSet();", + "\nvar dt11Prem1 = ifrsVars1.Where(x => x.DataNode == \"DT1.1\" && x.AmountType == \"PR\");", + "\n(ifrsVars1.Count(), dn1.Count(), dt11Prem1.Count())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Cash flow Import - restatement", + "\nImporting a file for the same period as previous import but it only contains 1 GIC: DT1.1 where one amount type (Premium) has been removed" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Import.FromFile(\"Data/NominalCashflows_CH_2020_12_DT1.1NoPrem.csv\")", + "\n .WithFormat(ImportFormats.Cashflow)", + "\n .WithTarget(DataSource)", + "\n .WithActivityLog(Session, DataSource, DataSetReader)", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var ifrsVars2 = await DataSource.Query().ToArrayAsync();", + "\nvar dn2 = ifrsVars2.Select(x => x.DataNode).ToHashSet();", + "\nvar dt11Prem2 = ifrsVars2.Where(x => x.DataNode == \"DT1.1\" && x.AmountType == \"PR\");", + "\n(ifrsVars2.Count(), dn2.Count(), dt11Prem2.Count())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Test" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Import generate variables" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "ifrsVars1.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "ifrsVars2.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Count of data nodes does not change" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "dn2.Count().Should().Be(dn1.Count());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Premiums are present with the first import and then deleted" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "dt11Prem1.Count().Should().NotBe(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "dt11Prem2.Count().Should().Be(0);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17-template/Test/Tests.ipynb b/ifrs17-template/Test/Tests.ipynb index 2a3d2bed..cf5f7611 100644 --- a/ifrs17-template/Test/Tests.ipynb +++ b/ifrs17-template/Test/Tests.ipynb @@ -30,7 +30,7 @@ "cell_type": "markdown", "source": [ "Comprehensive collection of tests executed on top of the Systemorph use cases (initialization).", - "\n
Execute this Notebook using at least 12Gb RAM." + "\n
Execute this Notebook using at least 14Gb RAM." ], "metadata": {}, "execution_count": 0, @@ -54,6 +54,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"ReimportWithDifferentScopeTest\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 93b6296e..fe8f34ec 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -254,9 +254,11 @@ { "cell_type": "code", "source": [ - "public static async Task CleanAsync (this IDataSource dataSource, Expression> filter = null) where T : class", + "public static async Task CleanAsync (this IDataSource dataSource, Guid partitionId = default, Expression> filter = null) where T : class, IPartitioned", "\n{", - "\n var loadData = await dataSource.Query().Where(filter?? (Expression>)(x => true)).ToListAsync();", + "\n var loadData = partitionId != (Guid)default", + "\n ? await dataSource.Query().Where(x => x.Partition == partitionId ).Where(filter?? (Expression>)(x => true)).ToListAsync()", + "\n : await dataSource.Query().Where(filter ?? (Expression>)(x => true)).ToListAsync();", "\n await dataSource.DeleteAsync(loadData);", "\n}" ], @@ -282,11 +284,11 @@ "\nwhere TData : class, IPartitioned", "\nwhere TPartition : IfrsPartition", "\n{", - "\n if(partitionId != new Guid()) {", + "\n if(partitionId != (Guid)default) {", "\n await target.Partition.SetAsync(partitionId);", "\n await source.Partition.SetAsync(partitionId);", "\n }", - "\n if(snapshot) await CleanAsync(target, filter);", + "\n if(snapshot) await CleanAsync(target, partitionId, filter);", "\n await target.UpdateAsync( await source.Query().ToArrayAsync() );", "\n await target.CommitAsync();", "\n}" @@ -847,8 +849,10 @@ "\n }", "\n", "\n // Remove data nodes which are unaffected by the updated yield curves", - "\n await workspaceToCompute.DeleteAsync( await workspaceToCompute.Query()", - "\n .Where(x => !(dataNodesToUpdate.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition))).ToArrayAsync() );", + "\n // TODO : Reintroduce this functionality. Note all UpdateAsync/DeleteAsync performed to the workspaceToCompute are then trasferred to the DataSource.", + "\n // This is way this functionality should be written in a different way. ", + "\n // await workspaceToCompute.DeleteAsync( await workspaceToCompute.Query()", + "\n // .Where(x => !(dataNodesToUpdate.Contains(x.DataNode) && (x.Partition == targetPartition || x.Partition == defaultPartition))).ToArrayAsync() );", "\n", "\n importLog = importLog.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false));", "\n if(importLog.Errors.Any()) return Activity.Finish().Merge(importLog);", @@ -1400,7 +1404,7 @@ "\n log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false)); ", "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n }", - "\n if (!log.Errors.Any()) await workspaceToCompute.CommitToTargetAsync(DataSource);", + "\n await workspaceToCompute.CommitToTargetAsync(DataSource);", "\n return Activity.Finish().Merge(log);", "\n});" ], @@ -1507,7 +1511,6 @@ "\n var targetDataNodes = workspace.Query().Select(v => v.DataNode).Distinct().ToArray();", "\n await workspace.CommitToAsync(DataSource, partitionId, snapshot : true,", "\n filter : x => targetDataNodes.Contains(x.DataNode));", - "\n ", "\n return Activity.Finish().Merge(parsingLog);", "\n});" ], @@ -1545,9 +1548,9 @@ "\n workspaceToCompute.Initialize(x => x.FromSource(DataSource));", "\n var calculationLog = await ComputeAsync(args, workspace, workspaceToCompute, false); ", "\n if(calculationLog.Errors.Any()) return Activity.Finish().Merge(calculationLog);", - "\n await workspaceToCompute.CommitToAsync(DataSource, partitionId);", + "\n await workspaceToCompute.CommitToTargetAsync(DataSource, x => x.SnapshotMode());", "\n return Activity.Finish().Merge(parsingLog).Merge(calculationLog);", - "\n});" + "\n})" ], "metadata": {}, "execution_count": 0,