From bf8aa4c8192107a4975edb0ba7e0477854afc571 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Thu, 29 Dec 2022 16:08:56 +0100 Subject: [PATCH 1/5] adding NB with some queries --- ifrs17-template/Report/ParameterReports.ipynb | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 ifrs17-template/Report/ParameterReports.ipynb diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb new file mode 100644 index 00000000..3f444f9e --- /dev/null +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -0,0 +1,208 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Data Initialization" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"../Initialization/InitSystemorphBaseToMemory\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Workspace.InitializeFrom(DataSource);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Args" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var args = new ImportArgs(\"CH\", 2021, 3, default, default , ImportFormats.Cashflow);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Node" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var dataNodeData = (await Workspace.LoadDataNodesAsync(args))", + "\n .Values", + "\n .ToArray();", + "\ndataNodeData.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "dataNodeData", + "\n" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# YieldCurve" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var lockedYieldCurves = (await Workspace.LoadLockedInYieldCurveAsync(args, dataNodeData))", + "\n .Select(x => new { ", + "\n DataNode = x.Key, ", + "\n LockedIn = (x.Value.Year, x.Value.Month, x.Value.Scenario, x.Value.Currency, x.Value.Name)", + "\n })", + "\n .ToArray();", + "\nlockedYieldCurves.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var currentYieldCurves = (await Workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => new { ", + "\n Period = y.Key,", + "\n Current = (y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.Currency, y.Value.Name)", + "\n }))", + "\n .ToArray();", + "\ncurrentYieldCurves.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Parameters" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var singleDataNodeParameters = (await Workspace.LoadSingleDataNodeParametersAsync(args))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => new { ", + "\n Period = y.Key, ", + "\n Parameter = (y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.DataNode, y.Value.PremiumAllocation)", + "\n }))", + "\n .ToArray();", + "\nsingleDataNodeParameters.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var interDataNodeParameters = (await Workspace.LoadInterDataNodeParametersAsync(args))", + "\n .Values", + "\n .SelectMany(x => x.SelectMany(y => y.Value.Select(z => new { ", + "\n Period = y.Key, ", + "\n //Parameter = (z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage)", + "\n z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage", + "\n })))", + "\n .Distinct()", + "\n .ToArray();", + "\ninterDataNodeParameters.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reports" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(interDataNodeParameters.OrderBy(x => x.DataNode))", + "\n .WithQuerySource(Workspace)", + "\n .ToTable()", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 3e4bcb1fd3e49d3d03bfbe7ac30cbdadd6655806 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Thu, 5 Jan 2023 14:15:24 +0100 Subject: [PATCH 2/5] update --- ifrs17-template/Report/ParameterReports.ipynb | 326 ++++++++++++++++-- 1 file changed, 297 insertions(+), 29 deletions(-) diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb index 3f444f9e..80508c36 100644 --- a/ifrs17-template/Report/ParameterReports.ipynb +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -54,7 +54,94 @@ { "cell_type": "markdown", "source": [ - "# Args" + "# Data Model" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public enum Period { Previous = -1, Current = 0 };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public abstract record ReportParameter {", + "\n [Display(Order = -100)]", + "\n [IdentityProperty]", + "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [Dimension(typeof(int), nameof(Year))]", + "\n public int Year { get; init; }", + "\n", + "\n [Display(Order = -90)]", + "\n [IdentityProperty]", + "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [Dimension(typeof(int), nameof(Month))]", + "\n public int Month { get; init; } ", + "\n", + "\n [Display(Order = -80)]", + "\n [IdentityProperty]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n public Period Period { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n [Dimension(typeof(GroupOfContract))]", + "\n public string GroupOfContract { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record YieldCurveReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n public string YieldCurveType { get; init; }", + "\n", + "\n [Dimension(typeof(Currency))]", + "\n public string Currency { get; init; }", + "\n", + "\n public string Name { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record SingleDataNodeReportParameter : ReportParameter {", + "\n public double PremiumAllocation { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record InterDataNodeReportParameter : ReportParameter {", + "\n [Dimension(typeof(GroupOfContract), nameof(LinkedDataNode))]", + "\n public string LinkedDataNode { get; init; }", + "\n", + "\n public double ReinsuranceCoverage { get; init; }", + "\n}" ], "metadata": {}, "execution_count": 0, @@ -63,7 +150,43 @@ { "cell_type": "code", "source": [ - "var args = new ImportArgs(\"CH\", 2021, 3, default, default , ImportFormats.Cashflow);" + "public record DataNodeData {", + "\n public string DataNode { get; init; }", + "\n", + "\n //Portfolio", + "\n [Dimension(typeof(Currency), nameof(ContractualCurrency))]", + "\n public string ContractualCurrency { get; init; }", + "\n", + "\n [Dimension(typeof(Currency), nameof(FunctionalCurrency))]", + "\n public string FunctionalCurrency { get; init; }", + "\n", + "\n [Dimension(typeof(LineOfBusiness))]", + "\n public string LineOfBusiness { get; init; }", + "\n", + "\n [Dimension(typeof(ValuationApproach))]", + "\n public string ValuationApproach { get; init; }", + "\n", + "\n public string OciType { get; init; }", + "\n ", + "\n //GroupOfContract", + "\n [Dimension(typeof(Portfolio))]", + "\n public string Portfolio { get; init; }", + "\n", + "\n [Dimension(typeof(int), nameof(AnnualCohort))]", + "\n public int AnnualCohort { get; init; }", + "\n public string LiabilityType { get; init; }", + "\n public string Profitability { get; init; }", + "\n public string Partner { get; init; }", + "\n ", + "\n //DataNodeState", + "\n public int Year { get; init; }", + "\n public int Month { get; init; }", + "\n public State State { get; init; }", + "\n public State PreviousState { get; init; }", + "\n ", + "\n public bool IsReinsurance { get; init; }", + "\n public DataNodeData(){}", + "\n}" ], "metadata": {}, "execution_count": 0, @@ -72,7 +195,7 @@ { "cell_type": "markdown", "source": [ - "# Data Node" + "# Args" ], "metadata": {}, "execution_count": 0, @@ -81,10 +204,16 @@ { "cell_type": "code", "source": [ - "var dataNodeData = (await Workspace.LoadDataNodesAsync(args))", - "\n .Values", - "\n .ToArray();", - "\ndataNodeData.Take(2)" + "var args = new ImportArgs(\"CH\", 2021, 3, default, default , default);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Node" ], "metadata": {}, "execution_count": 0, @@ -93,8 +222,10 @@ { "cell_type": "code", "source": [ - "dataNodeData", - "\n" + "var dataNodeData = (await Workspace.LoadDataNodesAsync(args))", + "\n .Values", + "\n .ToArray();", + "\ndataNodeData.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -113,10 +244,16 @@ "cell_type": "code", "source": [ "var lockedYieldCurves = (await Workspace.LoadLockedInYieldCurveAsync(args, dataNodeData))", - "\n .Select(x => new { ", - "\n DataNode = x.Key, ", - "\n LockedIn = (x.Value.Year, x.Value.Month, x.Value.Scenario, x.Value.Currency, x.Value.Name)", - "\n })", + "\n //.Select(x => new { DataNode = x.Key, LockedIn = ( x.Value.Year, x.Value.Month, x.Value.Scenario, x.Value.Currency, x.Value.Name)})", + "\n .Select(x => new YieldCurveReportParameter {", + "\n GroupOfContract = x.Key,", + "\n YieldCurveType = \"Locked-In Curve\",", + "\n Year = x.Value.Year,", + "\n Month = x.Value.Month,", + "\n Scenario = x.Value.Scenario,", + "\n Currency = x.Value.Currency,", + "\n Name = x.Value.Name }", + "\n )", "\n .ToArray();", "\nlockedYieldCurves.Take(2)" ], @@ -129,10 +266,16 @@ "source": [ "var currentYieldCurves = (await Workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", "\n .Values", - "\n .SelectMany(x => x.Select(y => new { ", - "\n Period = y.Key,", - "\n Current = (y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.Currency, y.Value.Name)", - "\n }))", + "\n //.SelectMany(x => x.Select(y => new { Period = y.Key, Current = ( y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.Currency, y.Value.Name)}))", + "\n .SelectMany(x => x.Select(y => new YieldCurveReportParameter {", + "\n Period = ((Period)y.Key),", + "\n YieldCurveType = \"Current Curve\",", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n Currency = y.Value.Currency,", + "\n Name = y.Value.Name}", + "\n ))", "\n .ToArray();", "\ncurrentYieldCurves.Take(2)" ], @@ -140,10 +283,29 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var allYieldCurves = lockedYieldCurves.Concat(lockedYieldCurves.SelectMany(loc => currentYieldCurves.Select(cuc => new YieldCurveReportParameter {", + "\n GroupOfContract = loc.GroupOfContract,", + "\n Period = cuc.Period,", + "\n YieldCurveType = cuc.YieldCurveType,", + "\n Year = cuc.Year,", + "\n Month = cuc.Month,", + "\n Scenario = cuc.Scenario,", + "\n Currency = cuc.Currency,", + "\n Name = cuc.Name}", + "\n )))", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ - "# Parameters" + "# Single Data Node Parameters" ], "metadata": {}, "execution_count": 0, @@ -154,10 +316,15 @@ "source": [ "var singleDataNodeParameters = (await Workspace.LoadSingleDataNodeParametersAsync(args))", "\n .Values", - "\n .SelectMany(x => x.Select(y => new { ", - "\n Period = y.Key, ", - "\n Parameter = (y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.DataNode, y.Value.PremiumAllocation)", - "\n }))", + "\n //.SelectMany(x => x.Select(y => new { Period = y.Key, Parameter = ( y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.DataNode, y.Value.PremiumAllocation)}))", + "\n .SelectMany(x => x.Select(y => new SingleDataNodeReportParameter {", + "\n GroupOfContract = y.Value.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n PremiumAllocation = y.Value.PremiumAllocation}", + "\n ))", "\n .ToArray();", "\nsingleDataNodeParameters.Take(2)" ], @@ -165,17 +332,33 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Inter Data Node Parameters" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ "var interDataNodeParameters = (await Workspace.LoadInterDataNodeParametersAsync(args))", "\n .Values", - "\n .SelectMany(x => x.SelectMany(y => y.Value.Select(z => new { ", - "\n Period = y.Key, ", - "\n //Parameter = (z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage)", - "\n z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage", - "\n })))", - "\n .Distinct()", + "\n //.SelectMany(x => x.SelectMany(y => y.Value.Select(z => new { Period = y.Key, Parameter = ( z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage)})))", + "\n .SelectMany(x => x.SelectMany(y => y.Value.Select(z => ", + "\n new InterDataNodeReportParameter {", + "\n GroupOfContract = z.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = z.Year,", + "\n Month = z.Month,", + "\n Scenario = z.Scenario,", + "\n LinkedDataNode = z.LinkedDataNode,", + "\n ReinsuranceCoverage = z.ReinsuranceCoverage}", + "\n )))", + "\n .Distinct()// Can be removed when we get rid of the dictionary", + "\n .SelectMany(x => new[]{x, x with { GroupOfContract = x.LinkedDataNode, LinkedDataNode = x.GroupOfContract}})", "\n .ToArray();", "\ninterDataNodeParameters.Take(2)" ], @@ -183,6 +366,52 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# CDR" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var partnerRatings = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => ", + "\n new {Period = ((Period)y.Key), y.Value}", + "\n ));", + "\nvar creditDefaultRates = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating))", + "\n .Values", + "\n .SelectMany(x => x.Select(y =>", + "\n new {Period = ((Period)y.Key), y.Value}", + "\n ));", + "\n//var partberDefaultRates" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "partnerRatings" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "creditDefaultRates" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -195,14 +424,53 @@ { "cell_type": "code", "source": [ - "await Report.ForObjects(interDataNodeParameters.OrderBy(x => x.DataNode))", + "await Report.ForObjects(allYieldCurves)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.GroupOfContract)", + "\n .GroupColumnsBy(x => x.YieldCurveType).GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(singleDataNodeParameters)", "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.GroupOfContract)", + "\n .GroupColumnsBy(x => x.Period)", "\n .ToTable()", "\n .ExecuteAsync()" ], "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(interDataNodeParameters)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.GroupOfContract).GroupRowsBy(x => x.LinkedDataNode)", + "\n .GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file From fa4166477ff40f26a0ab0df3cce399097fe6a58a Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Tue, 10 Jan 2023 09:34:54 +0100 Subject: [PATCH 3/5] update --- ifrs17-template/Report/ParameterReports.ipynb | 154 ++++++++++++++---- 1 file changed, 122 insertions(+), 32 deletions(-) diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb index 80508c36..2f02d3b7 100644 --- a/ifrs17-template/Report/ParameterReports.ipynb +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -104,6 +104,17 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "public record DataNodeStateReportParameter : ReportParameter {", + "\n public State State { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -150,10 +161,33 @@ { "cell_type": "code", "source": [ - "public record DataNodeData {", - "\n public string DataNode { get; init; }", + "public record PartnerRatingsReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n [Dimension(typeof(Partner))]", + "\n public string Partner { get; init; }", "\n", + "\n [Dimension(typeof(CreditRiskRating))]", + "\n public string CreditRiskRating { get; init; }", + "\n}", + "\npublic record CreditDefaultRatesReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [Dimension(typeof(CreditRiskRating))]", + "\n public string CreditRiskRating { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record DataNodeReportParameter : ReportParameter {", "\n //Portfolio", + "\n [Dimension(typeof(Portfolio))]", + "\n public string Portfolio { get; init; }", + "\n", "\n [Dimension(typeof(Currency), nameof(ContractualCurrency))]", "\n public string ContractualCurrency { get; init; }", "\n", @@ -169,8 +203,7 @@ "\n public string OciType { get; init; }", "\n ", "\n //GroupOfContract", - "\n [Dimension(typeof(Portfolio))]", - "\n public string Portfolio { get; init; }", + "\n", "\n", "\n [Dimension(typeof(int), nameof(AnnualCohort))]", "\n public int AnnualCohort { get; init; }", @@ -185,7 +218,7 @@ "\n public State PreviousState { get; init; }", "\n ", "\n public bool IsReinsurance { get; init; }", - "\n public DataNodeData(){}", + "\n", "\n}" ], "metadata": {}, @@ -204,7 +237,7 @@ { "cell_type": "code", "source": [ - "var args = new ImportArgs(\"CH\", 2021, 3, default, default , default);" + "var args = new ImportArgs(\"CH\", 2025, 3, default, default , default);" ], "metadata": {}, "execution_count": 0, @@ -231,6 +264,26 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var dataNodeStates = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.DataNode))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => ", + "\n new DataNodeStateReportParameter {", + "\n GroupOfContract = y.Value.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario }", + "\n ))", + "\n .ToArray();", + "\ndataNodeStates.Take(2)" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -255,16 +308,7 @@ "\n Name = x.Value.Name }", "\n )", "\n .ToArray();", - "\nlockedYieldCurves.Take(2)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var currentYieldCurves = (await Workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", + "\nvar currentYieldCurves = (await Workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", "\n .Values", "\n //.SelectMany(x => x.Select(y => new { Period = y.Key, Current = ( y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.Currency, y.Value.Name)}))", "\n .SelectMany(x => x.Select(y => new YieldCurveReportParameter {", @@ -277,16 +321,7 @@ "\n Name = y.Value.Name}", "\n ))", "\n .ToArray();", - "\ncurrentYieldCurves.Take(2)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var allYieldCurves = lockedYieldCurves.Concat(lockedYieldCurves.SelectMany(loc => currentYieldCurves.Select(cuc => new YieldCurveReportParameter {", + "\nvar allYieldCurves = lockedYieldCurves.Concat(lockedYieldCurves.SelectMany(loc => currentYieldCurves.Select(cuc => new YieldCurveReportParameter {", "\n GroupOfContract = loc.GroupOfContract,", "\n Period = cuc.Period,", "\n YieldCurveType = cuc.YieldCurveType,", @@ -296,7 +331,8 @@ "\n Currency = cuc.Currency,", "\n Name = cuc.Name}", "\n )))", - "\n .ToArray();" + "\n .ToArray();", + "\nallYieldCurves.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -369,7 +405,7 @@ { "cell_type": "markdown", "source": [ - "# CDR" + "# Partner Default Rates" ], "metadata": {}, "execution_count": 0, @@ -381,14 +417,39 @@ "var partnerRatings = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner))", "\n .Values", "\n .SelectMany(x => x.Select(y => ", - "\n new {Period = ((Period)y.Key), y.Value}", + "\n new PartnerRatingsReportParameter { ", + "\n Period = ((Period)y.Key),", + "\n Partner = y.Value.Partner,", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n CreditRiskRating = y.Value.CreditRiskRating", + "\n }", "\n ));", "\nvar creditDefaultRates = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating))", "\n .Values", "\n .SelectMany(x => x.Select(y =>", - "\n new {Period = ((Period)y.Key), y.Value}", + "\n new {", + "\n Period = ((Period)y.Key),", + "\n CreditRiskRating = y.Value.CreditRiskRating,", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario}", "\n ));", - "\n//var partberDefaultRates" + "\nvar partnerDefaultRates = partnerRatings.Join(", + "\n creditDefaultRates,", + "\n pr => new {pr.Period, pr.CreditRiskRating},", + "\n cdr => new {cdr.Period, cdr.CreditRiskRating},", + "\n (pr, cdr) => ", + "\n new CreditDefaultRatesReportParameter {", + "\n Period = pr.Period,", + "\n CreditRiskRating = pr.CreditRiskRating,", + "\n Year = cdr.Year,", + "\n Month = cdr.Month,", + "\n Scenario = cdr.Scenario,", + "\n }", + "\n ).ToArray();", + "\npartnerDefaultRates.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -406,7 +467,7 @@ { "cell_type": "code", "source": [ - "creditDefaultRates" + "partnerDefaultRates" ], "metadata": {}, "execution_count": 0, @@ -421,6 +482,21 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(dataNodeStates)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.GroupOfContract)", + "\n .GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()", + "\n " + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -463,6 +539,20 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(partnerRatings)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.Partner)", + "\n .GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ From 825113fab8a2eb431be3ad9b09c10d9f3b9d7bcc Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Tue, 10 Jan 2023 13:23:16 +0100 Subject: [PATCH 4/5] update --- ifrs17-template/Report/ParameterReports.ipynb | 93 +++++-------------- 1 file changed, 24 insertions(+), 69 deletions(-) diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb index 2f02d3b7..6e33fcc3 100644 --- a/ifrs17-template/Report/ParameterReports.ipynb +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -75,13 +75,13 @@ "public abstract record ReportParameter {", "\n [Display(Order = -100)]", "\n [IdentityProperty]", - "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [NotAggregated]", "\n [Dimension(typeof(int), nameof(Year))]", "\n public int Year { get; init; }", "\n", "\n [Display(Order = -90)]", "\n [IdentityProperty]", - "\n [NoArithmetics(ArithmeticOperation.Scale)]", + "\n [NotAggregated]", "\n [Dimension(typeof(int), nameof(Month))]", "\n public int Month { get; init; } ", "\n", @@ -173,6 +173,7 @@ "\npublic record CreditDefaultRatesReportParameter : ReportParameter {", "\n [IdentityProperty]", "\n [Dimension(typeof(CreditRiskRating))]", + "\n [NotVisible]", "\n public string CreditRiskRating { get; init; }", "\n}" ], @@ -180,51 +181,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "public record DataNodeReportParameter : ReportParameter {", - "\n //Portfolio", - "\n [Dimension(typeof(Portfolio))]", - "\n public string Portfolio { get; init; }", - "\n", - "\n [Dimension(typeof(Currency), nameof(ContractualCurrency))]", - "\n public string ContractualCurrency { get; init; }", - "\n", - "\n [Dimension(typeof(Currency), nameof(FunctionalCurrency))]", - "\n public string FunctionalCurrency { get; init; }", - "\n", - "\n [Dimension(typeof(LineOfBusiness))]", - "\n public string LineOfBusiness { get; init; }", - "\n", - "\n [Dimension(typeof(ValuationApproach))]", - "\n public string ValuationApproach { get; init; }", - "\n", - "\n public string OciType { get; init; }", - "\n ", - "\n //GroupOfContract", - "\n", - "\n", - "\n [Dimension(typeof(int), nameof(AnnualCohort))]", - "\n public int AnnualCohort { get; init; }", - "\n public string LiabilityType { get; init; }", - "\n public string Profitability { get; init; }", - "\n public string Partner { get; init; }", - "\n ", - "\n //DataNodeState", - "\n public int Year { get; init; }", - "\n public int Month { get; init; }", - "\n public State State { get; init; }", - "\n public State PreviousState { get; init; }", - "\n ", - "\n public bool IsReinsurance { get; init; }", - "\n", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -237,7 +193,7 @@ { "cell_type": "code", "source": [ - "var args = new ImportArgs(\"CH\", 2025, 3, default, default , default);" + "var args = new ImportArgs(\"CH\", 2021, 3, default, default , default);" ], "metadata": {}, "execution_count": 0, @@ -257,8 +213,7 @@ "source": [ "var dataNodeData = (await Workspace.LoadDataNodesAsync(args))", "\n .Values", - "\n .ToArray();", - "\ndataNodeData.Take(2)" + "\n .ToArray();" ], "metadata": {}, "execution_count": 0, @@ -278,7 +233,7 @@ "\n Scenario = y.Value.Scenario }", "\n ))", "\n .ToArray();", - "\ndataNodeStates.Take(2)" + "\n//dataNodeStates.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -332,7 +287,7 @@ "\n Name = cuc.Name}", "\n )))", "\n .ToArray();", - "\nallYieldCurves.Take(2)" + "\n//allYieldCurves.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -362,7 +317,7 @@ "\n PremiumAllocation = y.Value.PremiumAllocation}", "\n ))", "\n .ToArray();", - "\nsingleDataNodeParameters.Take(2)" + "\n//singleDataNodeParameters.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -396,7 +351,7 @@ "\n .Distinct()// Can be removed when we get rid of the dictionary", "\n .SelectMany(x => new[]{x, x with { GroupOfContract = x.LinkedDataNode, LinkedDataNode = x.GroupOfContract}})", "\n .ToArray();", - "\ninterDataNodeParameters.Take(2)" + "\n//interDataNodeParameters.Take(2)" ], "metadata": {}, "execution_count": 0, @@ -448,17 +403,16 @@ "\n Month = cdr.Month,", "\n Scenario = cdr.Scenario,", "\n }", - "\n ).ToArray();", - "\npartnerDefaultRates.Take(2)" + "\n ).ToArray();" ], "metadata": {}, "execution_count": 0, "outputs": [] }, { - "cell_type": "code", + "cell_type": "markdown", "source": [ - "partnerRatings" + "# Reports" ], "metadata": {}, "execution_count": 0, @@ -467,16 +421,12 @@ { "cell_type": "code", "source": [ - "partnerDefaultRates" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Reports" + "await Report.ForObjects(dataNodeData)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.Portfolio).GroupRowsBy(x => x.DataNode)", + "\n //.GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()" ], "metadata": {}, "execution_count": 0, @@ -556,7 +506,12 @@ { "cell_type": "code", "source": [ - "" + "await Report.ForObjects(partnerDefaultRates)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.CreditRiskRating)", + "\n .GroupColumnsBy(x => x.Period)", + "\n .ToTable()", + "\n .ExecuteAsync()" ], "metadata": {}, "execution_count": 0, From e5ab0514cca34df0c8e9c6c034beed7389732929 Mon Sep 17 00:00:00 2001 From: Daniel Trzesniak Date: Thu, 12 Jan 2023 11:04:04 +0100 Subject: [PATCH 5/5] Split in 2 files --- ifrs17-template/Report/ParameterReports.ipynb | 285 +------------ ifrs17/CalculationEngine.ipynb | 3 +- ifrs17/Report/ParameterReportsQueries.ipynb | 400 ++++++++++++++++++ 3 files changed, 410 insertions(+), 278 deletions(-) create mode 100644 ifrs17/Report/ParameterReportsQueries.ipynb diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb index 6e33fcc3..2d062832 100644 --- a/ifrs17-template/Report/ParameterReports.ipynb +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -51,136 +51,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "markdown", - "source": [ - "# Data Model" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public enum Period { Previous = -1, Current = 0 };" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public abstract record ReportParameter {", - "\n [Display(Order = -100)]", - "\n [IdentityProperty]", - "\n [NotAggregated]", - "\n [Dimension(typeof(int), nameof(Year))]", - "\n public int Year { get; init; }", - "\n", - "\n [Display(Order = -90)]", - "\n [IdentityProperty]", - "\n [NotAggregated]", - "\n [Dimension(typeof(int), nameof(Month))]", - "\n public int Month { get; init; } ", - "\n", - "\n [Display(Order = -80)]", - "\n [IdentityProperty]", - "\n [Dimension(typeof(Scenario))]", - "\n public string Scenario { get; init; }", - "\n", - "\n [IdentityProperty]", - "\n [NotVisible]", - "\n public Period Period { get; init; }", - "\n", - "\n [IdentityProperty]", - "\n [NotVisible]", - "\n [Dimension(typeof(GroupOfContract))]", - "\n public string GroupOfContract { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public record DataNodeStateReportParameter : ReportParameter {", - "\n public State State { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public record YieldCurveReportParameter : ReportParameter {", - "\n [IdentityProperty]", - "\n [NotVisible]", - "\n public string YieldCurveType { get; init; }", - "\n", - "\n [Dimension(typeof(Currency))]", - "\n public string Currency { get; init; }", - "\n", - "\n public string Name { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public record SingleDataNodeReportParameter : ReportParameter {", - "\n public double PremiumAllocation { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public record InterDataNodeReportParameter : ReportParameter {", - "\n [Dimension(typeof(GroupOfContract), nameof(LinkedDataNode))]", - "\n public string LinkedDataNode { get; init; }", - "\n", - "\n public double ReinsuranceCoverage { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public record PartnerRatingsReportParameter : ReportParameter {", - "\n [IdentityProperty]", - "\n [NotVisible]", - "\n [Dimension(typeof(Partner))]", - "\n public string Partner { get; init; }", - "\n", - "\n [Dimension(typeof(CreditRiskRating))]", - "\n public string CreditRiskRating { get; init; }", - "\n}", - "\npublic record CreditDefaultRatesReportParameter : ReportParameter {", - "\n [IdentityProperty]", - "\n [Dimension(typeof(CreditRiskRating))]", - "\n [NotVisible]", - "\n public string CreditRiskRating { get; init; }", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ @@ -211,9 +81,7 @@ { "cell_type": "code", "source": [ - "var dataNodeData = (await Workspace.LoadDataNodesAsync(args))", - "\n .Values", - "\n .ToArray();" + "var dataNodeData = await Workspace.GetDataNodeDataReportParameters(args);" ], "metadata": {}, "execution_count": 0, @@ -222,27 +90,7 @@ { "cell_type": "code", "source": [ - "var dataNodeStates = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.DataNode))", - "\n .Values", - "\n .SelectMany(x => x.Select(y => ", - "\n new DataNodeStateReportParameter {", - "\n GroupOfContract = y.Value.DataNode,", - "\n Period = ((Period)y.Key),", - "\n Year = y.Value.Year,", - "\n Month = y.Value.Month,", - "\n Scenario = y.Value.Scenario }", - "\n ))", - "\n .ToArray();", - "\n//dataNodeStates.Take(2)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# YieldCurve" + "var dataNodeStates = await Workspace.GetDataNodeStateReportParameters(args);" ], "metadata": {}, "execution_count": 0, @@ -251,52 +99,7 @@ { "cell_type": "code", "source": [ - "var lockedYieldCurves = (await Workspace.LoadLockedInYieldCurveAsync(args, dataNodeData))", - "\n //.Select(x => new { DataNode = x.Key, LockedIn = ( x.Value.Year, x.Value.Month, x.Value.Scenario, x.Value.Currency, x.Value.Name)})", - "\n .Select(x => new YieldCurveReportParameter {", - "\n GroupOfContract = x.Key,", - "\n YieldCurveType = \"Locked-In Curve\",", - "\n Year = x.Value.Year,", - "\n Month = x.Value.Month,", - "\n Scenario = x.Value.Scenario,", - "\n Currency = x.Value.Currency,", - "\n Name = x.Value.Name }", - "\n )", - "\n .ToArray();", - "\nvar currentYieldCurves = (await Workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", - "\n .Values", - "\n //.SelectMany(x => x.Select(y => new { Period = y.Key, Current = ( y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.Currency, y.Value.Name)}))", - "\n .SelectMany(x => x.Select(y => new YieldCurveReportParameter {", - "\n Period = ((Period)y.Key),", - "\n YieldCurveType = \"Current Curve\",", - "\n Year = y.Value.Year,", - "\n Month = y.Value.Month,", - "\n Scenario = y.Value.Scenario,", - "\n Currency = y.Value.Currency,", - "\n Name = y.Value.Name}", - "\n ))", - "\n .ToArray();", - "\nvar allYieldCurves = lockedYieldCurves.Concat(lockedYieldCurves.SelectMany(loc => currentYieldCurves.Select(cuc => new YieldCurveReportParameter {", - "\n GroupOfContract = loc.GroupOfContract,", - "\n Period = cuc.Period,", - "\n YieldCurveType = cuc.YieldCurveType,", - "\n Year = cuc.Year,", - "\n Month = cuc.Month,", - "\n Scenario = cuc.Scenario,", - "\n Currency = cuc.Currency,", - "\n Name = cuc.Name}", - "\n )))", - "\n .ToArray();", - "\n//allYieldCurves.Take(2)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Single Data Node Parameters" + "var allYieldCurves = await Workspace.GetYieldCurveReportParameters(args);;" ], "metadata": {}, "execution_count": 0, @@ -305,28 +108,7 @@ { "cell_type": "code", "source": [ - "var singleDataNodeParameters = (await Workspace.LoadSingleDataNodeParametersAsync(args))", - "\n .Values", - "\n //.SelectMany(x => x.Select(y => new { Period = y.Key, Parameter = ( y.Value.Year, y.Value.Month, y.Value.Scenario, y.Value.DataNode, y.Value.PremiumAllocation)}))", - "\n .SelectMany(x => x.Select(y => new SingleDataNodeReportParameter {", - "\n GroupOfContract = y.Value.DataNode,", - "\n Period = ((Period)y.Key),", - "\n Year = y.Value.Year,", - "\n Month = y.Value.Month,", - "\n Scenario = y.Value.Scenario,", - "\n PremiumAllocation = y.Value.PremiumAllocation}", - "\n ))", - "\n .ToArray();", - "\n//singleDataNodeParameters.Take(2)" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Inter Data Node Parameters" + "var singleDataNodeParameters = await Workspace.GetSingleDataNodeReportParameters(args);;" ], "metadata": {}, "execution_count": 0, @@ -335,32 +117,16 @@ { "cell_type": "code", "source": [ - "var interDataNodeParameters = (await Workspace.LoadInterDataNodeParametersAsync(args))", - "\n .Values", - "\n //.SelectMany(x => x.SelectMany(y => y.Value.Select(z => new { Period = y.Key, Parameter = ( z.Year, z.Month, z.Scenario, z.DataNode, z.LinkedDataNode, z.ReinsuranceCoverage)})))", - "\n .SelectMany(x => x.SelectMany(y => y.Value.Select(z => ", - "\n new InterDataNodeReportParameter {", - "\n GroupOfContract = z.DataNode,", - "\n Period = ((Period)y.Key),", - "\n Year = z.Year,", - "\n Month = z.Month,", - "\n Scenario = z.Scenario,", - "\n LinkedDataNode = z.LinkedDataNode,", - "\n ReinsuranceCoverage = z.ReinsuranceCoverage}", - "\n )))", - "\n .Distinct()// Can be removed when we get rid of the dictionary", - "\n .SelectMany(x => new[]{x, x with { GroupOfContract = x.LinkedDataNode, LinkedDataNode = x.GroupOfContract}})", - "\n .ToArray();", - "\n//interDataNodeParameters.Take(2)" + "var interDataNodeParameters = await Workspace.GetInterDataNodeParameters(args);;" ], "metadata": {}, "execution_count": 0, "outputs": [] }, { - "cell_type": "markdown", + "cell_type": "code", "source": [ - "# Partner Default Rates" + "var partnerRatings = await Workspace.GetPartnerRatingsReportParameters(args);" ], "metadata": {}, "execution_count": 0, @@ -369,41 +135,7 @@ { "cell_type": "code", "source": [ - "var partnerRatings = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner))", - "\n .Values", - "\n .SelectMany(x => x.Select(y => ", - "\n new PartnerRatingsReportParameter { ", - "\n Period = ((Period)y.Key),", - "\n Partner = y.Value.Partner,", - "\n Year = y.Value.Year,", - "\n Month = y.Value.Month,", - "\n Scenario = y.Value.Scenario,", - "\n CreditRiskRating = y.Value.CreditRiskRating", - "\n }", - "\n ));", - "\nvar creditDefaultRates = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating))", - "\n .Values", - "\n .SelectMany(x => x.Select(y =>", - "\n new {", - "\n Period = ((Period)y.Key),", - "\n CreditRiskRating = y.Value.CreditRiskRating,", - "\n Year = y.Value.Year,", - "\n Month = y.Value.Month,", - "\n Scenario = y.Value.Scenario}", - "\n ));", - "\nvar partnerDefaultRates = partnerRatings.Join(", - "\n creditDefaultRates,", - "\n pr => new {pr.Period, pr.CreditRiskRating},", - "\n cdr => new {cdr.Period, cdr.CreditRiskRating},", - "\n (pr, cdr) => ", - "\n new CreditDefaultRatesReportParameter {", - "\n Period = pr.Period,", - "\n CreditRiskRating = pr.CreditRiskRating,", - "\n Year = cdr.Year,", - "\n Month = cdr.Month,", - "\n Scenario = cdr.Scenario,", - "\n }", - "\n ).ToArray();" + "var partnerDefaultRates = await Workspace.GetCreditDefaultRatesReportParameters(args);;" ], "metadata": {}, "execution_count": 0, @@ -424,7 +156,6 @@ "await Report.ForObjects(dataNodeData)", "\n .WithQuerySource(Workspace)", "\n .GroupRowsBy(x => x.Portfolio).GroupRowsBy(x => x.DataNode)", - "\n //.GroupColumnsBy(x => x.Period)", "\n .ToTable()", "\n .ExecuteAsync()" ], diff --git a/ifrs17/CalculationEngine.ipynb b/ifrs17/CalculationEngine.ipynb index 288ee9fb..ccf9577a 100644 --- a/ifrs17/CalculationEngine.ipynb +++ b/ifrs17/CalculationEngine.ipynb @@ -22,7 +22,8 @@ "\n#!import \"Report/ReportMutableScopes\"", "\n#!import \"Import/Importers\"", "\n#!import \"Export/ExportConfiguration\"", - "\n#!import \"Utils/TestHelper\"" + "\n#!import \"Utils/TestHelper\"", + "\n#!import \"Report/ParameterReportsQueries\"" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Report/ParameterReportsQueries.ipynb b/ifrs17/Report/ParameterReportsQueries.ipynb new file mode 100644 index 00000000..04884352 --- /dev/null +++ b/ifrs17/Report/ParameterReportsQueries.ipynb @@ -0,0 +1,400 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Imports" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#!import \"../Utils/Queries\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Model", + "\nThe data model is still in progress, but this version already allows for simple reports" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public enum Period { Previous = -1, Current = 0 };" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public abstract record ReportParameter {", + "\n [Display(Order = -100)]", + "\n [IdentityProperty]", + "\n [NotAggregated]", + "\n [Dimension(typeof(int), nameof(Year))]", + "\n public int Year { get; init; }", + "\n", + "\n [Display(Order = -90)]", + "\n [IdentityProperty]", + "\n [NotAggregated]", + "\n [Dimension(typeof(int), nameof(Month))]", + "\n public int Month { get; init; } ", + "\n", + "\n [Display(Order = -80)]", + "\n [IdentityProperty]", + "\n [Dimension(typeof(Scenario))]", + "\n public string Scenario { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n public Period Period { get; init; }", + "\n", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n [Dimension(typeof(GroupOfContract))]", + "\n public string GroupOfContract { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record DataNodeStateReportParameter : ReportParameter {", + "\n public State State { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record YieldCurveReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n public string YieldCurveType { get; init; }", + "\n", + "\n [Dimension(typeof(Currency))]", + "\n public string Currency { get; init; }", + "\n", + "\n public string Name { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record SingleDataNodeReportParameter : ReportParameter {", + "\n public double PremiumAllocation { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record InterDataNodeReportParameter : ReportParameter {", + "\n [Dimension(typeof(GroupOfContract), nameof(LinkedDataNode))]", + "\n public string LinkedDataNode { get; init; }", + "\n", + "\n public double ReinsuranceCoverage { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public record PartnerRatingsReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [NotVisible]", + "\n [Dimension(typeof(Partner))]", + "\n public string Partner { get; init; }", + "\n", + "\n [Dimension(typeof(CreditRiskRating))]", + "\n public string CreditRiskRating { get; init; }", + "\n}", + "\npublic record CreditDefaultRatesReportParameter : ReportParameter {", + "\n [IdentityProperty]", + "\n [Dimension(typeof(CreditRiskRating))]", + "\n [NotVisible]", + "\n public string CreditRiskRating { get; init; }", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Node" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetDataNodeDataReportParameters(this IWorkspace workspace, ImportArgs args) =>", + "\n (await workspace.LoadDataNodesAsync(args))", + "\n .Values", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetDataNodeStateReportParameters(this IWorkspace workspace, ImportArgs args) =>", + "\n (await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.DataNode))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => ", + "\n new DataNodeStateReportParameter {", + "\n GroupOfContract = y.Value.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario }", + "\n ))", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# YieldCurve" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetYieldCurveReportParameters(this IWorkspace workspace, ImportArgs args) {", + "\n var dataNodeData = await workspace.GetDataNodeDataReportParameters(args);", + "\n", + "\n var lockedYieldCurves = (await workspace.LoadLockedInYieldCurveAsync(args, dataNodeData))", + "\n .Select(x => new YieldCurveReportParameter {", + "\n GroupOfContract = x.Key,", + "\n YieldCurveType = \"Locked-In Curve\",", + "\n Year = x.Value.Year,", + "\n Month = x.Value.Month,", + "\n Scenario = x.Value.Scenario,", + "\n Currency = x.Value.Currency,", + "\n Name = x.Value.Name }", + "\n )", + "\n .ToArray();", + "\n", + "\n var currentYieldCurves = (await workspace.LoadCurrentYieldCurveAsync(args, dataNodeData))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => new YieldCurveReportParameter {", + "\n Period = ((Period)y.Key),", + "\n YieldCurveType = \"Current Curve\",", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n Currency = y.Value.Currency,", + "\n Name = y.Value.Name}", + "\n ));", + "\n", + "\n var allYieldCurves = lockedYieldCurves.Concat(lockedYieldCurves.SelectMany(loc => currentYieldCurves.Select(cuc => new YieldCurveReportParameter {", + "\n GroupOfContract = loc.GroupOfContract,", + "\n Period = cuc.Period,", + "\n YieldCurveType = cuc.YieldCurveType,", + "\n Year = cuc.Year,", + "\n Month = cuc.Month,", + "\n Scenario = cuc.Scenario,", + "\n Currency = cuc.Currency,", + "\n Name = cuc.Name}", + "\n )))", + "\n .ToArray();", + "\n ", + "\n return allYieldCurves;", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Single Data Node Parameters" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetSingleDataNodeReportParameters(this IWorkspace workspace, ImportArgs args) =>", + "\n (await workspace.LoadSingleDataNodeParametersAsync(args))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => new SingleDataNodeReportParameter {", + "\n GroupOfContract = y.Value.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n PremiumAllocation = y.Value.PremiumAllocation}", + "\n ))", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Inter Data Node Parameters" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetInterDataNodeParameters(this IWorkspace workspace, ImportArgs args) =>", + "\n (await workspace.LoadInterDataNodeParametersAsync(args))", + "\n .Values", + "\n .SelectMany(x => x.SelectMany(y => y.Value.Select(z => ", + "\n new InterDataNodeReportParameter {", + "\n GroupOfContract = z.DataNode,", + "\n Period = ((Period)y.Key),", + "\n Year = z.Year,", + "\n Month = z.Month,", + "\n Scenario = z.Scenario,", + "\n LinkedDataNode = z.LinkedDataNode,", + "\n ReinsuranceCoverage = z.ReinsuranceCoverage}", + "\n )))", + "\n .Distinct()// Can be removed when we get rid of the dictionary", + "\n .SelectMany(x => new[]{x, x with { GroupOfContract = x.LinkedDataNode, LinkedDataNode = x.GroupOfContract}}", + "\n )", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Partner Default Rates" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetPartnerRatingsReportParameters(this IWorkspace workspace, ImportArgs args) =>", + "\n (await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Partner))", + "\n .Values", + "\n .SelectMany(x => x.Select(y => ", + "\n new PartnerRatingsReportParameter { ", + "\n Period = ((Period)y.Key),", + "\n Partner = y.Value.Partner,", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario,", + "\n CreditRiskRating = y.Value.CreditRiskRating", + "\n }", + "\n ))", + "\n .ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static async Task GetCreditDefaultRatesReportParameters(this IWorkspace workspace, ImportArgs args) {", + "\n var partnerRatings = await workspace.GetPartnerRatingsReportParameters(args);", + "\n ", + "\n var creditDefaultRates = (await workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.CreditRiskRating))", + "\n .Values", + "\n .SelectMany(x => x.Select(y =>", + "\n new {", + "\n Period = ((Period)y.Key),", + "\n CreditRiskRating = y.Value.CreditRiskRating,", + "\n Year = y.Value.Year,", + "\n Month = y.Value.Month,", + "\n Scenario = y.Value.Scenario}", + "\n ));", + "\n ", + "\n var partnerDefaultRates = partnerRatings.Join(", + "\n creditDefaultRates,", + "\n pr => new {pr.Period, pr.CreditRiskRating},", + "\n cdr => new {cdr.Period, cdr.CreditRiskRating},", + "\n (pr, cdr) => ", + "\n new CreditDefaultRatesReportParameter {", + "\n Period = pr.Period,", + "\n CreditRiskRating = pr.CreditRiskRating,", + "\n Year = cdr.Year,", + "\n Month = cdr.Month,", + "\n Scenario = cdr.Scenario,", + "\n }", + "\n )", + "\n .ToArray();", + "\n", + "\n return partnerDefaultRates;", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file