From 835a48bb4426d588a482aa1c2201d7c4e457ccb9 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Sat, 25 Mar 2023 18:03:24 +0100 Subject: [PATCH 1/5] fix openings scenario --- ifrs17/Import/ImportStorage.ipynb | 49 ++++++++++---------- ifrs17/Import/Importers.ipynb | 22 ++++++--- ifrs17/Test/ImportStorageTest.ipynb | 71 +++++++++++++++++++++++++---- 3 files changed, 103 insertions(+), 39 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index febe6674..7d13fd33 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -14,7 +14,7 @@ } }, "nbformat": 4, - "nbformat_minor": 8, + "nbformat_minor": 5, "cells": [ { "cell_type": "markdown", @@ -226,44 +226,43 @@ "\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", + "\n if(allImportScopesAtInceptionYear.Any() && ImportFormat != ImportFormats.Opening) {", + "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", + "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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) ", + "\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()", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index eaf7f45f..bfa2dd69 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -14,7 +14,7 @@ } }, "nbformat": 4, - "nbformat_minor": 8, + "nbformat_minor": 5, "cells": [ { "cell_type": "markdown", @@ -1569,20 +1569,30 @@ "\n Activity.Start();", "\n var args = await GetArgsAndCommitPartitionAsync(dataSet, options.TargetDataSource) with {ImportFormat = ImportFormats.Opening};", "\n if(Activity.HasErrors()) return Activity.Finish();", + "\n", + "\n //var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Opening);", "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, 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 if(parsingLog.Errors.Any()) return Activity.Finish().Merge(parsingLog);", + "\n var log = await ParseSimpleValueToWorkspaceAsync(dataSet, args, partitionId, 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 log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false)); ", + "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", + "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource, x => x.SnapshotMode());", + "\n return Activity.Finish().Merge(log);", + "\n/*", + "\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 90dfa772..d0db1584 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -14,7 +14,7 @@ } }, "nbformat": 4, - "nbformat_minor": 8, + "nbformat_minor": 5, "cells": [ { "cell_type": "markdown", @@ -136,7 +136,10 @@ { "cell_type": "code", "source": [ - "public async Task CheckIfrsVariablesFromImportStorageAsync(string importFormat, IEnumerable inputDataSetForWorkspace, IEnumerable inputDataSetForDataSource, IEnumerable ivsBenchmark, ImportArgs args)", + "static IfrsVariable[] mya;", + "\nstatic IfrsVariable[] myb;", + "\n", + "\npublic async Task CheckIfrsVariablesFromImportStorageAsync(string importFormat, IEnumerable inputDataSetForWorkspace, IEnumerable inputDataSetForDataSource, IEnumerable ivsBenchmark, ImportArgs args)", "\n{", "\n Activity.Start();", "\n //Prepare Workspace and DataSource", @@ -156,12 +159,13 @@ "\n ", "\n var errors = new List();", "\n ", - "\n var extraVariablesInStorage = ivs.Except(ivsBenchmark).Select(x => x.ToIdentityString()).ToArray();", + "\n var extraVariablesInStorage = ivs.Except(ivsBenchmark).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 var extraVariablesInBenchmark = ivsBenchmark.Except(ivs).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 mya = ivs.Except(ivsBenchmark).ToArray();", + "\n myb = ivsBenchmark.Except(ivs).ToArray();", "\n //find duplicates in storage", "\n var ivsByIdentityString = ivs.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)}.\");", @@ -492,7 +496,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. " ], @@ -542,7 +546,7 @@ { "cell_type": "markdown", "source": [ - "## B", + "## Secondary scope", "\n", "\nThe primary scope is a GRIC scenario while the underlying GIC is Best Estimate." ], @@ -590,6 +594,57 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Openings", + "\n", + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate." + ], + "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.AA};", + "\n", + "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, EstimateType = EstimateTypes.DA, Value = 1000.0},", + "\n basicIfrsVariable with {AocType = AocTypes.CL, 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 inputDataSetForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, 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.CL, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\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": [ From 9e534438dda34c59c1ccd8d7490f3fc6d55cd567 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Sat, 25 Mar 2023 20:07:21 +0100 Subject: [PATCH 2/5] better handling of all cases through tests --- ifrs17/Import/ImportStorage.ipynb | 4 +- ifrs17/Import/Importers.ipynb | 14 +- ifrs17/Test/ImportStorageTest.ipynb | 478 +++++++++++++++++++++++++++- ifrs17/Test/TestData.ipynb | 3 +- 4 files changed, 487 insertions(+), 12 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 7d13fd33..3086aa32 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -224,7 +224,7 @@ "\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() && ImportFormat != ImportFormats.Opening) {", "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", @@ -269,7 +269,7 @@ "\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.Concat(openingIfrsVariables) // TODO: ask Davide, why not union?", "\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) ", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index bfa2dd69..13539c37 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1460,7 +1460,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)", @@ -1516,7 +1516,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}" ], @@ -1534,16 +1533,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});" ], @@ -1574,9 +1573,8 @@ "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, args, options.TargetDataSource);", "\n if(Activity.HasErrors()) return Activity.Finish();", "\n", - "\n Guid partitionId = new Guid();", "\n var workspace = Workspace.CreateNew();", - "\n var log = await ParseSimpleValueToWorkspaceAsync(dataSet, args, partitionId, workspace, options.TargetDataSource);", + "\n var log = await ParseSimpleValueToWorkspaceAsync(dataSet, args, workspace, options.TargetDataSource);", "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", "\n", "\n var workspaceToCompute = Workspace.CreateNew();", diff --git a/ifrs17/Test/ImportStorageTest.ipynb b/ifrs17/Test/ImportStorageTest.ipynb index d0db1584..c5bb269a 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -124,6 +124,342 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "/*", + "\nstatic HashSet myDNatInception;", + "\nstatic HashSet myDNnotatInception;", + "\n", + "\npublic class ImportStorage", + "\n{ ", + "\n private readonly IDataSource querySource; ", + "\n private readonly IWorkspace workspace;", + "\n private readonly Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache;", + "\n private readonly ImportArgs args;", + "\n ", + "\n // Constants", + "\n private static int periodicityInMonths => 3; // Revisit", + "\n ", + "\n //Format", + "\n public string ImportFormat => args.ImportFormat; ", + "\n ", + "\n //Time Periods ", + "\n public (int Year, int Month) CurrentReportingPeriod => (args.Year, args.Month);", + "\n public (int Year, int Month) PreviousReportingPeriod => (args.Year - 1, MonthInAYear); // YTD Logic", + "\n", + "\n //Partitions", + "\n public Guid PartitionByRn;", + "\n public Guid TargetPartition;", + "\n public Guid DefaultPartition;", + "\n public Guid PreviousPeriodPartition; ", + "\n", + "\n //Projections", + "\n private ProjectionConfiguration[] ProjectionConfiguration;", + "\n ", + "\n //DataNodes", + "\n public IDictionary DataNodeDataBySystemName { get; private set; }", + "\n public IDictionary> DataNodesByImportScope { get; private set; }", + "\n public IDictionary> AccidentYearsByDataNode { get; private set; }", + "\n //Variables", + "\n public IDictionary> RawVariablesByImportIdentity { get; private set; }", + "\n public IDictionary> IfrsVariablesByImportIdentity { get; private set; }", + "\n ", + "\n //Parameters", + "\n public Dictionary LockedInYieldCurve { get; private set; }", + "\n public Dictionary> CurrentYieldCurve { get; private set; }", + "\n public Dictionary> PartnerRating { get; private set; }", + "\n public Dictionary> CreditDefaultRates { get; private set; }", + "\n public Dictionary> SingleDataNodeParametersByGoc { get; private set; }", + "\n public Dictionary>> InterDataNodeParametersByGoc { get; private set; }", + "\n public Dictionary AocConfigurationByAocStep { get; private set; }", + "\n ", + "\n private Dictionary> aocStepByInputSource;", + "\n ", + "\n //Dimensions", + "\n public Dictionary AmountTypeDimension { get; private set; }", + "\n public Dictionary NoveltyDimension { get; private set; }", + "\n public Dictionary EstimateTypeDimension { get; private set; }", + "\n public Dictionary> EstimateTypesByImportFormat { get; private set; }", + "\n public Dictionary ExperienceAdjustEstimateTypeMapping { get; private set; } ", + "\n public HashSet ImportActualEstimateTypes => GetImportActualEstimateType();", + "\n", + "\n //Constructor", + "\n public ImportStorage(ImportArgs args, IDataSource querySource, IWorkspace workspace)", + "\n {", + "\n this.querySource = querySource;", + "\n this.workspace = workspace;", + "\n hierarchyCache = workspace.ToHierarchicalDimensionCache();", + "\n this.args = args;", + "\n }", + "\n ", + "\n //Initialize", + "\n public async Task InitializeAsync()", + "\n { ", + "\n //Dimensions", + "\n var estimateTypes = await workspace.Query().ToArrayAsync();", + "\n ", + "\n EstimateTypeDimension = estimateTypes.ToDictionary(x => x.SystemName);", + "\n AmountTypeDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", + "\n NoveltyDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", + "\n ", + "\n ExperienceAdjustEstimateTypeMapping = new Dictionary{{EstimateTypes.A, EstimateTypes.APA}}; //TODO move this logic", + "\n ", + "\n //Hierarchy Cache", + "\n await hierarchyCache.InitializeAsync();", + "\n ", + "\n //EstimateType to load and to update", + "\n EstimateTypesByImportFormat = new InputSource[] { InputSource.Opening, InputSource.Actual, InputSource.Cashflow }", + "\n .ToDictionary(x => x.ToString(), ", + "\n x => estimateTypes", + "\n .Where(et => et.InputSource.Contains(x))", + "\n .Select(et => et.SystemName)", + "\n .ToHashSet());", + "\n ", + "\n //ProjectionConfiguration : Current Period + projection for every Quarter End for current Year and next Years as in projectionConfiguration.csv", + "\n ProjectionConfiguration = (await workspace.Query()", + "\n .Where(x => x.Shift > 0 || x.TimeStep == args.Month || (x.TimeStep > args.Month && x.TimeStep % periodicityInMonths == 0))", + "\n .OrderBy(x => x.Shift).ThenBy(x => x.TimeStep).ToArrayAsync());", + "\n ", + "\n //Get Partitions", + "\n PartitionByRn = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode).ToArrayAsync()).Single().Id;", + "\n TargetPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", + "\n p.Year == CurrentReportingPeriod.Year &&", + "\n p.Month == CurrentReportingPeriod.Month &&", + "\n p.Scenario == args.Scenario).ToArrayAsync()).Single().Id;", + "\n DefaultPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", + "\n p.Year == CurrentReportingPeriod.Year &&", + "\n p.Month == CurrentReportingPeriod.Month &&", + "\n p.Scenario == null).ToArrayAsync()).Single().Id;", + "\n //Set Partitions", + "\n await querySource.Partition.SetAsync(PartitionByRn);", + "\n await workspace.Partition.SetAsync(PartitionByRn);", + "\n ", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n await workspace.Partition.SetAsync(TargetPartition);", + "\n ", + "\n //Get data from Workspace (result of parsing)", + "\n var parsedRawVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", + "\n var parsedIfrsVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", + "\n ", + "\n //DataNodes", + "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", + "\n ", + "\n //Accident Years", + "\n AccidentYearsByDataNode = (IDictionary>)", + "\n (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => new {x.DataNode, x.AccidentYear}) : parsedIfrsVariables.Select(x => new {x.DataNode, x.AccidentYear}))", + "\n .ToDictionaryGrouped(x => x.DataNode, x => (ICollection)x.Select(y => y.AccidentYear).ToHashSet());", + "\n ", + "\n // Import Scopes and Data Node relationship parameters", + "\n InterDataNodeParametersByGoc = await workspace.LoadInterDataNodeParametersAsync(args);", + "\n ", + "\n var primaryScopeFromParsedVariables = (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => x.DataNode) : parsedIfrsVariables.Select(x => x.DataNode)).ToHashSet();", + "\n var primaryScopeFromLinkedReinsurance = primaryScopeFromParsedVariables", + "\n .Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance && DataNodeDataBySystemName[goc].LiabilityType == LiabilityTypes.LRC)", + "\n .SelectMany(goc => InterDataNodeParametersByGoc.TryGetValue(goc, out var interDataNodeParamByPeriod)", + "\n ? interDataNodeParamByPeriod[CurrentPeriod].Select(param => param.DataNode == goc ? param.LinkedDataNode : param.DataNode).Where(goc => !primaryScopeFromParsedVariables.Contains(goc))", + "\n : Enumerable.Empty())", + "\n .ToHashSet();", + "\n ", + "\n var primaryScope = primaryScopeFromParsedVariables.Concat(primaryScopeFromLinkedReinsurance).ToHashSet();", + "\n var secondaryScope = InterDataNodeParametersByGoc", + "\n .Where(kvp => primaryScope.Contains(kvp.Key))", + "\n .SelectMany(kvp => { var linkedGocs = kvp.Value[CurrentPeriod].Select(param => param.DataNode == kvp.Key ? param.LinkedDataNode : param.DataNode);", + "\n return linkedGocs.Where(goc => !primaryScope.Contains(goc));}).ToHashSet();", + "\n var allImportScopes = new HashSet(primaryScope.Concat(secondaryScope));", + "\n ", + "\n DataNodesByImportScope = new Dictionary> { { ImportScope.Primary, primaryScope }, { ImportScope.Secondary, secondaryScope } };", + "\n ", + "\n // Parameters", + "\n PartnerRating = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner);", + "\n CreditDefaultRates = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating);", + "\n SingleDataNodeParametersByGoc = await workspace.LoadSingleDataNodeParametersAsync(args);", + "\n LockedInYieldCurve = await workspace.LoadLockedInYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn]));", + "\n CurrentYieldCurve = await workspace.LoadCurrentYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn])); //TODO Rename this variable", + "\n ", + "\n AocConfigurationByAocStep = await querySource.LoadAocStepConfigurationAsDictionaryAsync(args.Year, args.Month); ", + "\n aocStepByInputSource = ((InputSource[])Enum.GetValues(typeof(InputSource))).ToDictionary(x => x,", + "\n x => AocConfigurationByAocStep", + "\n .Where(kvp => kvp.Value.InputSource.Contains(x))", + "\n .Select(kvp => kvp.Key)", + "\n .ToHashSet());", + "\n ", + "\n //Previous Period", + "\n var openingRawVariables = Enumerable.Empty();", + "\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).ToHashSet();", + "\n", + "\nmyDNatInception = allImportScopesAtInceptionYear;", + "\nmyDNnotatInception = allImportScopesNotAtInceptionYear;", + "\n", + "\n if(allImportScopesAtInceptionYear.Any() && ImportFormat != ImportFormats.Opening) {", + "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", + "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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) ", + "\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()", + "\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)).ToArrayAsync())", + "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, ", + "\n Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", + "\n ", + "\n openingIfrsVariables = openingIfrsVariables.Union((await querySource.Query()", + "\n .Where(iv => iv.Partition == PreviousPeriodPartition && iv.AocType == AocTypes.EOP)", + "\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 //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) // TODO: ask Davide, why not union?", + "\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", + "\n if(DefaultPartition != TargetPartition) {", + "\n await querySource.Partition.SetAsync(DefaultPartition);", + "\n var defaultRawVariables = await querySource.Query().Where(rv => rv.Partition == DefaultPartition && primaryScope.Contains(rv.DataNode)).ToArrayAsync();", + "\n var defaultIfrsVariables = await querySource.Query().Where(iv => iv.Partition == DefaultPartition && allImportScopes.Contains(iv.DataNode)).ToArrayAsync(); ", + "\n rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", + "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n }", + "\n", + "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", + "\n IfrsVariablesByImportIdentity = (IDictionary>)ifrsVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", + "\n }", + "\n ", + "\n //Getters", + "\n ", + "\n //Periods", + "\n public ValuationPeriod GetValuationPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].ValuationPeriod;", + "\n public PeriodType GetYieldCurvePeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].YcPeriod;", + "\n public PeriodType GetCreditDefaultRiskPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].CdrPeriod;", + "\n ", + "\n public IEnumerable GetAllAocSteps(InputSource source) => aocStepByInputSource[source];", + "\n public IEnumerable GetCalculatedTelescopicAocSteps() => AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType == DataType.CalculatedTelescopic).Select(kvp => kvp.Key);", + "\n", + "\n //YieldCurve", + "\n public double[] GetYearlyYieldCurve(ImportIdentity id, string economicBasis) {", + "\n var yc = GetYieldCurve(id, economicBasis);", + "\n return yc.Values.Skip(args.Year - yc.Year).ToArray(); //Check if the returned array is empty? Log Warning?", + "\n }", + "\n ", + "\n public YieldCurve GetYieldCurve(ImportIdentity id, string economicBasis) => (economicBasis, GetYieldCurvePeriod(id)) switch {", + "\n (EconomicBases.C, PeriodType.BeginningOfPeriod) => CurrentYieldCurve[id.DataNode][PreviousPeriod],", + "\n (EconomicBases.C, PeriodType.EndOfPeriod) => CurrentYieldCurve[id.DataNode][CurrentPeriod],", + "\n (EconomicBases.L, _ ) => LockedInYieldCurve[id.DataNode],", + "\n (_, PeriodType.NotApplicable) => (YieldCurve)ApplicationMessage.Log(Error.YieldCurvePeriodNotApplicable, id.AocType, id.Novelty),", + "\n (_, _) => (YieldCurve)ApplicationMessage.Log(Error.EconomicBasisNotFound, id.DataNode)", + "\n };", + "\n", + "\n //int Identity.ProjectionPeriod ", + "\n public int GetProjectionCount() => ProjectionConfiguration.Count();", + "\n public int GetShift(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].Shift;", + "\n public int GetTimeStep(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].TimeStep;", + "\n ", + "\n public PeriodType GetPeriodType(string amountType, string estimateType) => ", + "\n amountType != null && AmountTypeDimension.TryGetValue(amountType, out var at) ", + "\n ? at.PeriodType", + "\n : estimateType != null && EstimateTypeDimension.TryGetValue(estimateType, out var ct) ", + "\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 ", + "\n public double[] GetValues(ImportIdentity id, Func whereClause) => GetRawVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Values ?? Enumerable.Empty().ToArray();", + "\n public double GetValue(ImportIdentity id, Func whereClause) => GetIfrsVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Value ?? 0;", + "\n ", + "\n public double[] GetValues(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValues(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", + "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", + "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, string economicBasis, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType && v.EconomicBasis == economicBasis);", + "\n ", + "\n //Novelty", + "\n private IEnumerable GetNoveltiesForAocType(string aocType, IEnumerable aocConfiguration) => aocConfiguration.Where(aocStep => aocStep.AocType == aocType).Select(aocStep => aocStep.Novelty);", + "\n public IEnumerable GetNovelties() => NoveltyDimension.Keys;", + "\n public IEnumerable GetNovelties(string aocType) => GetNoveltiesForAocType(aocType, AocConfigurationByAocStep.Keys);", + "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", + "\n ", + "\n //Accident years", + "\n public IEnumerable GetAccidentYears(string dataNode) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear : new int?[] { null };", + "\n ", + "\n // Parameters", + "\n public double GetNonPerformanceRiskRate (ImportIdentity identity) {", + "\n var period = GetCreditDefaultRiskPeriod(identity) == PeriodType.BeginningOfPeriod ? PreviousPeriod : CurrentPeriod;", + "\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 Partner == Internal then return 0;", + "\n if(!PartnerRating.TryGetValue(dataNodeData.Partner, out var rating)) ApplicationMessage.Log(Error.RatingNotFound, dataNodeData.Partner);", + "\n if(!CreditDefaultRates.TryGetValue(rating[period].CreditRiskRating, out var rate)) ApplicationMessage.Log(Error.CreditDefaultRateNotFound, rating[period].CreditRiskRating);", + "\n return rate[period].Values[0];", + "\n }", + "\n ", + "\n public double GetPremiumAllocationFactor(ImportIdentity id) => SingleDataNodeParametersByGoc.TryGetValue(id.DataNode, out var singleDataNodeParameter) ", + "\n ? singleDataNodeParameter[CurrentPeriod].PremiumAllocation : DefaultPremiumExperienceAdjustmentFactor;", + "\n ", + "\n // Data Node relationships", + "\n public IEnumerable GetUnderlyingGic(ImportIdentity id) => !InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", + "\n ? Enumerable.Empty()", + "\n : interDataNodeParameters[CurrentPeriod].Select(x => x.DataNode != id.DataNode ? x.DataNode : x.LinkedDataNode).Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance);", + "\n ", + "\n public double GetReinsuranceCoverage (ImportIdentity id, string gic) ", + "\n {", + "\n var targetPeriod = AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].RcPeriod == PeriodType.EndOfPeriod ? CurrentPeriod : PreviousPeriod;", + "\n return InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", + "\n ? interDataNodeParameters[targetPeriod].FirstOrDefault(x => x.DataNode == gic || x.LinkedDataNode == gic).ReinsuranceCoverage", + "\n : (double)ApplicationMessage.Log(Error.ReinsuranceCoverage, id.DataNode);", + "\n }", + "\n ", + "\n // Import Scope", + "\n public bool IsPrimaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Primary].Contains(dataNode);", + "\n public bool IsSecondaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Secondary].Contains(dataNode);", + "\n ", + "\n // Other", + "\n public IEnumerable GetNonAttributableAmountType() => new string[]{AmountTypes.NE};", + "\n public IEnumerable GetAttributableExpenseAndCommissionAmountType() => hierarchyCache.Get(AmountTypes.ACA).Descendants(includeSelf : true).Select(x => x.SystemName)", + "\n .Concat(hierarchyCache.Get(AmountTypes.AEA).Descendants(includeSelf : true).Select(x => x.SystemName));", + "\n public IEnumerable GetInvestmentClaims() => hierarchyCache.Get(AmountTypes.ICO).Descendants(includeSelf : true).Select(x => x.SystemName);", + "\n public IEnumerable GetPremiums() => hierarchyCache.Get(AmountTypes.PR).Descendants(includeSelf : true).Select(x => x.SystemName);", + "\n public IEnumerable GetClaims() => hierarchyCache.Get(AmountTypes.CL).Descendants().Select(x => x.SystemName);", + "\n}", + "\n*/" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -138,6 +474,7 @@ "source": [ "static IfrsVariable[] mya;", "\nstatic IfrsVariable[] myb;", + "\nstatic ImportStorage mystorage;", "\n", "\npublic async Task CheckIfrsVariablesFromImportStorageAsync(string importFormat, IEnumerable inputDataSetForWorkspace, IEnumerable inputDataSetForDataSource, IEnumerable ivsBenchmark, ImportArgs args)", "\n{", @@ -166,6 +503,7 @@ "\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 mya = ivs.Except(ivsBenchmark).ToArray();", "\n myb = ivsBenchmark.Except(ivs).ToArray();", + "\n mystorage = testStorage;", "\n //find duplicates in storage", "\n var ivsByIdentityString = ivs.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)}.\");", @@ -597,7 +935,7 @@ { "cell_type": "markdown", "source": [ - "## Openings", + "## Openings 1", "\n", "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate." ], @@ -645,6 +983,144 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Openings 2", + "\n", + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate." + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "// Data Node at inception year", + "\nawait 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.AA};", + "\n", + "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CL, 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 inputDataSetForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 90.7}, ", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\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": [ + "## Openings 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": [ + "// Data Node at inception year", + "\nawait 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.AA};", + "\n", + "\nvar inputDataSetForDataSource = new IfrsVariable[]{", + "\n basicIfrsVariable with {AocType = AocTypes.CL, 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 inputDataSetForWorkspace = new IfrsVariable[]{", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, 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.CL, Value = -15.0},", + "\n};", + "\n", + "\nvar activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\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 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": "markdown", "source": [ diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index e222656a..afed3dcc 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -14,7 +14,7 @@ } }, "nbformat": 4, - "nbformat_minor": 8, + "nbformat_minor": 5, "cells": [ { "cell_type": "markdown", @@ -347,6 +347,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,", From 48c4599f651b46f84517deb881b8dede13811a1d Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Mon, 17 Apr 2023 09:59:23 +0200 Subject: [PATCH 3/5] toward the implementation of feedback --- ifrs17/Import/ImportStorage.ipynb | 2 +- ifrs17/Import/Importers.ipynb | 15 +- ifrs17/Test/ImportStorageTest.ipynb | 403 ++++------------------------ 3 files changed, 64 insertions(+), 356 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index d06f9735..dadd4efe 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -276,7 +276,7 @@ "\n .Where(rv => rv.Partition == TargetPartition)", "\n .Where(rv => primaryScopeFromLinkedReinsurance.Contains(rv.DataNode)).ToArrayAsync()); ", "\n ", - "\n var ifrsVariables = parsedIfrsVariables.Concat(openingIfrsVariables) // TODO: ask Davide, why not union?", + "\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) ", diff --git a/ifrs17/Import/Importers.ipynb b/ifrs17/Import/Importers.ipynb index 8c659314..8139f3cf 100644 --- a/ifrs17/Import/Importers.ipynb +++ b/ifrs17/Import/Importers.ipynb @@ -1566,31 +1566,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", - "\n //var allArgs = await GetAllArgsAsync(primaryArgs, options.TargetDataSource, ImportFormats.Opening);", - "\n await DataNodeFactoryAsync(dataSet, ImportFormats.Opening, args, options.TargetDataSource);", + "\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 var workspace = Workspace.CreateNew();", - "\n var log = await ParseSimpleValueToWorkspaceAsync(dataSet, args, workspace, options.TargetDataSource);", + "\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 log = log.Merge(await ComputeAsync(args, workspace, workspaceToCompute, false)); ", - "\n if(log.Errors.Any()) return Activity.Finish().Merge(log);", - "\n await workspaceToCompute.CommitToTargetAsync(options.TargetDataSource, x => x.SnapshotMode());", - "\n return Activity.Finish().Merge(log);", - "\n/*", "\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(log);", - "\n*/", + "\n", "\n})" ], "metadata": {}, diff --git a/ifrs17/Test/ImportStorageTest.ipynb b/ifrs17/Test/ImportStorageTest.ipynb index c5bb269a..ba790912 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -124,342 +124,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "/*", - "\nstatic HashSet myDNatInception;", - "\nstatic HashSet myDNnotatInception;", - "\n", - "\npublic class ImportStorage", - "\n{ ", - "\n private readonly IDataSource querySource; ", - "\n private readonly IWorkspace workspace;", - "\n private readonly Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache;", - "\n private readonly ImportArgs args;", - "\n ", - "\n // Constants", - "\n private static int periodicityInMonths => 3; // Revisit", - "\n ", - "\n //Format", - "\n public string ImportFormat => args.ImportFormat; ", - "\n ", - "\n //Time Periods ", - "\n public (int Year, int Month) CurrentReportingPeriod => (args.Year, args.Month);", - "\n public (int Year, int Month) PreviousReportingPeriod => (args.Year - 1, MonthInAYear); // YTD Logic", - "\n", - "\n //Partitions", - "\n public Guid PartitionByRn;", - "\n public Guid TargetPartition;", - "\n public Guid DefaultPartition;", - "\n public Guid PreviousPeriodPartition; ", - "\n", - "\n //Projections", - "\n private ProjectionConfiguration[] ProjectionConfiguration;", - "\n ", - "\n //DataNodes", - "\n public IDictionary DataNodeDataBySystemName { get; private set; }", - "\n public IDictionary> DataNodesByImportScope { get; private set; }", - "\n public IDictionary> AccidentYearsByDataNode { get; private set; }", - "\n //Variables", - "\n public IDictionary> RawVariablesByImportIdentity { get; private set; }", - "\n public IDictionary> IfrsVariablesByImportIdentity { get; private set; }", - "\n ", - "\n //Parameters", - "\n public Dictionary LockedInYieldCurve { get; private set; }", - "\n public Dictionary> CurrentYieldCurve { get; private set; }", - "\n public Dictionary> PartnerRating { get; private set; }", - "\n public Dictionary> CreditDefaultRates { get; private set; }", - "\n public Dictionary> SingleDataNodeParametersByGoc { get; private set; }", - "\n public Dictionary>> InterDataNodeParametersByGoc { get; private set; }", - "\n public Dictionary AocConfigurationByAocStep { get; private set; }", - "\n ", - "\n private Dictionary> aocStepByInputSource;", - "\n ", - "\n //Dimensions", - "\n public Dictionary AmountTypeDimension { get; private set; }", - "\n public Dictionary NoveltyDimension { get; private set; }", - "\n public Dictionary EstimateTypeDimension { get; private set; }", - "\n public Dictionary> EstimateTypesByImportFormat { get; private set; }", - "\n public Dictionary ExperienceAdjustEstimateTypeMapping { get; private set; } ", - "\n public HashSet ImportActualEstimateTypes => GetImportActualEstimateType();", - "\n", - "\n //Constructor", - "\n public ImportStorage(ImportArgs args, IDataSource querySource, IWorkspace workspace)", - "\n {", - "\n this.querySource = querySource;", - "\n this.workspace = workspace;", - "\n hierarchyCache = workspace.ToHierarchicalDimensionCache();", - "\n this.args = args;", - "\n }", - "\n ", - "\n //Initialize", - "\n public async Task InitializeAsync()", - "\n { ", - "\n //Dimensions", - "\n var estimateTypes = await workspace.Query().ToArrayAsync();", - "\n ", - "\n EstimateTypeDimension = estimateTypes.ToDictionary(x => x.SystemName);", - "\n AmountTypeDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", - "\n NoveltyDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", - "\n ", - "\n ExperienceAdjustEstimateTypeMapping = new Dictionary{{EstimateTypes.A, EstimateTypes.APA}}; //TODO move this logic", - "\n ", - "\n //Hierarchy Cache", - "\n await hierarchyCache.InitializeAsync();", - "\n ", - "\n //EstimateType to load and to update", - "\n EstimateTypesByImportFormat = new InputSource[] { InputSource.Opening, InputSource.Actual, InputSource.Cashflow }", - "\n .ToDictionary(x => x.ToString(), ", - "\n x => estimateTypes", - "\n .Where(et => et.InputSource.Contains(x))", - "\n .Select(et => et.SystemName)", - "\n .ToHashSet());", - "\n ", - "\n //ProjectionConfiguration : Current Period + projection for every Quarter End for current Year and next Years as in projectionConfiguration.csv", - "\n ProjectionConfiguration = (await workspace.Query()", - "\n .Where(x => x.Shift > 0 || x.TimeStep == args.Month || (x.TimeStep > args.Month && x.TimeStep % periodicityInMonths == 0))", - "\n .OrderBy(x => x.Shift).ThenBy(x => x.TimeStep).ToArrayAsync());", - "\n ", - "\n //Get Partitions", - "\n PartitionByRn = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode).ToArrayAsync()).Single().Id;", - "\n TargetPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", - "\n p.Year == CurrentReportingPeriod.Year &&", - "\n p.Month == CurrentReportingPeriod.Month &&", - "\n p.Scenario == args.Scenario).ToArrayAsync()).Single().Id;", - "\n DefaultPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", - "\n p.Year == CurrentReportingPeriod.Year &&", - "\n p.Month == CurrentReportingPeriod.Month &&", - "\n p.Scenario == null).ToArrayAsync()).Single().Id;", - "\n //Set Partitions", - "\n await querySource.Partition.SetAsync(PartitionByRn);", - "\n await workspace.Partition.SetAsync(PartitionByRn);", - "\n ", - "\n await querySource.Partition.SetAsync(TargetPartition);", - "\n await workspace.Partition.SetAsync(TargetPartition);", - "\n ", - "\n //Get data from Workspace (result of parsing)", - "\n var parsedRawVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", - "\n var parsedIfrsVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", - "\n ", - "\n //DataNodes", - "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", - "\n ", - "\n //Accident Years", - "\n AccidentYearsByDataNode = (IDictionary>)", - "\n (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => new {x.DataNode, x.AccidentYear}) : parsedIfrsVariables.Select(x => new {x.DataNode, x.AccidentYear}))", - "\n .ToDictionaryGrouped(x => x.DataNode, x => (ICollection)x.Select(y => y.AccidentYear).ToHashSet());", - "\n ", - "\n // Import Scopes and Data Node relationship parameters", - "\n InterDataNodeParametersByGoc = await workspace.LoadInterDataNodeParametersAsync(args);", - "\n ", - "\n var primaryScopeFromParsedVariables = (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => x.DataNode) : parsedIfrsVariables.Select(x => x.DataNode)).ToHashSet();", - "\n var primaryScopeFromLinkedReinsurance = primaryScopeFromParsedVariables", - "\n .Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance && DataNodeDataBySystemName[goc].LiabilityType == LiabilityTypes.LRC)", - "\n .SelectMany(goc => InterDataNodeParametersByGoc.TryGetValue(goc, out var interDataNodeParamByPeriod)", - "\n ? interDataNodeParamByPeriod[CurrentPeriod].Select(param => param.DataNode == goc ? param.LinkedDataNode : param.DataNode).Where(goc => !primaryScopeFromParsedVariables.Contains(goc))", - "\n : Enumerable.Empty())", - "\n .ToHashSet();", - "\n ", - "\n var primaryScope = primaryScopeFromParsedVariables.Concat(primaryScopeFromLinkedReinsurance).ToHashSet();", - "\n var secondaryScope = InterDataNodeParametersByGoc", - "\n .Where(kvp => primaryScope.Contains(kvp.Key))", - "\n .SelectMany(kvp => { var linkedGocs = kvp.Value[CurrentPeriod].Select(param => param.DataNode == kvp.Key ? param.LinkedDataNode : param.DataNode);", - "\n return linkedGocs.Where(goc => !primaryScope.Contains(goc));}).ToHashSet();", - "\n var allImportScopes = new HashSet(primaryScope.Concat(secondaryScope));", - "\n ", - "\n DataNodesByImportScope = new Dictionary> { { ImportScope.Primary, primaryScope }, { ImportScope.Secondary, secondaryScope } };", - "\n ", - "\n // Parameters", - "\n PartnerRating = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner);", - "\n CreditDefaultRates = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating);", - "\n SingleDataNodeParametersByGoc = await workspace.LoadSingleDataNodeParametersAsync(args);", - "\n LockedInYieldCurve = await workspace.LoadLockedInYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn]));", - "\n CurrentYieldCurve = await workspace.LoadCurrentYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn])); //TODO Rename this variable", - "\n ", - "\n AocConfigurationByAocStep = await querySource.LoadAocStepConfigurationAsDictionaryAsync(args.Year, args.Month); ", - "\n aocStepByInputSource = ((InputSource[])Enum.GetValues(typeof(InputSource))).ToDictionary(x => x,", - "\n x => AocConfigurationByAocStep", - "\n .Where(kvp => kvp.Value.InputSource.Contains(x))", - "\n .Select(kvp => kvp.Key)", - "\n .ToHashSet());", - "\n ", - "\n //Previous Period", - "\n var openingRawVariables = Enumerable.Empty();", - "\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).ToHashSet();", - "\n", - "\nmyDNatInception = allImportScopesAtInceptionYear;", - "\nmyDNnotatInception = allImportScopesNotAtInceptionYear;", - "\n", - "\n if(allImportScopesAtInceptionYear.Any() && ImportFormat != ImportFormats.Opening) {", - "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", - "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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) ", - "\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()", - "\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)).ToArrayAsync())", - "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, ", - "\n Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", - "\n ", - "\n openingIfrsVariables = openingIfrsVariables.Union((await querySource.Query()", - "\n .Where(iv => iv.Partition == PreviousPeriodPartition && iv.AocType == AocTypes.EOP)", - "\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 //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) // TODO: ask Davide, why not union?", - "\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", - "\n if(DefaultPartition != TargetPartition) {", - "\n await querySource.Partition.SetAsync(DefaultPartition);", - "\n var defaultRawVariables = await querySource.Query().Where(rv => rv.Partition == DefaultPartition && primaryScope.Contains(rv.DataNode)).ToArrayAsync();", - "\n var defaultIfrsVariables = await querySource.Query().Where(iv => iv.Partition == DefaultPartition && allImportScopes.Contains(iv.DataNode)).ToArrayAsync(); ", - "\n rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", - "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", - "\n await querySource.Partition.SetAsync(TargetPartition);", - "\n }", - "\n", - "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", - "\n IfrsVariablesByImportIdentity = (IDictionary>)ifrsVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", - "\n }", - "\n ", - "\n //Getters", - "\n ", - "\n //Periods", - "\n public ValuationPeriod GetValuationPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].ValuationPeriod;", - "\n public PeriodType GetYieldCurvePeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].YcPeriod;", - "\n public PeriodType GetCreditDefaultRiskPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].CdrPeriod;", - "\n ", - "\n public IEnumerable GetAllAocSteps(InputSource source) => aocStepByInputSource[source];", - "\n public IEnumerable GetCalculatedTelescopicAocSteps() => AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType == DataType.CalculatedTelescopic).Select(kvp => kvp.Key);", - "\n", - "\n //YieldCurve", - "\n public double[] GetYearlyYieldCurve(ImportIdentity id, string economicBasis) {", - "\n var yc = GetYieldCurve(id, economicBasis);", - "\n return yc.Values.Skip(args.Year - yc.Year).ToArray(); //Check if the returned array is empty? Log Warning?", - "\n }", - "\n ", - "\n public YieldCurve GetYieldCurve(ImportIdentity id, string economicBasis) => (economicBasis, GetYieldCurvePeriod(id)) switch {", - "\n (EconomicBases.C, PeriodType.BeginningOfPeriod) => CurrentYieldCurve[id.DataNode][PreviousPeriod],", - "\n (EconomicBases.C, PeriodType.EndOfPeriod) => CurrentYieldCurve[id.DataNode][CurrentPeriod],", - "\n (EconomicBases.L, _ ) => LockedInYieldCurve[id.DataNode],", - "\n (_, PeriodType.NotApplicable) => (YieldCurve)ApplicationMessage.Log(Error.YieldCurvePeriodNotApplicable, id.AocType, id.Novelty),", - "\n (_, _) => (YieldCurve)ApplicationMessage.Log(Error.EconomicBasisNotFound, id.DataNode)", - "\n };", - "\n", - "\n //int Identity.ProjectionPeriod ", - "\n public int GetProjectionCount() => ProjectionConfiguration.Count();", - "\n public int GetShift(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].Shift;", - "\n public int GetTimeStep(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].TimeStep;", - "\n ", - "\n public PeriodType GetPeriodType(string amountType, string estimateType) => ", - "\n amountType != null && AmountTypeDimension.TryGetValue(amountType, out var at) ", - "\n ? at.PeriodType", - "\n : estimateType != null && EstimateTypeDimension.TryGetValue(estimateType, out var ct) ", - "\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 ", - "\n public double[] GetValues(ImportIdentity id, Func whereClause) => GetRawVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Values ?? Enumerable.Empty().ToArray();", - "\n public double GetValue(ImportIdentity id, Func whereClause) => GetIfrsVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Value ?? 0;", - "\n ", - "\n public double[] GetValues(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValues(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", - "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", - "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, string economicBasis, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType && v.EconomicBasis == economicBasis);", - "\n ", - "\n //Novelty", - "\n private IEnumerable GetNoveltiesForAocType(string aocType, IEnumerable aocConfiguration) => aocConfiguration.Where(aocStep => aocStep.AocType == aocType).Select(aocStep => aocStep.Novelty);", - "\n public IEnumerable GetNovelties() => NoveltyDimension.Keys;", - "\n public IEnumerable GetNovelties(string aocType) => GetNoveltiesForAocType(aocType, AocConfigurationByAocStep.Keys);", - "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", - "\n ", - "\n //Accident years", - "\n public IEnumerable GetAccidentYears(string dataNode) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear : new int?[] { null };", - "\n ", - "\n // Parameters", - "\n public double GetNonPerformanceRiskRate (ImportIdentity identity) {", - "\n var period = GetCreditDefaultRiskPeriod(identity) == PeriodType.BeginningOfPeriod ? PreviousPeriod : CurrentPeriod;", - "\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 Partner == Internal then return 0;", - "\n if(!PartnerRating.TryGetValue(dataNodeData.Partner, out var rating)) ApplicationMessage.Log(Error.RatingNotFound, dataNodeData.Partner);", - "\n if(!CreditDefaultRates.TryGetValue(rating[period].CreditRiskRating, out var rate)) ApplicationMessage.Log(Error.CreditDefaultRateNotFound, rating[period].CreditRiskRating);", - "\n return rate[period].Values[0];", - "\n }", - "\n ", - "\n public double GetPremiumAllocationFactor(ImportIdentity id) => SingleDataNodeParametersByGoc.TryGetValue(id.DataNode, out var singleDataNodeParameter) ", - "\n ? singleDataNodeParameter[CurrentPeriod].PremiumAllocation : DefaultPremiumExperienceAdjustmentFactor;", - "\n ", - "\n // Data Node relationships", - "\n public IEnumerable GetUnderlyingGic(ImportIdentity id) => !InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", - "\n ? Enumerable.Empty()", - "\n : interDataNodeParameters[CurrentPeriod].Select(x => x.DataNode != id.DataNode ? x.DataNode : x.LinkedDataNode).Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance);", - "\n ", - "\n public double GetReinsuranceCoverage (ImportIdentity id, string gic) ", - "\n {", - "\n var targetPeriod = AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].RcPeriod == PeriodType.EndOfPeriod ? CurrentPeriod : PreviousPeriod;", - "\n return InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", - "\n ? interDataNodeParameters[targetPeriod].FirstOrDefault(x => x.DataNode == gic || x.LinkedDataNode == gic).ReinsuranceCoverage", - "\n : (double)ApplicationMessage.Log(Error.ReinsuranceCoverage, id.DataNode);", - "\n }", - "\n ", - "\n // Import Scope", - "\n public bool IsPrimaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Primary].Contains(dataNode);", - "\n public bool IsSecondaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Secondary].Contains(dataNode);", - "\n ", - "\n // Other", - "\n public IEnumerable GetNonAttributableAmountType() => new string[]{AmountTypes.NE};", - "\n public IEnumerable GetAttributableExpenseAndCommissionAmountType() => hierarchyCache.Get(AmountTypes.ACA).Descendants(includeSelf : true).Select(x => x.SystemName)", - "\n .Concat(hierarchyCache.Get(AmountTypes.AEA).Descendants(includeSelf : true).Select(x => x.SystemName));", - "\n public IEnumerable GetInvestmentClaims() => hierarchyCache.Get(AmountTypes.ICO).Descendants(includeSelf : true).Select(x => x.SystemName);", - "\n public IEnumerable GetPremiums() => hierarchyCache.Get(AmountTypes.PR).Descendants(includeSelf : true).Select(x => x.SystemName);", - "\n public IEnumerable GetClaims() => hierarchyCache.Get(AmountTypes.CL).Descendants().Select(x => x.SystemName);", - "\n}", - "\n*/" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -822,6 +486,17 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Openings Reimport", + "\n", + "\nccc" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -935,9 +610,9 @@ { "cell_type": "markdown", "source": [ - "## Openings 1", + "## Openings Actual 1", "\n", - "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate." + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Data Node is not at inception year." ], "metadata": {}, "execution_count": 0, @@ -986,9 +661,9 @@ { "cell_type": "markdown", "source": [ - "## Openings 2", + "## Openings Actual 2", "\n", - "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate." + "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Data Node is at inception year." ], "metadata": {}, "execution_count": 0, @@ -997,8 +672,7 @@ { "cell_type": "code", "source": [ - "// Data Node at inception year", - "\nawait Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "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}});" @@ -1048,7 +722,7 @@ { "cell_type": "markdown", "source": [ - "## Openings 3", + "## Openings Actual 3", "\n", "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Only the GRIC is at inception year." ], @@ -1059,8 +733,7 @@ { "cell_type": "code", "source": [ - "// Data Node at inception year", - "\nawait Workspace.DeleteAsync(await Workspace.Query().ToArrayAsync());", + "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}});" @@ -1121,6 +794,46 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "## Openings Cashflow 1", + "\n", + "\naaa" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Openings Cashflow 2", + "\n", + "\nbbb" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ From 22a8433bdc6696711ed14a56def1cb3ff60d0c67 Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Sun, 23 Apr 2023 18:11:00 +0200 Subject: [PATCH 4/5] implement all feedback --- ifrs17/Import/ImportStorage.ipynb | 4 +- ifrs17/Test/ImportStorageTest.ipynb | 550 +++++++++++++++++++++++++--- ifrs17/Test/TestData.ipynb | 19 +- 3 files changed, 514 insertions(+), 59 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index abc1c39d..67a64790 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -233,13 +233,13 @@ "\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).ToHashSet();", "\n", - "\n if(allImportScopesAtInceptionYear.Any() && ImportFormat != ImportFormats.Opening) {", + "\n if(allImportScopesAtInceptionYear.Any()) {", "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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) ", + "\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 }", diff --git a/ifrs17/Test/ImportStorageTest.ipynb b/ifrs17/Test/ImportStorageTest.ipynb index ba790912..402e3945 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -44,11 +44,354 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "static HashSet myimportscopesatinception;", + "\nstatic HashSet myimportscopesnotatinception;", + "\nstatic HashSet myprimaryscope;", + "\nstatic HashSet mysecondaryscope;", + "\nstatic HashSet myprimaryscopefromparsed;", + "\nstatic HashSet myprimaryscopefromlinked;", + "\n", + "\npublic class ImportStorage", + "\n{", + "\n private readonly IDataSource querySource; ", + "\n private readonly IWorkspace workspace;", + "\n private readonly Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache;", + "\n private readonly ImportArgs args;", + "\n ", + "\n // Constants", + "\n private static int periodicityInMonths => 3; // Revisit", + "\n ", + "\n //Format", + "\n public string ImportFormat => args.ImportFormat; ", + "\n ", + "\n //Time Periods ", + "\n public (int Year, int Month) CurrentReportingPeriod => (args.Year, args.Month);", + "\n public (int Year, int Month) PreviousReportingPeriod => (args.Year - 1, MonthInAYear); // YTD Logic", + "\n", + "\n //Partitions", + "\n public Guid PartitionByRn;", + "\n public Guid TargetPartition;", + "\n public Guid DefaultPartition;", + "\n public Guid PreviousPeriodPartition; ", + "\n", + "\n //Projections", + "\n private ProjectionConfiguration[] ProjectionConfiguration;", + "\n ", + "\n //DataNodes", + "\n public IDictionary DataNodeDataBySystemName { get; private set; }", + "\n public IDictionary> DataNodesByImportScope { get; private set; }", + "\n public IDictionary> AccidentYearsByDataNode { get; private set; }", + "\n //Variables", + "\n public IDictionary> RawVariablesByImportIdentity { get; private set; }", + "\n public IDictionary> IfrsVariablesByImportIdentity { get; private set; }", + "\n ", + "\n //Parameters", + "\n public Dictionary LockedInYieldCurve { get; private set; }", + "\n public Dictionary> CurrentYieldCurve { get; private set; }", + "\n public Dictionary> PartnerRating { get; private set; }", + "\n public Dictionary> CreditDefaultRates { get; private set; }", + "\n public Dictionary> SingleDataNodeParametersByGoc { get; private set; }", + "\n public Dictionary>> InterDataNodeParametersByGoc { get; private set; }", + "\n public Dictionary AocConfigurationByAocStep { get; private set; }", + "\n ", + "\n private Dictionary> aocStepByInputSource;", + "\n ", + "\n //Dimensions", + "\n public Dictionary AmountTypeDimension { get; private set; }", + "\n public Dictionary NoveltyDimension { get; private set; }", + "\n public Dictionary EstimateTypeDimension { get; private set; }", + "\n public Dictionary> EstimateTypesByImportFormat { get; private set; }", + "\n public Dictionary ExperienceAdjustEstimateTypeMapping { get; private set; } ", + "\n public HashSet ImportActualEstimateTypes => GetImportActualEstimateType();", + "\n", + "\n //Constructor", + "\n public ImportStorage(ImportArgs args, IDataSource querySource, IWorkspace workspace)", + "\n {", + "\n this.querySource = querySource;", + "\n this.workspace = workspace;", + "\n hierarchyCache = workspace.ToHierarchicalDimensionCache();", + "\n this.args = args;", + "\n }", + "\n ", + "\n //Initialize", + "\n public async Task InitializeAsync()", + "\n { ", + "\n //Dimensions", + "\n var estimateTypes = await workspace.Query().ToArrayAsync();", + "\n ", + "\n EstimateTypeDimension = estimateTypes.ToDictionary(x => x.SystemName);", + "\n AmountTypeDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", + "\n NoveltyDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", + "\n ", + "\n ExperienceAdjustEstimateTypeMapping = new Dictionary{{EstimateTypes.A, EstimateTypes.APA}}; //TODO move this logic", + "\n ", + "\n //Hierarchy Cache", + "\n await hierarchyCache.InitializeAsync();", + "\n ", + "\n //EstimateType to load and to update", + "\n EstimateTypesByImportFormat = new InputSource[] { InputSource.Opening, InputSource.Actual, InputSource.Cashflow }", + "\n .ToDictionary(x => x.ToString(), ", + "\n x => estimateTypes", + "\n .Where(et => et.InputSource.Contains(x))", + "\n .Select(et => et.SystemName)", + "\n .ToHashSet());", + "\n ", + "\n //ProjectionConfiguration : Current Period + projection for every Quarter End for current Year and next Years as in projectionConfiguration.csv", + "\n ProjectionConfiguration = (await workspace.Query()", + "\n .Where(x => x.Shift > 0 || x.TimeStep == args.Month || (x.TimeStep > args.Month && x.TimeStep % periodicityInMonths == 0))", + "\n .OrderBy(x => x.Shift).ThenBy(x => x.TimeStep).ToArrayAsync());", + "\n ", + "\n //Get Partitions", + "\n PartitionByRn = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode).ToArrayAsync()).Single().Id;", + "\n TargetPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", + "\n p.Year == CurrentReportingPeriod.Year &&", + "\n p.Month == CurrentReportingPeriod.Month &&", + "\n p.Scenario == args.Scenario).ToArrayAsync()).Single().Id;", + "\n DefaultPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", + "\n p.Year == CurrentReportingPeriod.Year &&", + "\n p.Month == CurrentReportingPeriod.Month &&", + "\n p.Scenario == null).ToArrayAsync()).Single().Id;", + "\n //Set Partitions", + "\n await querySource.Partition.SetAsync(PartitionByRn);", + "\n await workspace.Partition.SetAsync(PartitionByRn);", + "\n ", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n await workspace.Partition.SetAsync(TargetPartition);", + "\n ", + "\n //Get data from Workspace (result of parsing)", + "\n var parsedRawVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", + "\n var parsedIfrsVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", + "\n ", + "\n //DataNodes", + "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", + "\n ", + "\n //Accident Years", + "\n AccidentYearsByDataNode = (IDictionary>)", + "\n (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => new {x.DataNode, x.AccidentYear}) : parsedIfrsVariables.Select(x => new {x.DataNode, x.AccidentYear}))", + "\n .ToDictionaryGrouped(x => x.DataNode, x => (ICollection)x.Select(y => y.AccidentYear).ToHashSet());", + "\n ", + "\n // Import Scopes and Data Node relationship parameters", + "\n InterDataNodeParametersByGoc = await workspace.LoadInterDataNodeParametersAsync(args);", + "\n ", + "\n var primaryScopeFromParsedVariables = (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => x.DataNode) : parsedIfrsVariables.Select(x => x.DataNode)).ToHashSet();", + "\n var primaryScopeFromLinkedReinsurance = primaryScopeFromParsedVariables", + "\n .Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance && DataNodeDataBySystemName[goc].LiabilityType == LiabilityTypes.LRC)", + "\n .SelectMany(goc => InterDataNodeParametersByGoc.TryGetValue(goc, out var interDataNodeParamByPeriod)", + "\n ? interDataNodeParamByPeriod[CurrentPeriod].Select(param => param.DataNode == goc ? param.LinkedDataNode : param.DataNode).Where(goc => !primaryScopeFromParsedVariables.Contains(goc))", + "\n : Enumerable.Empty())", + "\n .ToHashSet();", + "\n", + "\n var primaryScope = primaryScopeFromParsedVariables.Concat(primaryScopeFromLinkedReinsurance).ToHashSet();", + "\n var secondaryScope = InterDataNodeParametersByGoc", + "\n .Where(kvp => primaryScope.Contains(kvp.Key))", + "\n .SelectMany(kvp => { var linkedGocs = kvp.Value[CurrentPeriod].Select(param => param.DataNode == kvp.Key ? param.LinkedDataNode : param.DataNode);", + "\n return linkedGocs.Where(goc => !primaryScope.Contains(goc));}).ToHashSet();", + "\n var allImportScopes = new HashSet(primaryScope.Concat(secondaryScope));", + "\n ", + "\n DataNodesByImportScope = new Dictionary> { { ImportScope.Primary, primaryScope }, { ImportScope.Secondary, secondaryScope } };", + "\n ", + "\n // Parameters", + "\n PartnerRating = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner);", + "\n CreditDefaultRates = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating);", + "\n SingleDataNodeParametersByGoc = await workspace.LoadSingleDataNodeParametersAsync(args);", + "\n LockedInYieldCurve = await workspace.LoadLockedInYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn]));", + "\n CurrentYieldCurve = await workspace.LoadCurrentYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn])); //TODO Rename this variable", + "\n ", + "\n AocConfigurationByAocStep = await querySource.LoadAocStepConfigurationAsDictionaryAsync(args.Year, args.Month); ", + "\n aocStepByInputSource = ((InputSource[])Enum.GetValues(typeof(InputSource))).ToDictionary(x => x,", + "\n x => AocConfigurationByAocStep", + "\n .Where(kvp => kvp.Value.InputSource.Contains(x))", + "\n .Select(kvp => kvp.Key)", + "\n .ToHashSet());", + "\n ", + "\n //Previous Period", + "\n var openingRawVariables = Enumerable.Empty();", + "\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).ToHashSet();", + "\nmyimportscopesatinception=allImportScopesAtInceptionYear;", + "\nmyimportscopesnotatinception=allImportScopesNotAtInceptionYear;", + "\nmyprimaryscope = primaryScope;", + "\nmysecondaryscope = secondaryScope;", + "\nmyprimaryscopefromparsed = primaryScopeFromParsedVariables;", + "\nmyprimaryscopefromlinked = primaryScopeFromLinkedReinsurance;", + "\n if(allImportScopesAtInceptionYear.Any()) {", + "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", + "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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()", + "\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)).ToArrayAsync())", + "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, ", + "\n Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", + "\n ", + "\n openingIfrsVariables = openingIfrsVariables.Union((await querySource.Query()", + "\n .Where(iv => iv.Partition == PreviousPeriodPartition && iv.AocType == AocTypes.EOP)", + "\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 //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.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", + "\n if(DefaultPartition != TargetPartition) {", + "\n await querySource.Partition.SetAsync(DefaultPartition);", + "\n var defaultRawVariables = await querySource.Query().Where(rv => rv.Partition == DefaultPartition && primaryScope.Contains(rv.DataNode)).ToArrayAsync();", + "\n var defaultIfrsVariables = await querySource.Query().Where(iv => iv.Partition == DefaultPartition && allImportScopes.Contains(iv.DataNode)).ToArrayAsync(); ", + "\n rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", + "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", + "\n await querySource.Partition.SetAsync(TargetPartition);", + "\n }", + "\n", + "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", + "\n IfrsVariablesByImportIdentity = (IDictionary>)ifrsVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", + "\n }", + "\n ", + "\n //Getters", + "\n ", + "\n //Periods", + "\n public ValuationPeriod GetValuationPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].ValuationPeriod;", + "\n public PeriodType GetYieldCurvePeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].YcPeriod;", + "\n public PeriodType GetCreditDefaultRiskPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].CdrPeriod;", + "\n ", + "\n public IEnumerable GetAllAocSteps(InputSource source) => aocStepByInputSource[source];", + "\n public IEnumerable GetCalculatedTelescopicAocSteps() => AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType == DataType.CalculatedTelescopic).Select(kvp => kvp.Key);", + "\n", + "\n //YieldCurve", + "\n public double[] GetYearlyYieldCurve(ImportIdentity id, string economicBasis) {", + "\n var yc = GetYieldCurve(id, economicBasis);", + "\n return yc.Values.Skip(args.Year - yc.Year).ToArray(); //Check if the returned array is empty? Log Warning?", + "\n }", + "\n ", + "\n public YieldCurve GetYieldCurve(ImportIdentity id, string economicBasis) => (economicBasis, GetYieldCurvePeriod(id)) switch {", + "\n (EconomicBases.C, PeriodType.BeginningOfPeriod ) => GetShift(id.ProjectionPeriod) > 0 ", + "\n ? CurrentYieldCurve[id.DataNode][CurrentPeriod]", + "\n : CurrentYieldCurve[id.DataNode][PreviousPeriod],", + "\n (EconomicBases.C, PeriodType.EndOfPeriod) => CurrentYieldCurve[id.DataNode][CurrentPeriod], ", + "\n (EconomicBases.L, _ ) => LockedInYieldCurve[id.DataNode],", + "\n (_, PeriodType.NotApplicable) => (YieldCurve)ApplicationMessage.Log(Error.YieldCurvePeriodNotApplicable, id.AocType, id.Novelty),", + "\n (_, _) => (YieldCurve)ApplicationMessage.Log(Error.EconomicBasisNotFound, id.DataNode)", + "\n };", + "\n", + "\n //int Identity.ProjectionPeriod ", + "\n public int GetProjectionCount() => ProjectionConfiguration.Count();", + "\n public int GetShift(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].Shift;", + "\n public int GetTimeStep(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].TimeStep;", + "\n ", + "\n public PeriodType GetPeriodType(string amountType, string estimateType) => ", + "\n amountType != null && AmountTypeDimension.TryGetValue(amountType, out var at) ", + "\n ? at.PeriodType", + "\n : estimateType != null && EstimateTypeDimension.TryGetValue(estimateType, out var ct) ", + "\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 ", + "\n public double[] GetValues(ImportIdentity id, Func whereClause) => GetRawVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Values ?? Enumerable.Empty().ToArray();", + "\n public double GetValue(ImportIdentity id, Func whereClause) => GetIfrsVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Value ?? 0;", + "\n public double[] GetValues(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValues(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", + "\n", + "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", + "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, string economicBasis, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType && v.EconomicBasis == economicBasis);", + "\n ", + "\n //Novelty", + "\n private IEnumerable GetNoveltiesForAocType(string aocType, IEnumerable aocConfiguration) => aocConfiguration.Where(aocStep => aocStep.AocType == aocType).Select(aocStep => aocStep.Novelty);", + "\n public IEnumerable GetNovelties() => NoveltyDimension.Keys;", + "\n public IEnumerable GetNovelties(string aocType) => GetNoveltiesForAocType(aocType, AocConfigurationByAocStep.Keys);", + "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", + "\n ", + "\n //Accident years", + "\n public IEnumerable GetAccidentYears(string dataNode) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear : new int?[] { null };", + "\n ", + "\n // Parameters", + "\n public double GetNonPerformanceRiskRate (ImportIdentity identity) {", + "\n var period = GetCreditDefaultRiskPeriod(identity) == PeriodType.BeginningOfPeriod ? PreviousPeriod : CurrentPeriod;", + "\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 Partner == Internal then return 0;", + "\n if(!PartnerRating.TryGetValue(dataNodeData.Partner, out var rating)) ApplicationMessage.Log(Error.RatingNotFound, dataNodeData.Partner);", + "\n if(!CreditDefaultRates.TryGetValue(rating[period].CreditRiskRating, out var rate)) ApplicationMessage.Log(Error.CreditDefaultRateNotFound, rating[period].CreditRiskRating);", + "\n return Math.Pow(1d + rate[period].Values[0], 1d / 12d) - 1d;", + "\n }", + "\n ", + "\n public double GetPremiumAllocationFactor(ImportIdentity id) => SingleDataNodeParametersByGoc.TryGetValue(id.DataNode, out var singleDataNodeParameter) ", + "\n ? singleDataNodeParameter[CurrentPeriod].PremiumAllocation : DefaultPremiumExperienceAdjustmentFactor;", + "\n ", + "\n // Data Node relationships", + "\n public IEnumerable GetUnderlyingGic(ImportIdentity id) => !InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", + "\n ? Enumerable.Empty()", + "\n : interDataNodeParameters[CurrentPeriod].Select(x => x.DataNode != id.DataNode ? x.DataNode : x.LinkedDataNode).Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance);", + "\n ", + "\n public double GetReinsuranceCoverage (ImportIdentity id, string gic) ", + "\n {", + "\n var targetPeriod = AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].RcPeriod == PeriodType.EndOfPeriod ? CurrentPeriod : PreviousPeriod;", + "\n return InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", + "\n ? interDataNodeParameters[targetPeriod].FirstOrDefault(x => x.DataNode == gic || x.LinkedDataNode == gic).ReinsuranceCoverage", + "\n : (double)ApplicationMessage.Log(Error.ReinsuranceCoverage, id.DataNode);", + "\n }", + "\n ", + "\n // Import Scope", + "\n public bool IsPrimaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Primary].Contains(dataNode);", + "\n public bool IsSecondaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Secondary].Contains(dataNode);", + "\n ", + "\n // Other", + "\n public IEnumerable GetNonAttributableAmountType() => new string[]{AmountTypes.NE};", + "\n public IEnumerable GetAttributableExpenseAndCommissionAmountType() => hierarchyCache.Get(AmountTypes.ACA).Descendants(includeSelf : true).Select(x => x.SystemName)", + "\n .Concat(hierarchyCache.Get(AmountTypes.AEA).Descendants(includeSelf : true).Select(x => x.SystemName));", + "\n public IEnumerable GetInvestmentClaims() => hierarchyCache.Get(AmountTypes.ICO).Descendants(includeSelf : true).Select(x => x.SystemName);", + "\n public IEnumerable GetPremiums() => hierarchyCache.Get(AmountTypes.PR).Descendants(includeSelf : true).Select(x => x.SystemName);", + "\n public IEnumerable GetClaims() => hierarchyCache.Get(AmountTypes.CL).Descendants().Select(x => x.SystemName);", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "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, @@ -150,7 +493,6 @@ "\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", @@ -192,7 +534,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." ], @@ -240,9 +582,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, @@ -251,28 +593,30 @@ { "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},", + "\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},", + "\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);", @@ -294,9 +638,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, @@ -305,30 +649,28 @@ { "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},", + "\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},", + "\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);", @@ -350,7 +692,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." ], @@ -414,7 +756,7 @@ { "cell_type": "markdown", "source": [ - "## E", + "## Actuals Reimport with Primary Secondary Scope", "\n", "\nThere is a previous year for Primary Scope (GRIC10) ", "\n", @@ -491,7 +833,68 @@ "source": [ "## Openings Reimport", "\n", - "\nccc" + "\nThere are openings for Primary Scope (GIC10) and for Secondary Scope (GRIC10). ", + "\n", + "\nThe Openings for the Secondary Scope are re-imported and the Primary Scope 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.AA};", + "\n", + "\nvar inputDataSetForDataSource = 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 inputDataSetForWorkspace = 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 CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Opening, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\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, @@ -610,7 +1013,7 @@ { "cell_type": "markdown", "source": [ - "## Openings Actual 1", + "## 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." ], @@ -661,7 +1064,7 @@ { "cell_type": "markdown", "source": [ - "## Openings Actual 2", + "## Scenario Actuals Import 2", "\n", "\nImport of Scenario Actuals where DataSource contains openings for scenario and best estimate. Data Node is at inception year." ], @@ -722,7 +1125,7 @@ { "cell_type": "markdown", "source": [ - "## Openings Actual 3", + "## 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." ], @@ -787,8 +1190,8 @@ "// Restore workspace", "\nawait 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}});" + "\nawait DataSource.UpdateAsync(new[]{ dt11State, dtr11State });", + "\nawait Workspace.UpdateAsync(new[]{ dt11State, dtr11State });" ], "metadata": {}, "execution_count": 0, @@ -797,9 +1200,9 @@ { "cell_type": "markdown", "source": [ - "## Openings Cashflow 1", + "## Scenario CF Import 1", "\n", - "\naaa" + "\nImport of a CF Scenario1 having (ifrsVar incl Opening) BE and Scenario2 in the DataSource." ], "metadata": {}, "execution_count": 0, @@ -808,7 +1211,26 @@ { "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};", + "\nvar 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 {Value = 150.0},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP2.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\nvar inputDataSetForWorkspace = new RawVariable[]{", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {Value = 150.5},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5},", + "\n};", + "\n", + "\n//var activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Cashflow, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\n//activity" ], "metadata": {}, "execution_count": 0, @@ -817,9 +1239,9 @@ { "cell_type": "markdown", "source": [ - "## Openings Cashflow 2", + "## Scenario CF Import 2", "\n", - "\nbbb" + "\nImport of a CF Scenario1 having (ifrsVar incl Opening) BE and Scenario1 in the DataSource." ], "metadata": {}, "execution_count": 0, @@ -828,7 +1250,27 @@ { "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};", + "\nvar 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 {Value = 150.0},", + "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\nvar inputDataSetForWorkspace = new RawVariable[]{", + "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", + "\n};", + "\n", + "\nvar ivsBenchmark = new IfrsVariable[]{", + "\n basicIfrsVariable with {Value = 150.5},", + "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\n};", + "\n", + "\n//var activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Cashflow, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\n//activity" ], "metadata": {}, "execution_count": 0, @@ -978,7 +1420,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();", @@ -1090,7 +1532,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();", @@ -1175,7 +1617,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 afed3dcc..0d13a9da 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 scenarioMortalityUp2 = \"MTUP2\";" ], "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 argsScenarioMTUP2 = new ImportArgs(reportingNode, 2021, 3, Periodicity.Quarterly, scenarioMortalityUp2, ImportFormats.Actual);", + "\nvar previousScenarioArgsMTUP2 = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioMortalityUp2, 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 partitionScenarioMTUP2 = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsScenarioMTUP)),", + "\n ReportingNode = reportingNode, ", + "\n Scenario = scenarioMortalityUp2, ", + "\n Year = args.Year,", + "\n Month = args.Month };", + "\nvar previousPeriodPartitionScenarioMTUP2 = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(previousScenarioArgsMTUP)),", + "\n ReportingNode = reportingNode, ", + "\n Scenario = scenarioMortalityUp2, ", + "\n Year = previousScenarioArgsMTUP2.Year,", + "\n Month = previousScenarioArgsMTUP2.Month };" ], "metadata": {}, "execution_count": 0, From b0977aeddc8fb13915d6af3bead454d31eafedca Mon Sep 17 00:00:00 2001 From: Andrea Muolo Date: Mon, 24 Apr 2023 16:02:12 +0200 Subject: [PATCH 5/5] resolve all comments --- ifrs17/Import/ImportStorage.ipynb | 6 +- ifrs17/Test/ImportStorageTest.ipynb | 685 ++++++++++------------------ ifrs17/Test/TestData.ipynb | 20 +- 3 files changed, 243 insertions(+), 468 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 67a64790..c506b1a3 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -234,8 +234,8 @@ "\n var allImportScopesNotAtInceptionYear = allImportScopes.Except(allImportScopesAtInceptionYear).ToHashSet();", "\n", "\n if(allImportScopesAtInceptionYear.Any()) {", - "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", - "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => secondaryScope.Contains(dn));", + "\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)", @@ -282,7 +282,7 @@ "\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/Test/ImportStorageTest.ipynb b/ifrs17/Test/ImportStorageTest.ipynb index 402e3945..960b5c26 100644 --- a/ifrs17/Test/ImportStorageTest.ipynb +++ b/ifrs17/Test/ImportStorageTest.ipynb @@ -44,348 +44,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "static HashSet myimportscopesatinception;", - "\nstatic HashSet myimportscopesnotatinception;", - "\nstatic HashSet myprimaryscope;", - "\nstatic HashSet mysecondaryscope;", - "\nstatic HashSet myprimaryscopefromparsed;", - "\nstatic HashSet myprimaryscopefromlinked;", - "\n", - "\npublic class ImportStorage", - "\n{", - "\n private readonly IDataSource querySource; ", - "\n private readonly IWorkspace workspace;", - "\n private readonly Systemorph.Vertex.Hierarchies.IHierarchicalDimensionCache hierarchyCache;", - "\n private readonly ImportArgs args;", - "\n ", - "\n // Constants", - "\n private static int periodicityInMonths => 3; // Revisit", - "\n ", - "\n //Format", - "\n public string ImportFormat => args.ImportFormat; ", - "\n ", - "\n //Time Periods ", - "\n public (int Year, int Month) CurrentReportingPeriod => (args.Year, args.Month);", - "\n public (int Year, int Month) PreviousReportingPeriod => (args.Year - 1, MonthInAYear); // YTD Logic", - "\n", - "\n //Partitions", - "\n public Guid PartitionByRn;", - "\n public Guid TargetPartition;", - "\n public Guid DefaultPartition;", - "\n public Guid PreviousPeriodPartition; ", - "\n", - "\n //Projections", - "\n private ProjectionConfiguration[] ProjectionConfiguration;", - "\n ", - "\n //DataNodes", - "\n public IDictionary DataNodeDataBySystemName { get; private set; }", - "\n public IDictionary> DataNodesByImportScope { get; private set; }", - "\n public IDictionary> AccidentYearsByDataNode { get; private set; }", - "\n //Variables", - "\n public IDictionary> RawVariablesByImportIdentity { get; private set; }", - "\n public IDictionary> IfrsVariablesByImportIdentity { get; private set; }", - "\n ", - "\n //Parameters", - "\n public Dictionary LockedInYieldCurve { get; private set; }", - "\n public Dictionary> CurrentYieldCurve { get; private set; }", - "\n public Dictionary> PartnerRating { get; private set; }", - "\n public Dictionary> CreditDefaultRates { get; private set; }", - "\n public Dictionary> SingleDataNodeParametersByGoc { get; private set; }", - "\n public Dictionary>> InterDataNodeParametersByGoc { get; private set; }", - "\n public Dictionary AocConfigurationByAocStep { get; private set; }", - "\n ", - "\n private Dictionary> aocStepByInputSource;", - "\n ", - "\n //Dimensions", - "\n public Dictionary AmountTypeDimension { get; private set; }", - "\n public Dictionary NoveltyDimension { get; private set; }", - "\n public Dictionary EstimateTypeDimension { get; private set; }", - "\n public Dictionary> EstimateTypesByImportFormat { get; private set; }", - "\n public Dictionary ExperienceAdjustEstimateTypeMapping { get; private set; } ", - "\n public HashSet ImportActualEstimateTypes => GetImportActualEstimateType();", - "\n", - "\n //Constructor", - "\n public ImportStorage(ImportArgs args, IDataSource querySource, IWorkspace workspace)", - "\n {", - "\n this.querySource = querySource;", - "\n this.workspace = workspace;", - "\n hierarchyCache = workspace.ToHierarchicalDimensionCache();", - "\n this.args = args;", - "\n }", - "\n ", - "\n //Initialize", - "\n public async Task InitializeAsync()", - "\n { ", - "\n //Dimensions", - "\n var estimateTypes = await workspace.Query().ToArrayAsync();", - "\n ", - "\n EstimateTypeDimension = estimateTypes.ToDictionary(x => x.SystemName);", - "\n AmountTypeDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", - "\n NoveltyDimension = (await workspace.Query().ToArrayAsync()).ToDictionary(x => x.SystemName);", - "\n ", - "\n ExperienceAdjustEstimateTypeMapping = new Dictionary{{EstimateTypes.A, EstimateTypes.APA}}; //TODO move this logic", - "\n ", - "\n //Hierarchy Cache", - "\n await hierarchyCache.InitializeAsync();", - "\n ", - "\n //EstimateType to load and to update", - "\n EstimateTypesByImportFormat = new InputSource[] { InputSource.Opening, InputSource.Actual, InputSource.Cashflow }", - "\n .ToDictionary(x => x.ToString(), ", - "\n x => estimateTypes", - "\n .Where(et => et.InputSource.Contains(x))", - "\n .Select(et => et.SystemName)", - "\n .ToHashSet());", - "\n ", - "\n //ProjectionConfiguration : Current Period + projection for every Quarter End for current Year and next Years as in projectionConfiguration.csv", - "\n ProjectionConfiguration = (await workspace.Query()", - "\n .Where(x => x.Shift > 0 || x.TimeStep == args.Month || (x.TimeStep > args.Month && x.TimeStep % periodicityInMonths == 0))", - "\n .OrderBy(x => x.Shift).ThenBy(x => x.TimeStep).ToArrayAsync());", - "\n ", - "\n //Get Partitions", - "\n PartitionByRn = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode).ToArrayAsync()).Single().Id;", - "\n TargetPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", - "\n p.Year == CurrentReportingPeriod.Year &&", - "\n p.Month == CurrentReportingPeriod.Month &&", - "\n p.Scenario == args.Scenario).ToArrayAsync()).Single().Id;", - "\n DefaultPartition = (await querySource.Query().Where(p => p.ReportingNode == args.ReportingNode &&", - "\n p.Year == CurrentReportingPeriod.Year &&", - "\n p.Month == CurrentReportingPeriod.Month &&", - "\n p.Scenario == null).ToArrayAsync()).Single().Id;", - "\n //Set Partitions", - "\n await querySource.Partition.SetAsync(PartitionByRn);", - "\n await workspace.Partition.SetAsync(PartitionByRn);", - "\n ", - "\n await querySource.Partition.SetAsync(TargetPartition);", - "\n await workspace.Partition.SetAsync(TargetPartition);", - "\n ", - "\n //Get data from Workspace (result of parsing)", - "\n var parsedRawVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", - "\n var parsedIfrsVariables = await workspace.QueryPartitionedDataAsync(querySource, TargetPartition, DefaultPartition, ImportFormat);", - "\n ", - "\n //DataNodes", - "\n DataNodeDataBySystemName = await workspace.LoadDataNodesAsync(args);", - "\n ", - "\n //Accident Years", - "\n AccidentYearsByDataNode = (IDictionary>)", - "\n (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => new {x.DataNode, x.AccidentYear}) : parsedIfrsVariables.Select(x => new {x.DataNode, x.AccidentYear}))", - "\n .ToDictionaryGrouped(x => x.DataNode, x => (ICollection)x.Select(y => y.AccidentYear).ToHashSet());", - "\n ", - "\n // Import Scopes and Data Node relationship parameters", - "\n InterDataNodeParametersByGoc = await workspace.LoadInterDataNodeParametersAsync(args);", - "\n ", - "\n var primaryScopeFromParsedVariables = (ImportFormat == ImportFormats.Cashflow ? parsedRawVariables.Select(x => x.DataNode) : parsedIfrsVariables.Select(x => x.DataNode)).ToHashSet();", - "\n var primaryScopeFromLinkedReinsurance = primaryScopeFromParsedVariables", - "\n .Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance && DataNodeDataBySystemName[goc].LiabilityType == LiabilityTypes.LRC)", - "\n .SelectMany(goc => InterDataNodeParametersByGoc.TryGetValue(goc, out var interDataNodeParamByPeriod)", - "\n ? interDataNodeParamByPeriod[CurrentPeriod].Select(param => param.DataNode == goc ? param.LinkedDataNode : param.DataNode).Where(goc => !primaryScopeFromParsedVariables.Contains(goc))", - "\n : Enumerable.Empty())", - "\n .ToHashSet();", - "\n", - "\n var primaryScope = primaryScopeFromParsedVariables.Concat(primaryScopeFromLinkedReinsurance).ToHashSet();", - "\n var secondaryScope = InterDataNodeParametersByGoc", - "\n .Where(kvp => primaryScope.Contains(kvp.Key))", - "\n .SelectMany(kvp => { var linkedGocs = kvp.Value[CurrentPeriod].Select(param => param.DataNode == kvp.Key ? param.LinkedDataNode : param.DataNode);", - "\n return linkedGocs.Where(goc => !primaryScope.Contains(goc));}).ToHashSet();", - "\n var allImportScopes = new HashSet(primaryScope.Concat(secondaryScope));", - "\n ", - "\n DataNodesByImportScope = new Dictionary> { { ImportScope.Primary, primaryScope }, { ImportScope.Secondary, secondaryScope } };", - "\n ", - "\n // Parameters", - "\n PartnerRating = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner);", - "\n CreditDefaultRates = await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating);", - "\n SingleDataNodeParametersByGoc = await workspace.LoadSingleDataNodeParametersAsync(args);", - "\n LockedInYieldCurve = await workspace.LoadLockedInYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn]));", - "\n CurrentYieldCurve = await workspace.LoadCurrentYieldCurveAsync(args, allImportScopes.Select(dn => DataNodeDataBySystemName[dn])); //TODO Rename this variable", - "\n ", - "\n AocConfigurationByAocStep = await querySource.LoadAocStepConfigurationAsDictionaryAsync(args.Year, args.Month); ", - "\n aocStepByInputSource = ((InputSource[])Enum.GetValues(typeof(InputSource))).ToDictionary(x => x,", - "\n x => AocConfigurationByAocStep", - "\n .Where(kvp => kvp.Value.InputSource.Contains(x))", - "\n .Select(kvp => kvp.Key)", - "\n .ToHashSet());", - "\n ", - "\n //Previous Period", - "\n var openingRawVariables = Enumerable.Empty();", - "\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).ToHashSet();", - "\nmyimportscopesatinception=allImportScopesAtInceptionYear;", - "\nmyimportscopesnotatinception=allImportScopesNotAtInceptionYear;", - "\nmyprimaryscope = primaryScope;", - "\nmysecondaryscope = secondaryScope;", - "\nmyprimaryscopefromparsed = primaryScopeFromParsedVariables;", - "\nmyprimaryscopefromlinked = primaryScopeFromLinkedReinsurance;", - "\n if(allImportScopesAtInceptionYear.Any()) {", - "\n var primaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(dn => primaryScope.Contains(dn));", - "\n var secondaryScopeAtInceptionYear = allImportScopesAtInceptionYear.Where(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()", - "\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)).ToArrayAsync())", - "\n .Select(rv => rv with {AocType = AocTypes.BOP, Novelty = Novelties.I, ", - "\n Values = rv.Values.Skip(MonthInAYear).ToArray(), Partition = TargetPartition});", - "\n ", - "\n openingIfrsVariables = openingIfrsVariables.Union((await querySource.Query()", - "\n .Where(iv => iv.Partition == PreviousPeriodPartition && iv.AocType == AocTypes.EOP)", - "\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 //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.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", - "\n if(DefaultPartition != TargetPartition) {", - "\n await querySource.Partition.SetAsync(DefaultPartition);", - "\n var defaultRawVariables = await querySource.Query().Where(rv => rv.Partition == DefaultPartition && primaryScope.Contains(rv.DataNode)).ToArrayAsync();", - "\n var defaultIfrsVariables = await querySource.Query().Where(iv => iv.Partition == DefaultPartition && allImportScopes.Contains(iv.DataNode)).ToArrayAsync(); ", - "\n rawVariables = rawVariables.Union(defaultRawVariables, EqualityComparer.Instance);", - "\n ifrsVariables = ifrsVariables.Union(defaultIfrsVariables, EqualityComparer.Instance);", - "\n await querySource.Partition.SetAsync(TargetPartition);", - "\n }", - "\n", - "\n RawVariablesByImportIdentity = (IDictionary>)rawVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", - "\n IfrsVariablesByImportIdentity = (IDictionary>)ifrsVariables.ToDictionaryGrouped(v => v.DataNode, v => (ICollection)v.ToArray());", - "\n }", - "\n ", - "\n //Getters", - "\n ", - "\n //Periods", - "\n public ValuationPeriod GetValuationPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].ValuationPeriod;", - "\n public PeriodType GetYieldCurvePeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].YcPeriod;", - "\n public PeriodType GetCreditDefaultRiskPeriod(ImportIdentity id) => AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].CdrPeriod;", - "\n ", - "\n public IEnumerable GetAllAocSteps(InputSource source) => aocStepByInputSource[source];", - "\n public IEnumerable GetCalculatedTelescopicAocSteps() => AocConfigurationByAocStep.Where(kvp => kvp.Value.DataType == DataType.CalculatedTelescopic).Select(kvp => kvp.Key);", - "\n", - "\n //YieldCurve", - "\n public double[] GetYearlyYieldCurve(ImportIdentity id, string economicBasis) {", - "\n var yc = GetYieldCurve(id, economicBasis);", - "\n return yc.Values.Skip(args.Year - yc.Year).ToArray(); //Check if the returned array is empty? Log Warning?", - "\n }", - "\n ", - "\n public YieldCurve GetYieldCurve(ImportIdentity id, string economicBasis) => (economicBasis, GetYieldCurvePeriod(id)) switch {", - "\n (EconomicBases.C, PeriodType.BeginningOfPeriod ) => GetShift(id.ProjectionPeriod) > 0 ", - "\n ? CurrentYieldCurve[id.DataNode][CurrentPeriod]", - "\n : CurrentYieldCurve[id.DataNode][PreviousPeriod],", - "\n (EconomicBases.C, PeriodType.EndOfPeriod) => CurrentYieldCurve[id.DataNode][CurrentPeriod], ", - "\n (EconomicBases.L, _ ) => LockedInYieldCurve[id.DataNode],", - "\n (_, PeriodType.NotApplicable) => (YieldCurve)ApplicationMessage.Log(Error.YieldCurvePeriodNotApplicable, id.AocType, id.Novelty),", - "\n (_, _) => (YieldCurve)ApplicationMessage.Log(Error.EconomicBasisNotFound, id.DataNode)", - "\n };", - "\n", - "\n //int Identity.ProjectionPeriod ", - "\n public int GetProjectionCount() => ProjectionConfiguration.Count();", - "\n public int GetShift(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].Shift;", - "\n public int GetTimeStep(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].TimeStep;", - "\n ", - "\n public PeriodType GetPeriodType(string amountType, string estimateType) => ", - "\n amountType != null && AmountTypeDimension.TryGetValue(amountType, out var at) ", - "\n ? at.PeriodType", - "\n : estimateType != null && EstimateTypeDimension.TryGetValue(estimateType, out var ct) ", - "\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 ", - "\n public double[] GetValues(ImportIdentity id, Func whereClause) => GetRawVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Values ?? Enumerable.Empty().ToArray();", - "\n public double GetValue(ImportIdentity id, Func whereClause) => GetIfrsVariables(id.DataNode).Where(v => (v.AocType, v.Novelty) == id.AocStep && whereClause(v)).Aggregate()?.Value ?? 0;", - "\n public double[] GetValues(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValues(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", - "\n", - "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType);", - "\n public double GetValue(ImportIdentity id, string amountType, string estimateType, string economicBasis, int? accidentYear) => GetValue(id, v => v.AccidentYear == accidentYear && v.AmountType == amountType && v.EstimateType == estimateType && v.EconomicBasis == economicBasis);", - "\n ", - "\n //Novelty", - "\n private IEnumerable GetNoveltiesForAocType(string aocType, IEnumerable aocConfiguration) => aocConfiguration.Where(aocStep => aocStep.AocType == aocType).Select(aocStep => aocStep.Novelty);", - "\n public IEnumerable GetNovelties() => NoveltyDimension.Keys;", - "\n public IEnumerable GetNovelties(string aocType) => GetNoveltiesForAocType(aocType, AocConfigurationByAocStep.Keys);", - "\n public IEnumerable GetNovelties(string aocType, InputSource inputSource) => GetNoveltiesForAocType(aocType, aocStepByInputSource[inputSource]);", - "\n ", - "\n //Accident years", - "\n public IEnumerable GetAccidentYears(string dataNode) => AccidentYearsByDataNode.TryGetValue(dataNode, out var accidentYear) ? accidentYear : new int?[] { null };", - "\n ", - "\n // Parameters", - "\n public double GetNonPerformanceRiskRate (ImportIdentity identity) {", - "\n var period = GetCreditDefaultRiskPeriod(identity) == PeriodType.BeginningOfPeriod ? PreviousPeriod : CurrentPeriod;", - "\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 Partner == Internal then return 0;", - "\n if(!PartnerRating.TryGetValue(dataNodeData.Partner, out var rating)) ApplicationMessage.Log(Error.RatingNotFound, dataNodeData.Partner);", - "\n if(!CreditDefaultRates.TryGetValue(rating[period].CreditRiskRating, out var rate)) ApplicationMessage.Log(Error.CreditDefaultRateNotFound, rating[period].CreditRiskRating);", - "\n return Math.Pow(1d + rate[period].Values[0], 1d / 12d) - 1d;", - "\n }", - "\n ", - "\n public double GetPremiumAllocationFactor(ImportIdentity id) => SingleDataNodeParametersByGoc.TryGetValue(id.DataNode, out var singleDataNodeParameter) ", - "\n ? singleDataNodeParameter[CurrentPeriod].PremiumAllocation : DefaultPremiumExperienceAdjustmentFactor;", - "\n ", - "\n // Data Node relationships", - "\n public IEnumerable GetUnderlyingGic(ImportIdentity id) => !InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", - "\n ? Enumerable.Empty()", - "\n : interDataNodeParameters[CurrentPeriod].Select(x => x.DataNode != id.DataNode ? x.DataNode : x.LinkedDataNode).Where(goc => !DataNodeDataBySystemName[goc].IsReinsurance);", - "\n ", - "\n public double GetReinsuranceCoverage (ImportIdentity id, string gic) ", - "\n {", - "\n var targetPeriod = AocConfigurationByAocStep[new AocStep(id.AocType, id.Novelty)].RcPeriod == PeriodType.EndOfPeriod ? CurrentPeriod : PreviousPeriod;", - "\n return InterDataNodeParametersByGoc.TryGetValue(id.DataNode, out var interDataNodeParameters)", - "\n ? interDataNodeParameters[targetPeriod].FirstOrDefault(x => x.DataNode == gic || x.LinkedDataNode == gic).ReinsuranceCoverage", - "\n : (double)ApplicationMessage.Log(Error.ReinsuranceCoverage, id.DataNode);", - "\n }", - "\n ", - "\n // Import Scope", - "\n public bool IsPrimaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Primary].Contains(dataNode);", - "\n public bool IsSecondaryScope (string dataNode) => DataNodesByImportScope[ImportScope.Secondary].Contains(dataNode);", - "\n ", - "\n // Other", - "\n public IEnumerable GetNonAttributableAmountType() => new string[]{AmountTypes.NE};", - "\n public IEnumerable GetAttributableExpenseAndCommissionAmountType() => hierarchyCache.Get(AmountTypes.ACA).Descendants(includeSelf : true).Select(x => x.SystemName)", - "\n .Concat(hierarchyCache.Get(AmountTypes.AEA).Descendants(includeSelf : true).Select(x => x.SystemName));", - "\n public IEnumerable GetInvestmentClaims() => hierarchyCache.Get(AmountTypes.ICO).Descendants(includeSelf : true).Select(x => x.SystemName);", - "\n public IEnumerable GetPremiums() => hierarchyCache.Get(AmountTypes.PR).Descendants(includeSelf : true).Select(x => x.SystemName);", - "\n public IEnumerable GetClaims() => hierarchyCache.Get(AmountTypes.CL).Descendants().Select(x => x.SystemName);", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ @@ -479,39 +137,39 @@ { "cell_type": "code", "source": [ - "static IfrsVariable[] mya;", - "\nstatic IfrsVariable[] myb;", - "\nstatic ImportStorage mystorage;", - "\n", - "\npublic 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 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()+\" Value: \"+x.Value.ToString()).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()+\" Value: \"+x.Value.ToString()).ToArray();", + "\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 mya = ivs.Except(ivsBenchmark).ToArray();", - "\n myb = ivsBenchmark.Except(ivs).ToArray();", - "\n mystorage = testStorage;", - "\n //find duplicates in storage", - "\n var ivsByIdentityString = ivs.GroupBy(x => x.ToIdentityString()).Where(x => x.Count() > 1).Select(x => x.Key);", + "\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));", @@ -522,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": [ @@ -547,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 };", @@ -563,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": {}, @@ -595,7 +281,7 @@ "source": [ "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[]{", + "\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},", @@ -604,7 +290,7 @@ "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 5000.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\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 };", @@ -619,7 +305,7 @@ "\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": {}, @@ -651,7 +337,7 @@ "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 basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, EstimateType = EstimateTypes.DA, Value = 1000.0},", @@ -661,7 +347,7 @@ "\n basicIfrsVariable with {AocType = AocTypes.EOP, Value = 450.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\nvar inputForWorkspace = new IfrsVariable[]{", "\n basicIfrsVariable with {AocType = AocTypes.CF, Value = -15.0},", "\n basicIfrsVariable with {AocType = AocTypes.WO, Value = -20.0},", "\n };", @@ -673,7 +359,7 @@ "\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": {}, @@ -706,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},", @@ -721,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 };", @@ -737,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": {}, @@ -773,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},", @@ -787,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 };", @@ -812,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": {}, @@ -831,11 +517,11 @@ { "cell_type": "markdown", "source": [ - "## Openings Reimport", + "## Openings Reimport for Gross", "\n", - "\nThere are openings for Primary Scope (GIC10) and for Secondary Scope (GRIC10). ", + "\nThere are openings for GIC and for the correlated GRIC. ", "\n", - "\nThe Openings for the Secondary Scope are re-imported and the Primary Scope must be loaded in the storage. Both are at inception year." + "\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, @@ -856,14 +542,86 @@ { "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, Novelty = Novelties.I, Value = 90.0},", "\n basicIfrsVariable with {DataNode = groupOfReinsuranceContracts, AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.0},", "\n };", "\n", - "\nvar inputDataSetForWorkspace = new IfrsVariable[]{", + "\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", @@ -871,7 +629,7 @@ "\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 CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Opening, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, args);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, args with {ImportFormat = ImportFormats.Opening});", "\nactivity" ], "metadata": {}, @@ -923,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": {}, @@ -973,28 +731,28 @@ { "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 CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -1024,28 +782,28 @@ { "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.CL, Value = 150.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 inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\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.CL, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.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": {}, @@ -1087,26 +845,26 @@ { "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[]{", - "\n basicIfrsVariable with {AocType = AocTypes.CL, Value = 150.0},", + "\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 inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\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 = 90.7}, ", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\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 CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Actual, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", + "\nvar activity = await CheckIfrsVariableImportStorageAsync(inputForWorkspace, inputForDataSource, ivsBenchmark, argsScenarioMTUP with {ImportFormat = ImportFormats.Actual});", "\nactivity" ], "metadata": {}, @@ -1148,27 +906,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[]{", - "\n basicIfrsVariable with {AocType = AocTypes.CL, Value = 150.0},", + "\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 inputDataSetForWorkspace = new IfrsVariable[]{", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Value = -15.0},", + "\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.CL, Value = -15.0},", + "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CF, Value = -15.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": {}, @@ -1202,7 +960,7 @@ "source": [ "## Scenario CF Import 1", "\n", - "\nImport of a CF Scenario1 having (ifrsVar incl Opening) BE and Scenario2 in the DataSource." + "\nImport of a CF Scenario1 having BE and Scenario2 in the DataSource." ], "metadata": {}, "execution_count": 0, @@ -1212,25 +970,33 @@ "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};", - "\nvar 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 {Value = 150.0},", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP2.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\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 inputDataSetForWorkspace = new RawVariable[]{", + "\nvar inputForWorkspace = new RawVariable[]{", "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", "\n};", "\n", - "\nvar ivsBenchmark = new IfrsVariable[]{", - "\n basicIfrsVariable with {Value = 150.5},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5},", + "\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", - "\n//var activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Cashflow, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", - "\n//activity" + "\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, @@ -1251,26 +1017,35 @@ "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};", - "\nvar 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 {Value = 150.0},", - "\n basicIfrsVariable with {Partition = previousPeriodPartition.Id, AocType = AocTypes.EOP, Novelty = Novelties.C, Value = 89.5},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\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 inputDataSetForWorkspace = new RawVariable[]{", + "\nvar inputForWorkspace = new RawVariable[]{", "\n basicRawVariable with {Partition = partitionScenarioMTUP.Id, Values = new[]{110.0}},", "\n};", "\n", - "\nvar ivsBenchmark = new IfrsVariable[]{", - "\n basicIfrsVariable with {Value = 150.5},", - "\n basicIfrsVariable with {AocType = AocTypes.BOP, Novelty = Novelties.I, Value = 89.5},", - "\n basicIfrsVariable with {Partition = partitionScenarioMTUP.Id, AocType = AocTypes.CL, Novelty = Novelties.C, Value = 89.1}", + "\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", - "\n//var activity = await CheckIfrsVariablesFromImportStorageAsync(ImportFormats.Cashflow, inputDataSetForWorkspace, inputDataSetForDataSource, ivsBenchmark, argsScenarioMTUP);", - "\n//activity" + "\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, diff --git a/ifrs17/Test/TestData.ipynb b/ifrs17/Test/TestData.ipynb index 0d13a9da..10f8a38c 100644 --- a/ifrs17/Test/TestData.ipynb +++ b/ifrs17/Test/TestData.ipynb @@ -224,7 +224,7 @@ "\nvar reportingNode = \"CH\";", "\nvar scenarioBestEstimate = (string)null;", "\nvar scenarioMortalityUp = \"MTUP\";", - "\nvar scenarioMortalityUp2 = \"MTUP2\";" + "\nvar scenarioMortalityDown = \"MTDOWN\";" ], "metadata": {}, "execution_count": 0, @@ -237,8 +237,8 @@ "\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 argsScenarioMTUP2 = new ImportArgs(reportingNode, 2021, 3, Periodicity.Quarterly, scenarioMortalityUp2, ImportFormats.Actual);", - "\nvar previousScenarioArgsMTUP2 = new ImportArgs(reportingNode, 2020, 12, Periodicity.Quarterly, scenarioMortalityUp2, 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, @@ -286,16 +286,16 @@ "\n Scenario = scenarioMortalityUp, ", "\n Year = previousScenarioArgsMTUP.Year,", "\n Month = previousScenarioArgsMTUP.Month };", - "\nvar partitionScenarioMTUP2 = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsScenarioMTUP)),", + "\nvar partitionScenarioMTDOWN = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(argsScenarioMTUP)),", "\n ReportingNode = reportingNode, ", - "\n Scenario = scenarioMortalityUp2, ", + "\n Scenario = scenarioMortalityDown, ", "\n Year = args.Year,", "\n Month = args.Month };", - "\nvar previousPeriodPartitionScenarioMTUP2 = new PartitionByReportingNodeAndPeriod { Id = (Guid)(await DataSource.Partition.GetKeyForInstanceAsync(previousScenarioArgsMTUP)),", - "\n ReportingNode = reportingNode, ", - "\n Scenario = scenarioMortalityUp2, ", - "\n Year = previousScenarioArgsMTUP2.Year,", - "\n Month = previousScenarioArgsMTUP2.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,