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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions full-ifrs17-template/Constants/Consts.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"metadata": {
"authors": [],
"kernelspec": {
"display_name": "Formula Framework",
"language": "C#",
"name": "C#"
},
"language_info": {
"file_extension": ".cs",
"mimetype": "text/plain",
"name": "C#"
}
},
"nbformat": 4,
"nbformat_minor": 5,
"cells": [
{
"cell_type": "code",
"source": [
"var projectName = \"ifrs17ce\";",
"\nvar environmentName = \"dev\";",
"\nvar notebookName = \"CalculationEngine\";",
"\nvar calculationEngine = $\"#!import \\\"//{projectName}/{environmentName}/{notebookName}\\\"\";"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
{
"cell_type": "code",
"source": [
"#!import \"//ifrs17ce/dev/CalculationEngine\""
"#!import \"../Constants/Consts\"",
"\n#!eval calculationEngine"
]
},
{
Expand Down Expand Up @@ -77,7 +78,6 @@
"\n .WithType<AocType>()",
"\n .WithType<PnlVariableType>()",
"\n .WithType<BsVariableType>()",
"\n .WithType<AocConfiguration>()",
"\n .WithType<PvAmountType>()",
"\n .WithType<DeferrableAmountType>()",
"\n .WithType<RiskDriver>()",
Expand All @@ -97,6 +97,12 @@
"\n .ExecuteAsync()"
]
},
{
"cell_type": "code",
"source": [
"await Import.FromFile(\"../Files/DimensionsAndPartitions.csv\").WithFormat(\"AocConfiguration\").WithTarget(DataSource).ExecuteAsync()"
]
},
{
"cell_type": "code",
"source": [
Expand Down
6 changes: 0 additions & 6 deletions full-ifrs17-template/Test/Tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
"#!eval-notebook \"ReportStorageTest\""
]
},
{
"cell_type": "code",
"source": [
"#!eval-notebook \"QueriesTest\""
]
},
{
"cell_type": "code",
"source": [
Expand Down
3 changes: 3 additions & 0 deletions ifrs17/Constants/Consts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@
"public static class AocTypes{",
"\n public const string BOP = nameof(BOP);",
"\n public const string MC = nameof(MC);",
"\n public const string PC = nameof(PC);",
"\n public const string RCU = nameof(RCU);",
"\n public const string CF = nameof(CF);",
"\n public const string IA = nameof(IA);",
"\n public const string AU = nameof(AU);",
"\n public const string FAU = nameof(FAU);",
"\n public const string YCU = nameof(YCU);",
"\n public const string CRU = nameof(CRU);",
"\n public const string WO = nameof(WO);",
Expand Down
6 changes: 5 additions & 1 deletion ifrs17/Constants/Validations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"source": [
"public enum Error { ",
"\n // Import",
"\n NoMainTab, IncompleteMainTab, ParsingScientificNotation, ValueTypeNotFound, ValueTypeNotValid, AocTypeNotValid,",
"\n NoMainTab, IncompleteMainTab, ParsingScientificNotation, ValueTypeNotFound, ValueTypeNotValid, ",
"\n AocTypeNotValid, AocTypeCompulsoryNotFound, AocTypePositionNotSupported, AocConfigurationOrderNotUnique,",
"\n // Partition",
"\n PartitionNotFound, ParsedPartitionNotFound, PartititionNameNotFound, PartitionTypeNotFound,",
"\n // Dimensions",
Expand Down Expand Up @@ -95,6 +96,9 @@
"\n (Error.ValueTypeNotFound , _) => $\"Value Type not found.\",",
"\n (Error.ValueTypeNotValid , 1) => $\"The Value Type {s[0]} is invalid.\",",
"\n (Error.AocTypeNotValid , 1) => $\"The parsed AocType {s[0]} is invalid.\",",
"\n (Error.AocTypeCompulsoryNotFound , _) => $\"Not all compulsory AocTypes have been imported.\",",
"\n (Error.AocTypePositionNotSupported , 1) => $\"The position of the AocType {s[0]} is not supported.\",",
"\n (Error.AocConfigurationOrderNotUnique , _) => $\"Two or more Aoc Configurations have the same Order.\",",
"\n // Partition",
"\n (Error.PartitionNotFound , _) => $\"Partition do not found.\",",
"\n (Error.ParsedPartitionNotFound , 1) => $\"Parsed partition not available: ReportingNode {s[0]}.\",",
Expand Down
111 changes: 106 additions & 5 deletions ifrs17/Import/Importers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,20 @@
{
"cell_type": "code",
"source": [
"public async Task DataNodeFactoryAsync (string file, string tab, ImportArgs args)",
"public async Task DataNodeFactoryAsync(string file, string tab, ImportArgs args)",
"\n{",
"\n var partition = (await DataSource.Query<PartitionByReportingNode>().Where(p => p.ReportingNode == args.ReportingNode && p.Scenario == null).ToArrayAsync()).SingleOrDefault();",
"\n if(partition == null) { ApplicationMessage.Log(Error.ParsedPartitionNotFound); return; }",
"\n",
"\n var extension = System.IO.Path.GetExtension(file);",
"\n var stream = await Project.FileStorage.ReadAsync(file);",
"\n var target = (await DataSetReader.ReadFromStream(stream).WithContentType(extension).ExecuteAsync()).DataSet.Tables[tab];",
"\n ",
"\n",
"\n var dataNodesImported = target.Rows.Select(x => x.Field<string>(nameof(RawVariable.DataNode))).ToHashSet();",
"\n var dataNodesDefined = await DataSource.Query<GroupOfContract>().Where(x => dataNodesImported.Contains(x.SystemName)).ToArrayAsync();",
"\n var dataNodeStatesDefined = await DataSource.Query<DataNodeState>().Select(x => x.DataNode).ToArrayAsync();",
"\n var dataNodeParametersDefined = await DataSource.Query<SingleDataNodeParameter>().Select(x => x.DataNode).ToArrayAsync(); ",
"\n ",
"\n",
"\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Contains(x)).ToHashSet();",
"\n var dataNodeSingleParametersUndefined = dataNodesImported.Where(x => x != null &&",
"\n !dataNodeParametersDefined.Contains(x) && ",
Expand All @@ -291,7 +290,7 @@
"\n",
"\n await DataSource.UpdateAsync( dataNodeSingleParametersUndefined.Select(x => ",
"\n new SingleDataNodeParameter {DataNode = x, Year = args.Year, Month = DefaultDataNodeActivationMonth, PremiumAllocation = DefaultPremiumExperienceAdjustmentFactor, Partition = partition.Id}).ToArray() );",
"\n ",
"\n",
"\n await DataSource.CommitAsync();",
"\n}"
]
Expand Down Expand Up @@ -319,6 +318,109 @@
"\n}"
]
},
{
"cell_type": "markdown",
"source": [
"### Analysis of Change Configuration"
]
},
{
"cell_type": "markdown",
"source": [
"The Analysis of Change configuration is parsed from the input file and complemented with defaults to allow for an easy insertion of new AOC steps. ",
"\n",
"\nAfter having checked that the AocTypes loaded in the target DataSource are including all the compulsory ones, default configurations are generated on the basis of the AocTypes ordering. ",
"\n",
"\nThe following categories have been identified based on the *Order* of the novel AOC step:",
"\n",
"\n| Category | Default added with same configuration of |",
"\n| --------------------- | ----------------------------------------------------- |",
"\n| Order < RCU | MC with Novelty I |",
"\n| RCU < Order < CF | RCU with Novelty I |",
"\n| IA < Order < YCU | AU with both Novelty I and N |",
"\n| CRU < Order < WO | EV with Novelty I and N |",
"\n| WO < Order < CL | WO with Novelty C (only for Import Source = Actual) |",
"\n",
"\nThe new Aoc Configurations are created with the same order of the Aoc Types. "
]
},
{
"cell_type": "code",
"source": [
"Import.DefineFormat(\"AocConfiguration\", async (options, dataSet) => {",
"\n Activity.Start();",
"\n var workspace = Workspace.CreateNew();",
"\n workspace.InitializeFrom(options.TargetDataSource);",
"\n",
"\n var aocTypes = await options.TargetDataSource.Query<AocType>().OrderBy(x => x.Order).ToArrayAsync();",
"\n var aocTypesCompulsory = typeof(AocTypes).GetFields().Select(x => (string)x.Name);",
"\n if(aocTypesCompulsory.Where(x => !aocTypes.Select(x => x.SystemName).Contains(x)).Any()) {",
"\n ApplicationMessage.Log(Error.AocTypeCompulsoryNotFound);",
"\n return Activity.Finish().RepeatOnce();",
"\n }",
"\n ",
"\n var logConfig = await Import.FromDataSet(dataSet).WithType<AocConfiguration>().WithTarget(workspace).ExecuteAsync();",
"\n if(logConfig.Errors.Any()) return logConfig.RepeatOnce(); ",
"\n",
"\n var orderByName = aocTypes.ToDictionary(x => x.SystemName, x => x.Order);",
"\n var aocConfigs = (await workspace.Query<AocConfiguration>().ToArrayAsync())",
Comment thread
amuolo marked this conversation as resolved.
"\n .GroupBy(x => (x.AocType, x.Novelty))",
"\n .Select(y => y.OrderByDescending(x => x.Year).ThenByDescending(x => x.Month).FirstOrDefault())",
"\n .ToDictionary(x => (x.AocType, x.Novelty));",
"\n var aocOrder = aocConfigs.ToDictionary(x => x.Key, x => x.Value.Order);",
"\n var newAocTypes = orderByName.Keys.Where(x => !aocConfigs.Keys.Contains((x, Novelties.I)) && ",
"\n !aocConfigs.Keys.Contains((x, Novelties.N)) && ",
"\n !aocConfigs.Keys.Contains((x, Novelties.C)) && ",
"\n !aocTypes.Any(y => y.Parent == x) &&",
"\n !aocTypesCompulsory.Contains(x)).ToArray();",
"\n",
"\n foreach(var newAocType in newAocTypes) {",
"\n if(orderByName[newAocType] < orderByName[AocTypes.RCU])",
"\n {",
"\n var step = (AocTypes.MC, Novelties.I);",
"\n await workspace.UpdateAsync( aocConfigs[step] with { AocType = newAocType, DataType = DataType.Optional, Order = ++aocOrder[step] }); ",
"\n }",
"\n else if(orderByName[newAocType] > orderByName[AocTypes.RCU] && orderByName[newAocType] < orderByName[AocTypes.CF]) ",
"\n {",
"\n var step = (AocTypes.RCU, Novelties.I);",
"\n await workspace.UpdateAsync( aocConfigs[step] with { AocType = newAocType, DataType = DataType.Optional, Order = ++aocOrder[step] });",
"\n }",
"\n else if(orderByName[newAocType] > orderByName[AocTypes.IA] && orderByName[newAocType] < orderByName[AocTypes.YCU]) ",
"\n {",
"\n foreach (var novelty in new[]{Novelties.I, Novelties.N}) {",
"\n var step = (AocTypes.AU, novelty);",
"\n var order = orderByName[newAocType] < orderByName[AocTypes.AU]? ++aocOrder[(AocTypes.IA, novelty)] : ++aocOrder[(AocTypes.AU, novelty)];",
"\n await workspace.UpdateAsync( aocConfigs[step] with { AocType = newAocType, DataType = DataType.Optional, Order = order } );",
"\n }",
"\n }",
"\n else if(orderByName[newAocType] > orderByName[AocTypes.CRU] && orderByName[newAocType] < orderByName[AocTypes.WO])",
"\n {",
"\n var stepI = (AocTypes.EV, Novelties.I);",
"\n var orderI = orderByName[newAocType] < orderByName[AocTypes.EV]? ++aocOrder[(AocTypes.CRU, Novelties.I)] : ++aocOrder[(AocTypes.EV, Novelties.I)];",
"\n await workspace.UpdateAsync( aocConfigs[stepI] with { AocType = newAocType, DataType = DataType.Optional, Order = orderI } );",
"\n",
"\n var stepN = (AocTypes.EV, Novelties.N);",
"\n var orderN = orderByName[newAocType] < orderByName[AocTypes.EV]? ++aocOrder[(AocTypes.AU, Novelties.N)] : ++aocOrder[(AocTypes.EV, Novelties.N)];",
"\n await workspace.UpdateAsync( aocConfigs[stepN] with { AocType = newAocType, DataType = DataType.Optional, Order = orderN } );",
"\n }",
"\n else if(orderByName[newAocType] > orderByName[AocTypes.WO] && orderByName[newAocType] < orderByName[AocTypes.CL])",
"\n {",
"\n var step = (AocTypes.WO, Novelties.C);",
"\n await workspace.UpdateAsync( aocConfigs[step] with { AocType = newAocType, DataType = DataType.Optional, Order = ++aocOrder[step] } );",
"\n }",
"\n else",
"\n ApplicationMessage.Log(Error.AocTypePositionNotSupported);",
"\n };",
"\n",
"\n var aocConfigsFinal = await workspace.Query<AocConfiguration>().ToArrayAsync();",
"\n if(aocConfigsFinal.GroupBy(x => x.Order).Any(x => x.Count() > 1))",
"\n ApplicationMessage.Log(Error.AocConfigurationOrderNotUnique);",
"\n",
"\n await workspace.CommitToTargetAsync(options.TargetDataSource);",
"\n return new[] {Activity.Finish(),logConfig}; ",
"\n});"
]
},
{
"cell_type": "markdown",
"source": [
Expand Down Expand Up @@ -492,7 +594,6 @@
"\n await CommitToDatabase<ReinsurancePortfolio>(partition);",
"\n await CommitToDatabase<GroupOfInsuranceContract>(partition);",
"\n await CommitToDatabase<GroupOfReinsuranceContract>(partition);",
"\n ",
"\n return log;",
"\n}"
]
Expand Down
Loading