diff --git a/ifrs17-template/Report/ParameterReports.ipynb b/ifrs17-template/Report/ParameterReports.ipynb new file mode 100644 index 00000000..2d062832 --- /dev/null +++ b/ifrs17-template/Report/ParameterReports.ipynb @@ -0,0 +1,252 @@ +{ + "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 , default);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Data Node" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var dataNodeData = await Workspace.GetDataNodeDataReportParameters(args);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var dataNodeStates = await Workspace.GetDataNodeStateReportParameters(args);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var allYieldCurves = await Workspace.GetYieldCurveReportParameters(args);;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var singleDataNodeParameters = await Workspace.GetSingleDataNodeReportParameters(args);;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var interDataNodeParameters = await Workspace.GetInterDataNodeParameters(args);;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var partnerRatings = await Workspace.GetPartnerRatingsReportParameters(args);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var partnerDefaultRates = await Workspace.GetCreditDefaultRatesReportParameters(args);;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Reports" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "await Report.ForObjects(dataNodeData)", + "\n .WithQuerySource(Workspace)", + "\n .GroupRowsBy(x => x.Portfolio).GroupRowsBy(x => x.DataNode)", + "\n .ToTable()", + "\n .ExecuteAsync()" + ], + "metadata": {}, + "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": [ + "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": [ + "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": [ + "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, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17/CalculationEngine.ipynb b/ifrs17/CalculationEngine.ipynb index 06c8c635..49d163c6 100644 --- a/ifrs17/CalculationEngine.ipynb +++ b/ifrs17/CalculationEngine.ipynb @@ -23,7 +23,8 @@ "\n#!import \"Import/Importers\"", "\n#!import \"Export/ExportConfiguration\"", "\n#!import \"Utils/TestHelper\"", - "\n#!import \"Utils/ActivityLog\"" + "\n#!import \"Utils/ActivityLog\"", + "\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