From e2ece849d1619c814f6f935c8df91c7e7eab56fd Mon Sep 17 00:00:00 2001 From: Aleksei Nekrasov Date: Tue, 13 Dec 2022 19:17:58 +0100 Subject: [PATCH 01/49] Distinguish YieldCurve by Name --- ifrs17/Utils/Queries.ipynb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 47f4597b..51af8e57 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -183,14 +183,15 @@ { "cell_type": "code", "source": [ - "public static async Task> LoadLockedInYieldCurveAsync(this IQuerySource querySource, Args args, ", + "public static async Task> LoadLockedInYieldCurveAsync(this IQuerySource querySource, Args args, string yieldCurveName,", "\n IEnumerable dataNodes)", + "\n", "\n{", "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", - "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency));", + "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == yieldCurveName));", "\n ", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", @@ -217,13 +218,13 @@ { "cell_type": "code", "source": [ - "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args, ", + "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args, string yieldCurveName, ", "\n IEnumerable dataNodes)", "\n{", "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", "\n return (await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", - "\n x => contractualCurrenciesInScope.Contains(x.Currency)", + "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == yieldCurveName", "\n ));", "\n}" ], From 67136bb01dcbf49b540c70399c8c2d70f09f63c6 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Wed, 14 Dec 2022 18:08:37 +0100 Subject: [PATCH 02/49] Enhance DataStructure.DataNodeData with YieldCurveName string; edit Queries --- ifrs17/DataModel/DataStructure.ipynb | 2 ++ ifrs17/Utils/Queries.ipynb | 35 +++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ifrs17/DataModel/DataStructure.ipynb b/ifrs17/DataModel/DataStructure.ipynb index 3e6144ff..4285733e 100644 --- a/ifrs17/DataModel/DataStructure.ipynb +++ b/ifrs17/DataModel/DataStructure.ipynb @@ -1673,6 +1673,8 @@ "\n public string LiabilityType { get; init; }", "\n public string Profitability { get; init; }", "\n public string Partner { get; init; }", + "\n public string YieldCurveName { get; init; }", + "\n ", "\n ", "\n //DataNodeState", "\n public int Year { get; init; }", diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 51af8e57..26986a89 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -183,15 +183,14 @@ { "cell_type": "code", "source": [ - "public static async Task> LoadLockedInYieldCurveAsync(this IQuerySource querySource, Args args, string yieldCurveName,", - "\n IEnumerable dataNodes)", + "public static async Task> LoadLockedInYieldCurveAsync(this IQuerySource querySource, Args args, IEnumerable dataNodes)", "\n", "\n{", "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", - "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == yieldCurveName));", + "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", @@ -218,14 +217,31 @@ { "cell_type": "code", "source": [ - "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args, string yieldCurveName, ", - "\n IEnumerable dataNodes)", + "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args,", + "\n IEnumerable dataNodes)", "\n{", "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", - "\n return (await querySource.LoadCurrentAndPreviousParameterAsync(args, ", - "\n x => x.Currency,", - "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == yieldCurveName", - "\n ));", + "\n ", + "\n var returnDictionary = new Dictionary>(); ", + "\n foreach (var dn in dataNodes)", + "\n {", + "\n", + "\n result[dn.DataNode] = SomeDict_querySource.LoadCurrentAndPreviousParameterAsync()[dn.DataNode] //But that is the same as to return that SomeDict_querySource !!!", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n donary[dn.DataNode] = ", + "\n var renameMe = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n x => dn.DataNode", + "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", + "\n }", + "\n ", + "\n return await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n x => dn.DataNode", + "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", "\n}" ], "metadata": {}, @@ -292,6 +308,7 @@ "\n Profitability = dn.Profitability,", "\n Partner = dn.Partner,", "\n IsReinsurance = dn.GetType() == typeof(GroupOfReinsuranceContract),", + "\n YieldCurveName = dn.YieldCurveName", "\n };", "\n }", "\n );", From d1ebb6fd3978e66072beabbff4e1fe6308672c13 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 10:51:46 +0100 Subject: [PATCH 03/49] Fix LoadCurrentYieldCurveAsync Task --- ifrs17/Utils/Queries.ipynb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 26986a89..61145630 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -191,7 +191,6 @@ "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", - "\n ", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", @@ -223,25 +222,22 @@ "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", "\n ", "\n var returnDictionary = new Dictionary>(); ", - "\n foreach (var dn in dataNodes)", + "\n ", + "\n foreach (var dn in dataNodes) //do we need to have some condition on dataNodes?", "\n {", - "\n", - "\n result[dn.DataNode] = SomeDict_querySource.LoadCurrentAndPreviousParameterAsync()[dn.DataNode] //But that is the same as to return that SomeDict_querySource !!!", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n donary[dn.DataNode] = ", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var renameMe = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", - "\n x => dn.DataNode", + "\n x => x.Currency,", "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", + "\n if(!renameMe.TryGetValue(dn.ContractualCurrency, out var renameMeYc))", + "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", + "\n ", + "\n returnDictionary[dn.DataNode] = renameMeYc;", "\n }", "\n ", - "\n return await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n return returnDictionary; /* await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => dn.DataNode", - "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", + "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);*/", "\n}" ], "metadata": {}, From 25e8460fae1ee6846aef8ad46090b103512838b9 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 11:39:01 +0100 Subject: [PATCH 04/49] new test --- ifrs17/Utils/Queries.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 61145630..a457b00f 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -191,6 +191,7 @@ "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", + "\n //LoadCurrentParameterAsync -> Dictionary<'Currency'=string, T>", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", @@ -221,15 +222,15 @@ "\n{", "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", "\n ", - "\n var returnDictionary = new Dictionary>(); ", + "\n var returnDictionary = new Dictionary>();", "\n ", "\n foreach (var dn in dataNodes) //do we need to have some condition on dataNodes?", "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", - "\n var renameMe = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", - "\n if(!renameMe.TryGetValue(dn.ContractualCurrency, out var renameMeYc))", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var renameMeYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n returnDictionary[dn.DataNode] = renameMeYc;", From 8deb3a4a4992854e6da0c06784fec2c97150fd3d Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 11:58:48 +0100 Subject: [PATCH 05/49] Additional tests + args edit (yieldCurveName) --- ifrs17/Test/QueriesTest.ipynb | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index a3f67136..658db08a 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -17,6 +17,24 @@ "nbformat": 4, "nbformat_minor": 5, "cells": [ + { + "cell_type": "code", + "source": [ + "//#r \"nuget:Systemorph.Test, 1.6.1\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "REMOVE above cell" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -344,7 +362,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month) dataNodeYearAndMonth, ", + "\n (int year , int month, string yieldCurveName) dataNodeParameters,", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -353,18 +371,18 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\"}};", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", - "\n var currentPrevPeriod = eurCurrentYieldCurve[\"EUR\"][PreviousPeriod].Values.First();", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", "\n ", - "\n var currentCurrPeriod = eurCurrentYieldCurve[\"EUR\"][CurrentPeriod].Values.First();", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", @@ -388,7 +406,22 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6), 6.1, 0.1, 6.1);" + "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);" ], "metadata": {}, "execution_count": 0, From 3d25b5046d83426a3c8684d55d6952f36e0c930f Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 11:58:48 +0100 Subject: [PATCH 06/49] Additional tests + args edit (yieldCurveName) --- ifrs17/Test/QueriesTest.ipynb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index a3f67136..599c6872 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -344,7 +344,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month) dataNodeYearAndMonth, ", + "\n (int year , int month, string yieldCurveName) dataNodeParameters,", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -353,18 +353,18 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\"}};", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", - "\n var currentPrevPeriod = eurCurrentYieldCurve[\"EUR\"][PreviousPeriod].Values.First();", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", "\n ", - "\n var currentCurrPeriod = eurCurrentYieldCurve[\"EUR\"][CurrentPeriod].Values.First();", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", @@ -388,7 +388,22 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6), 6.1, 0.1, 6.1);" + "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);" ], "metadata": {}, "execution_count": 0, From 59653d9b0621149d67726cc47d050dfbaa1fbd1e Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 14:04:53 +0100 Subject: [PATCH 07/49] Clean up and renaming variables --- ifrs17/Utils/Queries.ipynb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index a457b00f..29de3bba 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -191,7 +191,7 @@ "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", - "\n //LoadCurrentParameterAsync -> Dictionary<'Currency'=string, T>", + "\n ", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", @@ -217,28 +217,26 @@ { "cell_type": "code", "source": [ - "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args,", + "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args,", "\n IEnumerable dataNodes)", "\n{", "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", "\n ", - "\n var returnDictionary = new Dictionary>();", + "\n var currentYieldCurveByGoc = new Dictionary>();", "\n ", - "\n foreach (var dn in dataNodes) //do we need to have some condition on dataNodes?", + "\n foreach (var dn in dataNodes)", "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var renameMeYc))", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", - "\n returnDictionary[dn.DataNode] = renameMeYc;", + "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", "\n }", "\n ", - "\n return returnDictionary; /* await querySource.LoadCurrentAndPreviousParameterAsync(args, ", - "\n x => dn.DataNode", - "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);*/", + "\n return currentYieldCurveByGoc;", "\n}" ], "metadata": {}, From f9e456e7be5837696c80a4369ccd3553864deca2 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 18:26:46 +0100 Subject: [PATCH 08/49] Add new condition to prevent failure while retrieving data from YieldCurve dictionaries --- ifrs17/Test/QueriesTest.ipynb | 55 ++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index e4d303fb..e7f00570 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -563,17 +563,32 @@ "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", - "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", - "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", - "\n ", - "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", - "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", - "\n ", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", - "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", - "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", + "\n", + "\n if (eurCurrentYieldCurve[gic] == null)", + "\n errors.Add( $\"No Current YieldCurve corresponding to {gic}\" );", + "\n else if (eurCurrentYieldCurve[gic][PreviousPeriod] == null) // RUSO : need a test? need a test? need a test? need a test? need a test? need a test? ", + "\n errors.Add( $\"No Current YieldCurve corresponding to the Previous Period\" );", + "\n else if (eurCurrentYieldCurve[gic][CurrentPeriod] == null)", + "\n errors.Add( $\"No Current YieldCurve corresponding to the Current Period\" );", + "\n else", + "\n {", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", + "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", + "\n", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", + "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", + "\n }", + "\n", + "\n if (eurLockedYieldCurve[gic] == null)", + "\n errors.Add( $\"No LockedIn Yield Curve corresponding to {gic}\" ); // RUSO : need a test! need a test! need a test! need a test! need a test! ", + "\n else", + "\n {", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", + "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", + "\n } ", "\n ", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", "\n return Activity.Finish();", @@ -592,7 +607,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);" + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", + "\nactivity" + ], + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -607,7 +629,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nawait CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);" + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\nactivity" + ], + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, From b34c6edce5a14b4c7b7f8739f9d245ac2105a0fc Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 19 Dec 2022 19:47:34 +0100 Subject: [PATCH 09/49] Next improvements. But I propose to throw an exception! --- ifrs17/Test/QueriesTest.ipynb | 22 ++++++++++++++++++++++ ifrs17/Utils/Queries.ipynb | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index e7f00570..ffad090e 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -629,6 +629,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", + "\n", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", "\nactivity" ], @@ -642,6 +643,27 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n", + "\nactivity.Status== ActivityLogStatus.Failed " + ], + }, + { + "cell_type": "code", + "source": [ + "activity" + ], + }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 29de3bba..b29ae606 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -192,7 +192,7 @@ "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n lockedInYieldCurveByGoc[dn.DataNode] = lockedYc;", @@ -230,7 +230,7 @@ "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict))", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null)", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", From 01f4dba906543b0dfb0da1afad56709bdacf01ec Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 14:59:48 +0100 Subject: [PATCH 10/49] Change to ValuationApproaches.VFA, add additional condition to post an error; cosmetic change - rename 'activity' to 'log' --- ifrs17/Test/QueriesTest.ipynb | 195 ++++++++++++++++------------------ ifrs17/Utils/Queries.ipynb | 17 +-- 2 files changed, 100 insertions(+), 112 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index ffad090e..a73a0d88 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -106,8 +106,8 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9, null),(2020, 9, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9, null),(2020, 9, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -116,7 +116,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -128,8 +128,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", "\nvar testData = new[] { new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9 } };", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario),(2020, 9, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario),(2020, 9, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -138,7 +138,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -149,8 +149,8 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12, null), (2019, 12, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12, null), (2019, 12, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -159,7 +159,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -171,8 +171,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -181,7 +181,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -193,8 +193,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -203,7 +203,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -215,8 +215,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -225,7 +225,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -237,8 +237,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2019, 3, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2019, 3, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -247,7 +247,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -259,8 +259,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2020, 9, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2020, 9, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -269,7 +269,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -281,8 +281,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2019, 9, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2019, 9, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -291,7 +291,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -304,8 +304,8 @@ "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = scenario},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -314,7 +314,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -326,8 +326,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -336,7 +336,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -348,8 +348,8 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 9, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -358,7 +358,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -371,8 +371,8 @@ "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -381,7 +381,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -395,8 +395,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -405,7 +405,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -419,8 +419,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2015, Month = 9, Scenario = null},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -429,7 +429,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -444,8 +444,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Scenario = null},", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", "\n", - "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", - "\nactivity" + "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -454,7 +454,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -495,8 +495,8 @@ "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2019, Month = 12, State = State.Active },", "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 6, State = State.Inactive }};", - "\nvar activity = await CheckLoadDataNodeStateAsync(args, testData, false);", - "\nactivity" + "\nvar log = await CheckLoadDataNodeStateAsync(args, testData, false);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -505,7 +505,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -517,8 +517,8 @@ "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2020, Month = 3, State = State.Active },", "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 9, State = State.Inactive }};", - "\nvar activity = await CheckLoadDataNodeStateAsync(args, testData, false);", - "\nactivity" + "\nvar log = await CheckLoadDataNodeStateAsync(args, testData, false);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -527,7 +527,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -560,36 +560,25 @@ "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", + "\n var errors = new List();", + "\n ", + "\n if (ApplicationMessage.HasErrors()) ", + "\n return Activity.Finish();", + "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", - "\n var errors = new List();", - "\n", - "\n if (eurCurrentYieldCurve[gic] == null)", - "\n errors.Add( $\"No Current YieldCurve corresponding to {gic}\" );", - "\n else if (eurCurrentYieldCurve[gic][PreviousPeriod] == null) // RUSO : need a test? need a test? need a test? need a test? need a test? need a test? ", - "\n errors.Add( $\"No Current YieldCurve corresponding to the Previous Period\" );", - "\n else if (eurCurrentYieldCurve[gic][CurrentPeriod] == null)", - "\n errors.Add( $\"No Current YieldCurve corresponding to the Current Period\" );", - "\n else", - "\n {", - "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", - "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", + "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", "\n", - "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", - "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", - "\n }", - "\n", - "\n if (eurLockedYieldCurve[gic] == null)", - "\n errors.Add( $\"No LockedIn Yield Curve corresponding to {gic}\" ); // RUSO : need a test! need a test! need a test! need a test! need a test! ", - "\n else", - "\n {", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", - "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", - "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\n } ", - "\n ", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", + "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", + "\n ", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", + "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", + "\n ", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", "\n return Activity.Finish();", "\n}" @@ -607,14 +596,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", - "\nactivity" + "\nvar log = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", + "\nlog" ], }, { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -630,14 +619,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", - "\nactivity" + "\nvar log = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\nlog" ], }, { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -652,16 +641,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n", - "\nactivity.Status== ActivityLogStatus.Failed " + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");" ], }, { "cell_type": "code", "source": [ - "activity" + "var log = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(log.Errors.Single().ToString().Contains(\"Yield Curve not found\")).Should().Be(true);" ], }, { @@ -789,8 +776,8 @@ "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", "\n };", "\n", - "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear);", - "\nactivity" + "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -799,7 +786,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -820,8 +807,8 @@ "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9}, ", "\n };", "\n", - "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nactivity" + "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -830,7 +817,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -848,8 +835,8 @@ "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", "\n };", "\n", - "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nactivity" + "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -858,7 +845,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, @@ -876,8 +863,8 @@ "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 3}, ", "\n };", "\n", - "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nactivity" + "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\nlog" ], "metadata": {}, "execution_count": 0, @@ -886,7 +873,7 @@ { "cell_type": "code", "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + "log.Status.Should().Be(ActivityLogStatus.Succeeded);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index b29ae606..21989289 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,12 +189,12 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //RUSO : change dn.Month to MonthInAYear constant !!!!!!!!!", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", + "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", - "\n ", + "\n ", "\n lockedInYieldCurveByGoc[dn.DataNode] = lockedYc;", "\n }", "\n ", @@ -219,9 +219,7 @@ "source": [ "public static async Task>> LoadCurrentYieldCurveAsync(this IQuerySource querySource, Args args,", "\n IEnumerable dataNodes)", - "\n{", - "\n var contractualCurrenciesInScope = dataNodes.Select(dn => dn.ContractualCurrency).ToHashSet();", - "\n ", + "\n{ ", "\n var currentYieldCurveByGoc = new Dictionary>();", "\n ", "\n foreach (var dn in dataNodes)", @@ -229,8 +227,11 @@ "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", - "\n x => contractualCurrenciesInScope.Contains(x.Currency) && x.Name == dn.YieldCurveName);", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null)", + "\n x => x.Currency == dn.ContractualCurrency ", + "\n && (dn.ValuationApproach == ValuationApproaches.VFA ", + "\n ? x.Name == dn.YieldCurveName ", + "\n : true));", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null || currentYcDict.Values == null)", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", From e77328fb8546ba4f381f5df4c12741a8bf3c5373 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 15:57:54 +0100 Subject: [PATCH 11/49] Organize Unit test differently --- ifrs17/Test/QueriesTest.ipynb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index a73a0d88..aa987596 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -618,8 +618,13 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n", - "\nvar log = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");" + ], + }, + { + "cell_type": "code", + "source": [ + "var log = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nlog" ], }, @@ -641,14 +646,14 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");" + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 2, \"A\");" ], }, { "cell_type": "code", "source": [ "var log = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n(log.Errors.Single().ToString().Contains(\"Yield Curve not found\")).Should().Be(true);" + "\n(log.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" ], }, { From 159d6926fdbcb1740c1d5df27509dba7866c3045 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 16:11:26 +0100 Subject: [PATCH 12/49] Add a general Error.YieldCurveNotFound error message --- ifrs17/Constants/Validations.ipynb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index e4db9b6c..1cf4fd45 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -157,6 +157,7 @@ "\n (Error.MissingPremiumAllocation , 1) => $\"Premium Allocation Rate not found for Group of Contract {s[0]}.\", // TODO: this is now a warning to be produced by a validation in the importers (default is 1)", "\n (Error.ReinsuranceCoverage , 1) => $\"Reinsurance Allocation Rate not found for Group of Insurance Contract {s[0]}.\",", "\n (Error.YieldCurveNotFound , 3) => $\"Yield Curve not found for currency {s[0]}, year {s[1]}, and month {s[2]}.\",", + "\n (Error.YieldCurveNotFound , 0) => $\"Yield Curve not found\",", "\n (Error.YieldCurvePeriodNotApplicable , 2) => $\"YieldCurve period NotApplicable not valid for AoC Step with AoC Type {s[0]} and Novelty {s[1]}.\",", "\n (Error.EconomicBasisNotFound , 1) => $\"EconomicBasis not valid for DataNode {s[0]}.\",", "\n (Error.AccountingVariableTypeNotFound , 1) => $\"AccountingVariableType {s[0]} not found.\",", @@ -190,15 +191,6 @@ "metadata": {}, "execution_count": 0, "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] } ] } \ No newline at end of file From 89519ce15e1781c24ca56395bbf6a87e7f66133a Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 16:26:03 +0100 Subject: [PATCH 13/49] Try to bring back the corrupted NB --- ifrs17/Test/QueriesTest.ipynb | 897 ---------------------------------- 1 file changed, 897 deletions(-) delete mode 100644 ifrs17/Test/QueriesTest.ipynb diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb deleted file mode 100644 index aa987596..00000000 --- a/ifrs17/Test/QueriesTest.ipynb +++ /dev/null @@ -1,897 +0,0 @@ -{ - "metadata": { - "authors": [], - "kernelspec": { - "display_name": "Formula Framework", - "language": "C#", - "name": "C#" - }, - "language_info": { - "file_extension": ".cs", - "mimetype": "text/plain", - "name": "C#" - }, - "toc-autonumbering": "True", - "toc-showcode": "False" - }, - "nbformat": 4, - "nbformat_minor": 5, - "cells": [ - { - "cell_type": "code", - "source": [ - "//#r \"nuget:Systemorph.Test, 1.6.1\"" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "REMOVE above cell" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "#!import \"../CalculationEngine\"" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var gic = \"DT1.1\";", - "\nvar scenario = \"MTUP\";" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Test Load Current and Previous Parameter for Yield Curve" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public async Task CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int Year, int Month, string Scenario) expectedCurrentPeriod, ", - "\n (int Year, int Month, string Scenario) expectedPreviousPeriod)", - "\n{", - "\n Activity.Start();", - "\n await Workspace.UpdateAsync(testData);", - "\n var eurCurrentAndPreviousYieldCurve = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Currency))[\"EUR\"];", - "\n ", - "\n //Check Current Period", - "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Year.Should().Be(expectedCurrentPeriod.Year);", - "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Month.Should().Be(expectedCurrentPeriod.Month);", - "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Scenario.Should().Be(expectedCurrentPeriod.Scenario);", - "\n ", - "\n //Check Previous Period", - "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Year.Should().Be(expectedPreviousPeriod.Year);", - "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Month.Should().Be(expectedPreviousPeriod.Month);", - "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Scenario.Should().Be(expectedPreviousPeriod.Scenario);", - "\n ", - "\n await Workspace.DeleteAsync(Workspace.Query().ToArray());", - "\n return Activity.Finish();", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9, null),(2020, 9, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", - "\nvar testData = new[] { new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9 } };", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario),(2020, 9, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12, null), (2019, 12, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2019, 3, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2020, 9, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2019, 9, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"EUR\",2020,9,Periodicity.Monthly,scenario);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = scenario},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 9, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly, scenario);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = scenario},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2015, Month = 9, Scenario = null},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Scenario = null},", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", - "\n", - "\nvar log = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Test Data Node State Query" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public async Task CheckLoadDataNodeStateAsync(Args args, IEnumerable testData, bool isExpectedToBeActive)", - "\n{", - "\n Activity.Start();", - "\n await Workspace.Partition.SetAsync(args);", - "\n await Workspace.UpdateAsync(testData);", - "\n var isActive = (await Workspace.LoadDataNodeStateAsync(args)).Keys.Contains(gic);", - "\n ", - "\n isActive.Should().Be(isExpectedToBeActive);", - "\n ", - "\n Workspace.Reset(x => x.ResetCurrentPartitions());", - "\n return Activity.Finish();", - "\n}" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", - "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2019, Month = 12, State = State.Active },", - "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 6, State = State.Inactive }};", - "\nvar log = await CheckLoadDataNodeStateAsync(args, testData, false);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", - "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2020, Month = 3, State = State.Active },", - "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 9, State = State.Inactive }};", - "\nvar log = await CheckLoadDataNodeStateAsync(args, testData, false);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Test Load Yield Curve" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month, string yieldCurveName) dataNodeParameters,", - "\n double expectedCurrentPreviousFirstYcValue,", - "\n double expectedCurrentFirstYcValue,", - "\n double expectedLockedFirstYcValue)", - "\n{", - "\n Activity.Start();", - "\n await Workspace.Partition.SetAsync(args);", - "\n await Workspace.UpdateAsync(testData);", - "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", - "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", - "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", - "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", - "\n ", - "\n var errors = new List();", - "\n ", - "\n if (ApplicationMessage.HasErrors()) ", - "\n return Activity.Finish();", - "\n ", - "\n Workspace.Reset(x => x.ResetCurrentPartitions());", - "\n ", - "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", - "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", - "\n", - "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", - "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", - "\n ", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", - "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", - "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\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": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\nvar log = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", - "\nlog" - ], - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");" - ], - }, - { - "cell_type": "code", - "source": [ - "var log = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\nlog" - ], - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 2, \"A\");" - ], - }, - { - "cell_type": "code", - "source": [ - "var log = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n(log.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" - ], - }, - { - "cell_type": "markdown", - "source": [ - "# Test Load Data Node Parameter" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var gic2 = \"gic2\";", - "\nvar xgic = \"xgic\";", - "\nvar gric1 = \"gric1\";" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "public async Task CheckLoadInterDataNodeParameterAsync(Args args, IEnumerable testData, ", - "\n int previousYear,", - "\n int? currentYear = null)", - "\n{", - "\n Activity.Start();", - "\n currentYear = currentYear ?? previousYear;", - "\n await Workspace.Partition.SetAsync(args);", - "\n await Workspace.UpdateAsync(testData);", - "\n ", - "\n var interDataNodeParameters = await LoadInterDataNodeParametersAsync(Workspace, args);", - "\n ", - "\n //Check Keys", - "\n var uniqueLinks = testData.Select(x => x.DataNode).Concat(testData.Select(x => x.LinkedDataNode)).ToHashSet();", - "\n uniqueLinks.Intersect(interDataNodeParameters.Keys).Count().Should().Be(uniqueLinks.Count());", - "\n ", - "\n //CheckInnerDictionaries", - "\n var currentYearData = testData.Where(x => x.Year == currentYear);", - "\n var previousYearData = testData.Where(x => x.Year == previousYear);", - "\n ", - "\n var errors = new List();", - "\n foreach(var dn in uniqueLinks)", - "\n {", - "\n //Set up BM counts", - "\n var currentLinks = currentYearData.Select(x => x.DataNode).Concat(currentYearData.Select(x => x.LinkedDataNode));", - "\n var currentLinksCount = currentLinks.Where(x => x == dn).Count();", - "\n var prevlinks = previousYearData.Select(x => x.DataNode).Concat(previousYearData.Select(x => x.LinkedDataNode));", - "\n var previousLinksCount = prevlinks.Where(x => x == dn).Count();", - "\n ", - "\n //Current Period", - "\n var computedCount = interDataNodeParameters[dn][CurrentPeriod].Count();", - "\n", - "\n if (currentYearData.Any())", - "\n {", - "\n if(computedCount != currentLinksCount)", - "\n errors.Add( $\"Current DataNode parameter count for {dn} not matching:\\n Expected {currentLinksCount} \\n Computed {computedCount}.\" );", - "\n }", - "\n else if(computedCount != previousLinksCount)", - "\n errors.Add( $\"Current DataNode parameter count for {dn} not matching:\\n Expected {previousLinksCount} \\n Computed {computedCount}.\" );", - "\n ", - "\n foreach (var param in interDataNodeParameters[dn][CurrentPeriod])", - "\n {", - "\n var linkedDn = param.DataNode == dn ? param.LinkedDataNode : param.DataNode;", - "\n var isLinkInPrevPeriod = previousYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn);", - "\n var isLinkInCurrPeriod = currentYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn); ", - "\n ", - "\n if(isLinkInPrevPeriod && !isLinkInCurrPeriod)", - "\n { ", - "\n if (param.ReinsuranceCoverage != ((double)previousYear)/1000)", - "\n errors.Add( $\"Current Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)previousYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", - "\n }", - "\n else if( param.ReinsuranceCoverage != ((double)currentYear)/1000)", - "\n errors.Add( $\"Current Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)currentYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", - "\n }", - "\n", - "\n //Previous Period", - "\n computedCount = interDataNodeParameters[dn][PreviousPeriod].Count();", - "\n ", - "\n if (currentYearData.Any())", - "\n {", - "\n if(computedCount != currentLinksCount)", - "\n errors.Add( $\"Previous DataNode parameter count for {dn} not matching:\\n Expected {currentLinksCount} \\n Computed {computedCount}.\" );", - "\n }", - "\n else if(computedCount != previousLinksCount)", - "\n errors.Add( $\"Previous DataNode parameter count for {dn} not matching:\\n Expected {previousLinksCount} \\n Computed {computedCount}.\" );", - "\n ", - "\n foreach (var param in interDataNodeParameters[dn][PreviousPeriod])", - "\n {", - "\n var linkedDn = param.DataNode == dn ? param.LinkedDataNode : param.DataNode;", - "\n var isLinkInPrevPeriod = previousYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn);", - "\n var isLinkInCurrPeriod = currentYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn); ", - "\n ", - "\n if(!isLinkInPrevPeriod && isLinkInCurrPeriod)", - "\n { ", - "\n if (param.ReinsuranceCoverage != ((double)currentYear)/1000)", - "\n errors.Add( $\"Previous Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)currentYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", - "\n }", - "\n else if( param.ReinsuranceCoverage != ((double)previousYear)/1000)", - "\n errors.Add( $\"Previous Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)previousYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", - "\n }", - "\n }", - "\n ", - "\n Workspace.Reset(x => x.ResetCurrentPartitions());", - "\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": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nint previousYear = 2019;", - "\nvar testData = new InterDataNodeParameter[] ", - "\n {new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gic2, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n };", - "\n", - "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nint previousYear = 2019;", - "\nint currentYear = 2020;", - "\nvar testData = new InterDataNodeParameter[] ", - "\n {", - "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9},", - "\n new InterDataNodeParameter{ DataNode = gic2, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9}, ", - "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9}, ", - "\n };", - "\n", - "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nint previousYear = 2019;", - "\nint currentYear = 2020;", - "\nvar testData = new InterDataNodeParameter[] ", - "\n {", - "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", - "\n };", - "\n", - "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nint previousYear = 2019;", - "\nint currentYear = 2020;", - "\nvar testData = new InterDataNodeParameter[] ", - "\n {", - "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 3}, ", - "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 3}, ", - "\n };", - "\n", - "\nvar log = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", - "\nlog" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "log.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - } - ] -} \ No newline at end of file From bd76591648a2d24d6e5e7318cdbad2c415f362e7 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 17:54:30 +0100 Subject: [PATCH 14/49] Take Sara's QueriesTest.nb --- ifrs17/Test/QueriesTest.ipynb | 856 ++++++++++++++++++++++++++++++++++ 1 file changed, 856 insertions(+) create mode 100644 ifrs17/Test/QueriesTest.ipynb diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb new file mode 100644 index 00000000..ad81d48b --- /dev/null +++ b/ifrs17/Test/QueriesTest.ipynb @@ -0,0 +1,856 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + }, + "toc-autonumbering": "True", + "toc-showcode": "False" + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "code", + "source": [ + "#!import \"../CalculationEngine\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var gic = \"DT1.1\";", + "\nvar scenario = \"MTUP\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Test Load Current and Previous Parameter for Yield Curve" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "Workspace.Reset(x => x.ResetInitializationRules().ResetCurrentPartitions());" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(Args args, IEnumerable testData, ", + "\n (int Year, int Month, string Scenario) expectedCurrentPeriod, ", + "\n (int Year, int Month, string Scenario) expectedPreviousPeriod)", + "\n{", + "\n Activity.Start();", + "\n await Workspace.UpdateAsync(testData);", + "\n var eurCurrentAndPreviousYieldCurve = (await Workspace.LoadCurrentAndPreviousParameterAsync(args, x => x.Currency))[\"EUR\"];", + "\n ", + "\n //Check Current Period", + "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Year.Should().Be(expectedCurrentPeriod.Year);", + "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Month.Should().Be(expectedCurrentPeriod.Month);", + "\n eurCurrentAndPreviousYieldCurve[CurrentPeriod].Scenario.Should().Be(expectedCurrentPeriod.Scenario);", + "\n ", + "\n //Check Previous Period", + "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Year.Should().Be(expectedPreviousPeriod.Year);", + "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Month.Should().Be(expectedPreviousPeriod.Month);", + "\n eurCurrentAndPreviousYieldCurve[PreviousPeriod].Scenario.Should().Be(expectedPreviousPeriod.Scenario);", + "\n ", + "\n await Workspace.DeleteAsync(Workspace.Query().ToArray());", + "\n return Activity.Finish();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2020, 9, null),(2020, 9, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new[] { new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9 } };", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario),(2020, 9, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData.RepeatOnce(), (2019, 12, null), (2019, 12, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2020, 6, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2019, 3, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2020, 9, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, null), (2019, 9, null));", + "\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": [ + "var args = new Args(\"EUR\",2020,9,Periodicity.Monthly,scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 9, scenario), (2019, 12, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 9, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 12, null), (2019, 12, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly, scenario);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = scenario},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 6, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2019, 6, null), (2019, 6, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2015, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Scenario = null}, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Scenario = null},", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Scenario = null}};", + "\n", + "\nvar activity = await CheckLoadCurrentAndPreviousParameterForYieldCurveAsync(args, testData, (2020, 6, null), (2016, 3, null));", + "\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": [ + "# Test Data Node State Query" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CheckLoadDataNodeStateAsync(Args args, IEnumerable testData, bool isExpectedToBeActive)", + "\n{", + "\n Activity.Start();", + "\n await Workspace.Partition.SetAsync(args);", + "\n await Workspace.UpdateAsync(testData);", + "\n var isActive = (await Workspace.LoadDataNodeStateAsync(args)).Keys.Contains(gic);", + "\n ", + "\n isActive.Should().Be(isExpectedToBeActive);", + "\n ", + "\n Workspace.Reset(x => x.ResetCurrentPartitions());", + "\n return Activity.Finish();", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", + "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2019, Month = 12, State = State.Active },", + "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 6, State = State.Inactive }};", + "\nvar activity = await CheckLoadDataNodeStateAsync(args, testData, false);", + "\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": [ + "var args = new Args(\"CH\",2020,12,Periodicity.Monthly,null);", + "\nvar testData = new DataNodeState[] {new DataNodeState{ DataNode = gic, Year = 2020, Month = 3, State = State.Active },", + "\n new DataNodeState{ DataNode = gic, Year = 2020, Month = 9, State = State.Inactive }};", + "\nvar activity = await CheckLoadDataNodeStateAsync(args, testData, false);", + "\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": [ + "# Test Load Yield Curve" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", + "\n (int year , int month, string yieldCurveName) dataNodeParameters, ", + "\n double expectedCurrentPreviousFirstYcValue,", + "\n double expectedCurrentFirstYcValue,", + "\n double expectedLockedFirstYcValue)", + "\n{", + "\n Activity.Start();", + "\n await Workspace.Partition.SetAsync(args);", + "\n await Workspace.UpdateAsync(testData);", + "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", + "\n ", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", + "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", + "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", + "\n ", + "\n Workspace.Reset(x => x.ResetCurrentPartitions());", + "\n ", + "\n var errors = new List();", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", + "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", + "\n ", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", + "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", + "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", + "\n ", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", + "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", + "\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": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\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": [ + "# Test Load Data Node Parameter" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var gic2 = \"gic2\";", + "\nvar xgic = \"xgic\";", + "\nvar gric1 = \"gric1\";" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public async Task CheckLoadInterDataNodeParameterAsync(Args args, IEnumerable testData, ", + "\n int previousYear,", + "\n int? currentYear = null)", + "\n{", + "\n Activity.Start();", + "\n currentYear = currentYear ?? previousYear;", + "\n await Workspace.Partition.SetAsync(args);", + "\n await Workspace.UpdateAsync(testData);", + "\n ", + "\n var interDataNodeParameters = await LoadInterDataNodeParametersAsync(Workspace, args);", + "\n ", + "\n //Check Keys", + "\n var uniqueLinks = testData.Select(x => x.DataNode).Concat(testData.Select(x => x.LinkedDataNode)).ToHashSet();", + "\n uniqueLinks.Intersect(interDataNodeParameters.Keys).Count().Should().Be(uniqueLinks.Count());", + "\n ", + "\n //CheckInnerDictionaries", + "\n var currentYearData = testData.Where(x => x.Year == currentYear);", + "\n var previousYearData = testData.Where(x => x.Year == previousYear);", + "\n ", + "\n var errors = new List();", + "\n foreach(var dn in uniqueLinks)", + "\n {", + "\n //Set up BM counts", + "\n var currentLinks = currentYearData.Select(x => x.DataNode).Concat(currentYearData.Select(x => x.LinkedDataNode));", + "\n var currentLinksCount = currentLinks.Where(x => x == dn).Count();", + "\n var prevlinks = previousYearData.Select(x => x.DataNode).Concat(previousYearData.Select(x => x.LinkedDataNode));", + "\n var previousLinksCount = prevlinks.Where(x => x == dn).Count();", + "\n ", + "\n //Current Period", + "\n var computedCount = interDataNodeParameters[dn][CurrentPeriod].Count();", + "\n", + "\n if (currentYearData.Any())", + "\n {", + "\n if(computedCount != currentLinksCount)", + "\n errors.Add( $\"Current DataNode parameter count for {dn} not matching:\\n Expected {currentLinksCount} \\n Computed {computedCount}.\" );", + "\n }", + "\n else if(computedCount != previousLinksCount)", + "\n errors.Add( $\"Current DataNode parameter count for {dn} not matching:\\n Expected {previousLinksCount} \\n Computed {computedCount}.\" );", + "\n ", + "\n foreach (var param in interDataNodeParameters[dn][CurrentPeriod])", + "\n {", + "\n var linkedDn = param.DataNode == dn ? param.LinkedDataNode : param.DataNode;", + "\n var isLinkInPrevPeriod = previousYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn);", + "\n var isLinkInCurrPeriod = currentYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn); ", + "\n ", + "\n if(isLinkInPrevPeriod && !isLinkInCurrPeriod)", + "\n { ", + "\n if (param.ReinsuranceCoverage != ((double)previousYear)/1000)", + "\n errors.Add( $\"Current Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)previousYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", + "\n }", + "\n else if( param.ReinsuranceCoverage != ((double)currentYear)/1000)", + "\n errors.Add( $\"Current Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)currentYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", + "\n }", + "\n", + "\n //Previous Period", + "\n computedCount = interDataNodeParameters[dn][PreviousPeriod].Count();", + "\n ", + "\n if (currentYearData.Any())", + "\n {", + "\n if(computedCount != currentLinksCount)", + "\n errors.Add( $\"Previous DataNode parameter count for {dn} not matching:\\n Expected {currentLinksCount} \\n Computed {computedCount}.\" );", + "\n }", + "\n else if(computedCount != previousLinksCount)", + "\n errors.Add( $\"Previous DataNode parameter count for {dn} not matching:\\n Expected {previousLinksCount} \\n Computed {computedCount}.\" );", + "\n ", + "\n foreach (var param in interDataNodeParameters[dn][PreviousPeriod])", + "\n {", + "\n var linkedDn = param.DataNode == dn ? param.LinkedDataNode : param.DataNode;", + "\n var isLinkInPrevPeriod = previousYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn);", + "\n var isLinkInCurrPeriod = currentYearData.Any(x => x.DataNode == dn && x.LinkedDataNode == linkedDn || x.DataNode == linkedDn && x.LinkedDataNode == dn); ", + "\n ", + "\n if(!isLinkInPrevPeriod && isLinkInCurrPeriod)", + "\n { ", + "\n if (param.ReinsuranceCoverage != ((double)currentYear)/1000)", + "\n errors.Add( $\"Previous Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)currentYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", + "\n }", + "\n else if( param.ReinsuranceCoverage != ((double)previousYear)/1000)", + "\n errors.Add( $\"Previous Reinsurance Coverage for {dn} linked to {linkedDn} not matching:\\n Expected {((double)previousYear)/1000} \\n Computed {param.ReinsuranceCoverage}.\" );", + "\n }", + "\n }", + "\n ", + "\n Workspace.Reset(x => x.ResetCurrentPartitions());", + "\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": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nint previousYear = 2019;", + "\nvar testData = new InterDataNodeParameter[] ", + "\n {new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gic2, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n };", + "\n", + "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear);", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nint previousYear = 2019;", + "\nint currentYear = 2020;", + "\nvar testData = new InterDataNodeParameter[] ", + "\n {", + "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9},", + "\n new InterDataNodeParameter{ DataNode = gic2, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9}, ", + "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 9}, ", + "\n };", + "\n", + "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nint previousYear = 2019;", + "\nint currentYear = 2020;", + "\nvar testData = new InterDataNodeParameter[] ", + "\n {", + "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)previousYear)/1000, Year = previousYear, Month = 3}, ", + "\n };", + "\n", + "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\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": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nint previousYear = 2019;", + "\nint currentYear = 2020;", + "\nvar testData = new InterDataNodeParameter[] ", + "\n {", + "\n new InterDataNodeParameter{ DataNode = gic, LinkedDataNode = gric1, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 3}, ", + "\n new InterDataNodeParameter{ DataNode = gric1, LinkedDataNode = xgic, ReinsuranceCoverage = ((double)currentYear)/1000, Year = currentYear, Month = 3}, ", + "\n };", + "\n", + "\nvar activity = await CheckLoadInterDataNodeParameterAsync(args, testData, previousYear, currentYear);", + "\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": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 2c7178bf6058306327c52bde32bf0aa77833cc6c Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 18:13:23 +0100 Subject: [PATCH 15/49] New try - QueriesTest.ipynb --- ifrs17/Test/QueriesTest.ipynb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index ad81d48b..f5ee4c80 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -528,7 +528,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month, string yieldCurveName) dataNodeParameters, ", + "\n (int year , int month, string yieldCurveName) dataNodeParameters,", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -542,13 +542,17 @@ "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", + "\n var errors = new List();", + "\n ", + "\n if (ApplicationMessage.HasErrors()) ", + "\n return Activity.Finish();", + "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", - "\n var errors = new List();", "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", - "\n ", + "\n", "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", @@ -556,7 +560,7 @@ "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\n ", + "\n ", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", "\n return Activity.Finish();", "\n}" From 06344ccbba5eac23c511b5899b2aa915fadea081 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 18:20:34 +0100 Subject: [PATCH 16/49] Bring back a test NO YieldCurve --- ifrs17/Test/QueriesTest.ipynb | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index f5ee4c80..964497f8 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -578,7 +578,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, null);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -598,12 +599,13 @@ "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} },", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -619,6 +621,32 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 2, \"A\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "(log.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ From 09e9c0c411588d097766e4d1dfb03257d7e4c934 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 18:20:34 +0100 Subject: [PATCH 17/49] Bring back a test NO YieldCurve --- ifrs17/Test/QueriesTest.ipynb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index f5ee4c80..3146fbf2 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -578,7 +578,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, null), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, null);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -598,12 +599,13 @@ "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} },", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6, \"A\"), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -619,6 +621,23 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 2, \"A\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(activity.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ From 1f2c093d989d75619adf0a44d7e9bc5d1ecfd38c Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 20 Dec 2022 18:53:57 +0100 Subject: [PATCH 18/49] Remove unneeded cell in QueriesTest.ipynb --- ifrs17/Test/QueriesTest.ipynb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index cd85b6eb..3146fbf2 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -638,15 +638,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "(log.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ From 37e029352d38a2aa0c5fa20dd6b95a14744475ee Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Wed, 21 Dec 2022 20:45:30 +0100 Subject: [PATCH 19/49] Test ValuationApproach + fix test numbers --- ifrs17/Test/QueriesTest.ipynb | 55 ++++++++++++++++++++++++----------- ifrs17/Utils/Queries.ipynb | 6 ++-- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 3146fbf2..ecc93641 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -528,7 +528,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month, string yieldCurveName) dataNodeParameters,", + "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters,", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -538,9 +538,9 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", - "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}}; ", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", + "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n ", "\n var errors = new List();", "\n ", @@ -548,21 +548,23 @@ "\n return Activity.Finish();", "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", - "\n ", + "\n ", "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", - "\n", + "\n ", "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", - "\n ", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" ); ", + "\n", + "\n var lockedYc = eurLockedYieldCurve.TryGetValue(gic, out var yieldCurve)", + "\n ? (yieldCurve?.Values.FirstOrDefault() ?? 0) ", + "\n : 0;", "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\n ", + "\n", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", - "\n return Activity.Finish();", + "\n return Activity.Finish(); ", "\n}" ], "metadata": {}, @@ -578,8 +580,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, null);", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -601,11 +603,29 @@ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 6, \"A\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", + "\nactivity" + ], + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" + ], + }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"VFA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 0);", "\nactivity" ], "metadata": {}, @@ -630,9 +650,10 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName) dataNodeParameters = (2016, 2, \"A\");", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", + "\n", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n(activity.Errors.Single().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" + "\n(activity.Errors.FirstOrDefault().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" ], "metadata": {}, "execution_count": 0, diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 21989289..6b3860f7 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,7 +189,7 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //RUSO : change dn.Month to MonthInAYear constant !!!!!!!!!", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", @@ -225,13 +225,13 @@ "\n foreach (var dn in dataNodes)", "\n {", "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", - "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(argsNew, ", "\n x => x.Currency,", "\n x => x.Currency == dn.ContractualCurrency ", "\n && (dn.ValuationApproach == ValuationApproaches.VFA ", "\n ? x.Name == dn.YieldCurveName ", "\n : true));", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null || currentYcDict.Values == null)", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null || currentYcDict?.Values == null)", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", From d2d8d9e09cef967bee7e7d24bd0e1d501b126da7 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 11:10:44 +0100 Subject: [PATCH 20/49] queries fix and reset QueriesTest --- ifrs17/Test/QueriesTest.ipynb | 104 +++++++--------------------------- ifrs17/Utils/Queries.ipynb | 2 +- 2 files changed, 23 insertions(+), 83 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index ecc93641..a7a95c10 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -26,6 +26,15 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "code", "source": [ @@ -528,7 +537,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters,", + "\n (int year , int month) dataNodeYearAndMonth, ", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -538,33 +547,27 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}}; ", - "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\"}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", - "\n ", - "\n var errors = new List();", - "\n ", - "\n if (ApplicationMessage.HasErrors()) ", - "\n return Activity.Finish();", + "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", "\n Workspace.Reset(x => x.ResetCurrentPartitions());", - "\n ", - "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", + "\n ", + "\n var errors = new List();", + "\n var currentPrevPeriod = eurCurrentYieldCurve[\"EUR\"][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", "\n ", - "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", + "\n var currentCurrPeriod = eurCurrentYieldCurve[\"EUR\"][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", - "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" ); ", - "\n", - "\n var lockedYc = eurLockedYieldCurve.TryGetValue(gic, out var yieldCurve)", - "\n ? (yieldCurve?.Values.FirstOrDefault() ?? 0) ", - "\n : 0;", + "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", + "\n ", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\n", + "\n ", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", - "\n return Activity.Finish(); ", + "\n return Activity.Finish();", "\n}" ], "metadata": {}, @@ -580,52 +583,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", - "\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": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", - "\nactivity" - ], - }, - { - "cell_type": "code", - "source": [ - "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" - ], - }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"VFA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 0);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6), 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -641,24 +599,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", - "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n(activity.Errors.FirstOrDefault().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "markdown", "source": [ diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 98d89f6e..8f75c43b 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -224,7 +224,7 @@ "\n ", "\n foreach (var dn in dataNodes)", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = dn.Scenario}; //MonthInAYear", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario}; //MonthInAYear", "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(argsNew, ", "\n x => x.Currency,", "\n x => x.Currency == dn.ContractualCurrency ", From 478c641b40a81173454b0fc51b2d173f84502b32 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 16:04:19 +0100 Subject: [PATCH 21/49] delete empty cell --- ifrs17/Test/QueriesTest.ipynb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index a7a95c10..0bf6dc5d 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -26,15 +26,6 @@ "execution_count": 0, "outputs": [] }, - { - "cell_type": "code", - "source": [ - "" - ], - "metadata": {}, - "execution_count": 0, - "outputs": [] - }, { "cell_type": "code", "source": [ From 2db0432afcc4da5f5c01709548334ff1bac856c8 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 16:35:33 +0100 Subject: [PATCH 22/49] change test substitude first --- ifrs17/Test/QueriesTest.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 0bf6dc5d..b0da6e73 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -528,7 +528,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month) dataNodeYearAndMonth, ", + "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters, ", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -538,7 +538,7 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=\"BBA\", Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\"}};", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", @@ -574,7 +574,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, (2016, 6), 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", "\nactivity" ], "metadata": {}, From fcc213dbfd3efbd12c80b12eeaf6568e214e7b39 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 16:50:55 +0100 Subject: [PATCH 23/49] second cell --- ifrs17/Test/QueriesTest.ipynb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index b0da6e73..9d927f51 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -591,6 +591,31 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", + "\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 0257c7b99da3b08d971a79786ff2c2170d87cd8a Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 16:55:04 +0100 Subject: [PATCH 24/49] last cell --- ifrs17/Test/QueriesTest.ipynb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 9d927f51..070de2ec 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -615,6 +615,24 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, +{ + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", + "\n", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(activity.Errors.FirstOrDefault().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] }, { "cell_type": "markdown", From d3b255340d9c4a53ca46ae8822bbbe04e7fee56e Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 23 Dec 2022 17:04:28 +0100 Subject: [PATCH 25/49] formatting like Alexey --- ifrs17/Test/QueriesTest.ipynb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 070de2ec..f1404e39 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -538,7 +538,7 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeYearAndMonth.year, Month = dataNodeYearAndMonth.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", @@ -553,7 +553,9 @@ "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n var lockedYc = eurLockedYieldCurve.TryGetValue(gic, out var yieldCurve)", + "\n ? (yieldCurve?.Values.FirstOrDefault() ?? 0) ", + "\n : 0;", "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", "\n ", @@ -591,7 +593,7 @@ "execution_count": 0, "outputs": [] }, - { + { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", @@ -603,7 +605,7 @@ "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", "\nactivity" ], - "metadata": {}, + "metadata": {}, "execution_count": 0, "outputs": [] }, @@ -612,11 +614,11 @@ "source": [ "activity.Status.Should().Be(ActivityLogStatus.Succeeded);" ], - "metadata": {}, + "metadata": {}, "execution_count": 0, "outputs": [] - }, -{ + }, + { "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", @@ -633,7 +635,7 @@ "metadata": {}, "execution_count": 0, "outputs": [] - }, + }, { "cell_type": "markdown", "source": [ From 7c86c0d510c4f405239b0f4940faa0414ba44b25 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 3 Jan 2023 14:30:52 +0100 Subject: [PATCH 26/49] fix test --- ifrs17/Test/QueriesTest.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index f1404e39..db141c63 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -545,11 +545,11 @@ "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", - "\n var currentPrevPeriod = eurCurrentYieldCurve[\"EUR\"][PreviousPeriod].Values.First();", + "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", "\n ", - "\n var currentCurrPeriod = eurCurrentYieldCurve[\"EUR\"][CurrentPeriod].Values.First();", + "\n var currentCurrPeriod = eurCurrentYieldCurve[gic][CurrentPeriod].Values.First();", "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", From d315ee8fcdde231d7fab8e40afd234f2997073cd Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 3 Jan 2023 14:55:40 +0100 Subject: [PATCH 27/49] lean up tests --- ifrs17/Test/QueriesTest.ipynb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index db141c63..cee8e378 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -545,6 +545,8 @@ "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", + "\n if (eurCurrentYieldCurve[gic] == null || eurLockedYieldCurve[gic] == null)", + "\n return Activity.Finish();", "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Previous Period not matching:\\n Expected {expectedCurrentPreviousFirstYcValue} \\n Computed {currentPrevPeriod}.\" );", @@ -553,9 +555,7 @@ "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", - "\n var lockedYc = eurLockedYieldCurve.TryGetValue(gic, out var yieldCurve)", - "\n ? (yieldCurve?.Values.FirstOrDefault() ?? 0) ", - "\n : 0;", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", "\n ", @@ -630,7 +630,17 @@ "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", "\n", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\n(activity.Errors.FirstOrDefault().ToString().Contains(Get(Error.YieldCurveNotFound))).Should().Be(true);" + "\nactivity" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "activity.Status.Should().Be(ActivityLogStatus.Failed);", + "\nactivity.Errors.Select(x => x.ToString().Contains(Get(Error.YieldCurveNotFound)).Should().Be(true));" ], "metadata": {}, "execution_count": 0, From 29280bd6833c062836771922210297c5e312df6b Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 3 Jan 2023 15:00:07 +0100 Subject: [PATCH 28/49] MonthInAYear --- ifrs17/Utils/Queries.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 8f75c43b..0a6a6db8 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,7 +189,7 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario};", + "\n var argsNew = args with {Year = dn.Year, Month = MonthInAYear, Scenario = args.Scenario};", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", @@ -224,7 +224,7 @@ "\n ", "\n foreach (var dn in dataNodes)", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario}; //MonthInAYear", + "\n var argsNew = args with {Year = dn.Year, Month = MonthInAYear, Scenario = args.Scenario};", "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(argsNew, ", "\n x => x.Currency,", "\n x => x.Currency == dn.ContractualCurrency ", From 4291380806b0add63f4358a4d6c85f6ee5659c5d Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 3 Jan 2023 15:41:03 +0100 Subject: [PATCH 29/49] delete print Activity --- ifrs17/Test/QueriesTest.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index cee8e378..ae63f597 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -629,8 +629,7 @@ "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", - "\nactivity" + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);" ], "metadata": {}, "execution_count": 0, From 37375c8283d90d4da283c7298c0b86c90a0ac4d6 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 3 Jan 2023 15:43:56 +0100 Subject: [PATCH 30/49] reset validations --- ifrs17/Constants/Validations.ipynb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ifrs17/Constants/Validations.ipynb b/ifrs17/Constants/Validations.ipynb index 40c76ea5..64a58f8c 100644 --- a/ifrs17/Constants/Validations.ipynb +++ b/ifrs17/Constants/Validations.ipynb @@ -158,7 +158,6 @@ "\n (Error.MissingPremiumAllocation , 1) => $\"Premium Allocation Rate not found for Group of Contract {s[0]}.\", // TODO: this is now a warning to be produced by a validation in the importers (default is 1)", "\n (Error.ReinsuranceCoverage , 1) => $\"Reinsurance Allocation Rate not found for Group of Insurance Contract {s[0]}.\",", "\n (Error.YieldCurveNotFound , 3) => $\"Yield Curve not found for currency {s[0]}, year {s[1]}, and month {s[2]}.\",", - "\n (Error.YieldCurveNotFound , 0) => $\"Yield Curve not found\",", "\n (Error.YieldCurvePeriodNotApplicable , 2) => $\"YieldCurve period NotApplicable not valid for AoC Step with AoC Type {s[0]} and Novelty {s[1]}.\",", "\n (Error.EconomicBasisNotFound , 1) => $\"EconomicBasis not valid for DataNode {s[0]}.\",", "\n (Error.AccountingVariableTypeNotFound , 1) => $\"AccountingVariableType {s[0]} not found.\",", @@ -193,6 +192,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file From 89f439418a2824a9c04fad16cf3c1911a8808f31 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Thu, 5 Jan 2023 16:47:01 +0100 Subject: [PATCH 31/49] update Storage --- ifrs17/Import/ImportStorage.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ifrs17/Import/ImportStorage.ipynb b/ifrs17/Import/ImportStorage.ipynb index 3bce6f0b..bc20e709 100644 --- a/ifrs17/Import/ImportStorage.ipynb +++ b/ifrs17/Import/ImportStorage.ipynb @@ -301,7 +301,7 @@ "\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", "\n //YieldCurve", "\n public double[] GetYearlyYieldCurve(ImportIdentity id, string economicBasis) {", "\n var yc = GetYieldCurve(id, economicBasis);", @@ -309,13 +309,13 @@ "\n }", "\n ", "\n public YieldCurve GetYieldCurve(ImportIdentity id, string economicBasis) => (economicBasis, GetYieldCurvePeriod(id)) switch {", - "\n (EconomicBases.C, PeriodType.BeginningOfPeriod) => CurrentYieldCurve[DataNodeDataBySystemName[id.DataNode].ContractualCurrency][PreviousPeriod],", - "\n (EconomicBases.C, PeriodType.EndOfPeriod) => CurrentYieldCurve[DataNodeDataBySystemName[id.DataNode].ContractualCurrency][CurrentPeriod],", + "\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", "\n //int Identity.ProjectionPeriod ", "\n public int GetProjectionCount() => ProjectionConfiguration.Count();", "\n public int GetShift(int projectionPeriod) => ProjectionConfiguration[projectionPeriod].Shift;", From e8337738e10920cf13843a6967d0fc2b0b6de71e Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 6 Jan 2023 16:56:17 +0100 Subject: [PATCH 32/49] fix test and new query --- ifrs17-template/Test/ImportStorageTest.ipynb | 12 ++++++------ ifrs17/Utils/Queries.ipynb | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ifrs17-template/Test/ImportStorageTest.ipynb b/ifrs17-template/Test/ImportStorageTest.ipynb index 11c212dd..523c51f4 100644 --- a/ifrs17-template/Test/ImportStorageTest.ipynb +++ b/ifrs17-template/Test/ImportStorageTest.ipynb @@ -427,15 +427,15 @@ "cell_type": "code", "source": [ "var sampleGic = new GroupOfInsuranceContract(){Portfolio = \"P1\"};", - "\nvar inputDataGic = new GroupOfInsuranceContract[]{ sampleGic with {SystemName = \"Gross1\", LiabilityType = LiabilityTypes.LRC},", - "\n sampleGic with {SystemName = \"Gross2\", LiabilityType = LiabilityTypes.LRC},", - "\n sampleGic with {SystemName = \"Gross3\", LiabilityType = LiabilityTypes.LRC},", + "\nvar inputDataGic = new GroupOfInsuranceContract[]{ sampleGic with {SystemName = \"Gross1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\n sampleGic with {SystemName = \"Gross2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\n sampleGic with {SystemName = \"Gross3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", "\n };", "\n", "\nvar sampleGric = new GroupOfReinsuranceContract(){Portfolio = \"ReP1\"};", - "\nvar inputDataGric = new GroupOfReinsuranceContract[]{ sampleGric with {SystemName = \"Reins1\", LiabilityType = LiabilityTypes.LRC},", - "\n sampleGric with {SystemName = \"Reins2\", LiabilityType = LiabilityTypes.LRC},", - "\n sampleGric with {SystemName = \"Reins3\", LiabilityType = LiabilityTypes.LRC},", + "\nvar inputDataGric = new GroupOfReinsuranceContract[]{ sampleGric with {SystemName = \"Reins1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\n sampleGric with {SystemName = \"Reins2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\n sampleGric with {SystemName = \"Reins3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", "\n };", "\nvar sampleDnState = new DataNodeState {Partition = reportingNodePartition.Id, Year = args.Year, Month = args.Month, State = State.Active};", "\nvar inputDataState = new DataNodeState[]{ sampleDnState with {DataNode = \"Gross1\"} ,", diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 0a6a6db8..462da19c 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,7 +189,7 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = MonthInAYear, Scenario = args.Scenario};", + "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario};", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", @@ -224,15 +224,14 @@ "\n ", "\n foreach (var dn in dataNodes)", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = MonthInAYear, Scenario = args.Scenario};", - "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(argsNew, ", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", "\n x => x.Currency == dn.ContractualCurrency ", "\n && (dn.ValuationApproach == ValuationApproaches.VFA ", "\n ? x.Name == dn.YieldCurveName ", "\n : true));", "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null || currentYcDict?.Values == null)", - "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", + "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, args.Year.ToString(), args.Month.ToString());", "\n ", "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", "\n }", From 145ebb8774bb343745e250479ca1795d4bbbf429 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 6 Jan 2023 17:03:10 +0100 Subject: [PATCH 33/49] string typo --- ifrs17-template/Test/ImportStorageTest.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ifrs17-template/Test/ImportStorageTest.ipynb b/ifrs17-template/Test/ImportStorageTest.ipynb index 523c51f4..73c83161 100644 --- a/ifrs17-template/Test/ImportStorageTest.ipynb +++ b/ifrs17-template/Test/ImportStorageTest.ipynb @@ -427,15 +427,15 @@ "cell_type": "code", "source": [ "var sampleGic = new GroupOfInsuranceContract(){Portfolio = \"P1\"};", - "\nvar inputDataGic = new GroupOfInsuranceContract[]{ sampleGic with {SystemName = \"Gross1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", - "\n sampleGic with {SystemName = \"Gross2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", - "\n sampleGic with {SystemName = \"Gross3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\nvar inputDataGic = new GroupOfInsuranceContract[]{ sampleGic with {SystemName = \"Gross1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", + "\n sampleGic with {SystemName = \"Gross2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", + "\n sampleGic with {SystemName = \"Gross3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", "\n };", "\n", "\nvar sampleGric = new GroupOfReinsuranceContract(){Portfolio = \"ReP1\"};", - "\nvar inputDataGric = new GroupOfReinsuranceContract[]{ sampleGric with {SystemName = \"Reins1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", - "\n sampleGric with {SystemName = \"Reins2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", - "\n sampleGric with {SystemName = \"Reins3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \\\"CHF\\\", ValuationApproach = \\\"BBA\\\"},", + "\nvar inputDataGric = new GroupOfReinsuranceContract[]{ sampleGric with {SystemName = \"Reins1\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", + "\n sampleGric with {SystemName = \"Reins2\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", + "\n sampleGric with {SystemName = \"Reins3\", LiabilityType = LiabilityTypes.LRC, ContractualCurrency = \"CHF\", ValuationApproach = \"BBA\"},", "\n };", "\nvar sampleDnState = new DataNodeState {Partition = reportingNodePartition.Id, Year = args.Year, Month = args.Month, State = State.Active};", "\nvar inputDataState = new DataNodeState[]{ sampleDnState with {DataNode = \"Gross1\"} ,", From 0721c04e3dc772f05e3f86a72e6a7dba08e47dec Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 6 Jan 2023 17:19:37 +0100 Subject: [PATCH 34/49] updated test. all green --- ifrs17/Test/QueriesTest.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index ae63f597..7e08c16d 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -577,7 +577,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -602,7 +602,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 6.1, 6.1);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, From 191e14f319a8a25a6af126b313f7c6aa0192b4df Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Mon, 9 Jan 2023 10:20:48 +0100 Subject: [PATCH 35/49] update test to consider other valuation approaches than BBA --- ifrs17/Test/QueriesTest.ipynb | 40 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 7e08c16d..d48d5a96 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -545,7 +545,7 @@ "\n Workspace.Reset(x => x.ResetCurrentPartitions());", "\n ", "\n var errors = new List();", - "\n if (eurCurrentYieldCurve[gic] == null || eurLockedYieldCurve[gic] == null)", + "\n if (eurCurrentYieldCurve[gic] == null)", "\n return Activity.Finish();", "\n var currentPrevPeriod = eurCurrentYieldCurve[gic][PreviousPeriod].Values.First();", "\n if(Math.Abs(currentPrevPeriod - expectedCurrentPreviousFirstYcValue) > 1E-8)", @@ -555,10 +555,14 @@ "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", - "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", - "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", - "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", - "\n ", + "\n if(dataNodeParameters.valuationApproach == ValuationApproaches.BBA)", + "\n {", + "\n if (eurLockedYieldCurve[gic] == null)", + "\n return Activity.Finish();", + "\n var lockedYc = eurLockedYieldCurve[gic].Values.First();", + "\n if(Math.Abs(lockedYc - expectedLockedFirstYcValue) > 1E-8)", + "\n errors.Add( $\"LockedIn YieldCurve not matching:\\n Expected {expectedLockedFirstYcValue} \\n Computed {lockedYc}.\" );", + "\n }", "\n if(errors.Any()) ApplicationMessage.Log(Error.Generic, string.Join(\"\\n\", errors)); ", "\n return Activity.Finish();", "\n}" @@ -618,6 +622,32 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"VFA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\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": [ From 25b6180a736d862c86da54eaac9ededa3b7cf26c Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Mon, 9 Jan 2023 14:54:14 +0100 Subject: [PATCH 36/49] Get rid of meaningless check ups (data that we get must consist of the yield curves information) --- ifrs17/Utils/Queries.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 462da19c..1bbf178c 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -192,7 +192,7 @@ "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario};", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", - "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc) || lockedYc == null)", + "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, argsNew.Year.ToString(), argsNew.Month.ToString());", "\n ", "\n lockedInYieldCurveByGoc[dn.DataNode] = lockedYc;", @@ -230,7 +230,7 @@ "\n && (dn.ValuationApproach == ValuationApproaches.VFA ", "\n ? x.Name == dn.YieldCurveName ", "\n : true));", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict) || currentYcDict == null || currentYcDict?.Values == null)", + "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict))", "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, args.Year.ToString(), args.Month.ToString());", "\n ", "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", From 1267df7e014108b070e19949514319a6653056a3 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 10 Jan 2023 11:16:19 +0100 Subject: [PATCH 37/49] Rename dataNodeParameters -> dataNodeTestData --- ifrs17/Test/QueriesTest.ipynb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index d48d5a96..7620b264 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -528,7 +528,7 @@ "cell_type": "code", "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", - "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters, ", + "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData, ", "\n double expectedCurrentPreviousFirstYcValue,", "\n double expectedCurrentFirstYcValue,", "\n double expectedLockedFirstYcValue)", @@ -538,7 +538,7 @@ "\n await Workspace.UpdateAsync(testData);", "\n await Workspace.UpdateAsync(new ReportingNode[]{new ReportingNode{Currency=\"EUR\",SystemName=\"CH\"}});", "\n ", - "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeParameters.valuationApproach, Year = dataNodeParameters.year, Month = dataNodeParameters.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeParameters.yieldCurveName}};", + "\n var dataNodes = new DataNodeData[]{new DataNodeData{ValuationApproach=dataNodeTestData.valuationApproach, Year = dataNodeTestData.year, Month = dataNodeTestData.month, DataNode = gic, ContractualCurrency = \"EUR\", YieldCurveName = dataNodeTestData.yieldCurveName}};", "\n var eurLockedYieldCurve = (await LoadLockedInYieldCurveAsync(Workspace, args, dataNodes));", "\n var eurCurrentYieldCurve = (await LoadCurrentYieldCurveAsync(Workspace, args, dataNodes));", "\n ", @@ -555,7 +555,7 @@ "\n if(Math.Abs(currentCurrPeriod - expectedCurrentFirstYcValue) > 1E-8)", "\n errors.Add( $\"Current YieldCurve for Current Period not matching:\\n Expected {expectedCurrentFirstYcValue} \\n Computed {currentCurrPeriod}.\" );", "\n ", - "\n if(dataNodeParameters.valuationApproach == ValuationApproaches.BBA)", + "\n if(dataNodeTestData.valuationApproach == ValuationApproaches.BBA)", "\n {", "\n if (eurLockedYieldCurve[gic] == null)", "\n return Activity.Finish();", @@ -580,8 +580,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, null, \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -605,8 +605,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, \"A\", \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -631,8 +631,8 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 6, null, \"VFA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, null, \"VFA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", "\nactivity" ], "metadata": {}, @@ -657,9 +657,9 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"C\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeParameters = (2016, 2, \"A\", \"BBA\");", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 2, \"A\", \"BBA\");", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeParameters, 6.1, 0.1, 6.1);" + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);" ], "metadata": {}, "execution_count": 0, From 0c48535549f688c320375951068511d8ddc8af0a Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Tue, 10 Jan 2023 11:48:52 +0100 Subject: [PATCH 38/49] Don't enter BM to the failing test, set default expected values --- ifrs17/Test/QueriesTest.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 7620b264..0a48934e 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -529,9 +529,9 @@ "source": [ "public async Task CheckLoadYieldCurveAsync(Args args, IEnumerable testData, ", "\n (int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData, ", - "\n double expectedCurrentPreviousFirstYcValue,", - "\n double expectedCurrentFirstYcValue,", - "\n double expectedLockedFirstYcValue)", + "\n double expectedCurrentPreviousFirstYcValue = default(double),", + "\n double expectedCurrentFirstYcValue = default(double),", + "\n double expectedLockedFirstYcValue = default(double))", "\n{", "\n Activity.Start();", "\n await Workspace.Partition.SetAsync(args);", @@ -659,7 +659,7 @@ "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 2, \"A\", \"BBA\");", "\n", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);" + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData);" ], "metadata": {}, "execution_count": 0, From 1e79fe23c322da09f313671a18622098e3922c22 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 10 Jan 2023 14:14:44 +0100 Subject: [PATCH 39/49] properly test VFA --- ifrs17/Test/QueriesTest.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 0a48934e..1431c53e 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -626,13 +626,12 @@ "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Name = \"A\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", - "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, null, \"VFA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"VFA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1);", "\nactivity" ], "metadata": {}, From 42a8d79a21b9aa7425c228de35c636b470e58e5a Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 10 Jan 2023 14:20:36 +0100 Subject: [PATCH 40/49] modify VFA test --- ifrs17/Test/QueriesTest.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 1431c53e..478d9f7a 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -627,9 +627,10 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Name = \"A\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", - "\n", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} }};", + "\n ", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"VFA\");", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1);", "\nactivity" From 435f547bf5d96ea83fa78ed79bbdf08dd8557fe2 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Tue, 10 Jan 2023 14:42:33 +0100 Subject: [PATCH 41/49] last comment Davide --- ifrs17/Test/QueriesTest.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 478d9f7a..2442fbea 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -576,9 +576,11 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2021, Month = 9, Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{9.1,9.2,9.3,9.4,9.5,9.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, null, \"BBA\");", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", From 4ffa435fd77bd5ee6afc1a367fb5332e8370f104 Mon Sep 17 00:00:00 2001 From: AlekseiNekrasov Date: Wed, 11 Jan 2023 12:41:59 +0100 Subject: [PATCH 42/49] Fix last YC test --- ifrs17/Utils/Queries.ipynb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index 1bbf178c..d12aa4c7 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -221,21 +221,30 @@ "\n IEnumerable dataNodes)", "\n{ ", "\n var currentYieldCurveByGoc = new Dictionary>();", + "\n", + "\n var dnDict = dataNodes.ToDictionaryGrouped(x => x.ValuationApproach, x => x.ToDictionaryGrouped(u => (u.ContractualCurrency, u.YieldCurveName), u => u.Select(y => y.DataNode).ToArray()));", "\n ", - "\n foreach (var dn in dataNodes)", + "\n foreach (var va in dnDict.Keys)", "\n {", - "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n foreach (var key in dnDict[va].Keys)", + "\n {", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", - "\n x => x.Currency == dn.ContractualCurrency ", - "\n && (dn.ValuationApproach == ValuationApproaches.VFA ", - "\n ? x.Name == dn.YieldCurveName ", - "\n : true));", - "\n if(!loadedYc.TryGetValue(dn.ContractualCurrency, out var currentYcDict))", - "\n ApplicationMessage.Log(Error.YieldCurveNotFound, dn.ContractualCurrency, args.Year.ToString(), args.Month.ToString());", - "\n ", - "\n currentYieldCurveByGoc[dn.DataNode] = currentYcDict;", + "\n x => x.Currency == key.Item1 ", + "\n && (va == ValuationApproaches.VFA", + "\n ? x.Name == key.Item2", + "\n : true));", + "\n ", + "\n if (!loadedYc.TryGetValue(key.Item1, out var currentYcDict))", + "\n ApplicationMessage.Log(Error.YieldCurveNotFound, key.Item1, args.Year.ToString(), args.Month.ToString());", + "\n", + "\n foreach(var dn in dnDict[va][key])", + "\n {", + "\n currentYieldCurveByGoc[dn] = loadedYc[key.Item1];", + "\n }", + "\n }", "\n }", - "\n ", + "\n ", "\n return currentYieldCurveByGoc;", "\n}" ], From a48caff380a0f5d469cb7fb94f80be768bb20552 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Wed, 11 Jan 2023 14:22:50 +0100 Subject: [PATCH 43/49] improve test for different currencies --- ifrs17/Test/QueriesTest.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 2442fbea..b79ad841 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -604,8 +604,11 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"CHF\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{3.1,3.2,3.3,3.4,3.5,3.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} },", + "\n new YieldCurve{ Currency = \"CHF\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{8.1,8.2,8.3,8.4,8.5,8.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", From 1e55cd0ec35fd0f19a7e87fe5c748dba74467fb2 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Wed, 11 Jan 2023 15:16:12 +0100 Subject: [PATCH 44/49] renaming and avoid extra loop --- ifrs17/Utils/Queries.ipynb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index d12aa4c7..dfea043f 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -222,26 +222,26 @@ "\n{ ", "\n var currentYieldCurveByGoc = new Dictionary>();", "\n", - "\n var dnDict = dataNodes.ToDictionaryGrouped(x => x.ValuationApproach, x => x.ToDictionaryGrouped(u => (u.ContractualCurrency, u.YieldCurveName), u => u.Select(y => y.DataNode).ToArray()));", + "\n var dnByVaCurrYc = dataNodes.ToDictionaryGrouped(x => (x.ValuationApproach, x.ContractualCurrency, x.YieldCurveName), x => x.Select(y => y.DataNode).ToArray());", "\n ", - "\n foreach (var va in dnDict.Keys)", + "\n foreach (var key in dnByVaCurrYc.Keys)", "\n {", - "\n foreach (var key in dnDict[va].Keys)", - "\n {", - "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", - "\n x => x.Currency,", - "\n x => x.Currency == key.Item1 ", - "\n && (va == ValuationApproaches.VFA", - "\n ? x.Name == key.Item2", - "\n : true));", - "\n ", - "\n if (!loadedYc.TryGetValue(key.Item1, out var currentYcDict))", - "\n ApplicationMessage.Log(Error.YieldCurveNotFound, key.Item1, args.Year.ToString(), args.Month.ToString());", + "\n var valuationApproach = key.Item1;", + "\n var contractualCurrency = key.Item2;", + "\n var yieldCurveName = key.Item3;", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n x => x.Currency,", + "\n x => x.Currency == contractualCurrency ", + "\n && (valuationApproach == ValuationApproaches.VFA", + "\n ? x.Name == yieldCurveName", + "\n : true));", + "\n ", + "\n if (!loadedYc.TryGetValue(contractualCurrency, out var currentYcDict))", + "\n ApplicationMessage.Log(Error.YieldCurveNotFound, contractualCurrency, args.Year.ToString(), args.Month.ToString());", "\n", - "\n foreach(var dn in dnDict[va][key])", - "\n {", - "\n currentYieldCurveByGoc[dn] = loadedYc[key.Item1];", - "\n }", + "\n foreach(var dn in dnByVaCurrYc[key])", + "\n {", + "\n currentYieldCurveByGoc[dn] = loadedYc[contractualCurrency];", "\n }", "\n }", "\n ", From 30958f48a620e1f4840ddf4d1301c154121fcc9e Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Wed, 11 Jan 2023 15:54:01 +0100 Subject: [PATCH 45/49] rename and nominalized tuple --- ifrs17/Utils/Queries.ipynb | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index dfea043f..f94c0a42 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -222,26 +222,24 @@ "\n{ ", "\n var currentYieldCurveByGoc = new Dictionary>();", "\n", - "\n var dnByVaCurrYc = dataNodes.ToDictionaryGrouped(x => (x.ValuationApproach, x.ContractualCurrency, x.YieldCurveName), x => x.Select(y => y.DataNode).ToArray());", + "\n var dnByValAppContrCurrYcName = dataNodes.ToDictionaryGrouped(x => (ValuationApproach: x.ValuationApproach, ContractualCurrency: x.ContractualCurrency, YieldCurveName: x.YieldCurveName), ", + "\n x => x.Select(y => y.DataNode).ToArray());", "\n ", - "\n foreach (var key in dnByVaCurrYc.Keys)", + "\n foreach (var key in dnByValAppContrCurrYcName.Keys)", "\n {", - "\n var valuationApproach = key.Item1;", - "\n var contractualCurrency = key.Item2;", - "\n var yieldCurveName = key.Item3;", - "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", + "\n var loadedYc = await querySource.LoadCurrentAndPreviousParameterAsync(args, ", "\n x => x.Currency,", - "\n x => x.Currency == contractualCurrency ", - "\n && (valuationApproach == ValuationApproaches.VFA", - "\n ? x.Name == yieldCurveName", + "\n x => x.Currency == key.ContractualCurrency ", + "\n && (key.ValuationApproach == ValuationApproaches.VFA", + "\n ? x.Name == key.YieldCurveName", "\n : true));", "\n ", - "\n if (!loadedYc.TryGetValue(contractualCurrency, out var currentYcDict))", - "\n ApplicationMessage.Log(Error.YieldCurveNotFound, contractualCurrency, args.Year.ToString(), args.Month.ToString());", + "\n if (!loadedYc.TryGetValue(key.ContractualCurrency, out var currentYcDict))", + "\n ApplicationMessage.Log(Error.YieldCurveNotFound, key.ContractualCurrency, args.Year.ToString(), args.Month.ToString());", "\n", - "\n foreach(var dn in dnByVaCurrYc[key])", + "\n foreach(var dn in dnByValAppContrCurrYcName[key])", "\n {", - "\n currentYieldCurveByGoc[dn] = loadedYc[contractualCurrency];", + "\n currentYieldCurveByGoc[dn] = loadedYc[key.ContractualCurrency];", "\n }", "\n }", "\n ", From 2a4a93bc31026a7fa3ea3c3e30f808addd3181da Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Thu, 12 Jan 2023 10:49:16 +0100 Subject: [PATCH 46/49] test improved --- ifrs17/Test/QueriesTest.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index b79ad841..7fea84e5 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -604,9 +604,11 @@ "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Values = new double[]{1.1,1.2,1.3,1.4,1.5,1.6} }, ", "\n new YieldCurve{ Currency = \"CHF\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{3.1,3.2,3.3,3.4,3.5,3.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{9.1,9.2,9.3,9.4,9.5,9.6} },", "\n new YieldCurve{ Currency = \"CHF\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{8.1,8.2,8.3,8.4,8.5,8.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }};", "\n", From 88d351936dfbd06f8078e37d35fc38e4bcd275d8 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Thu, 12 Jan 2023 11:30:27 +0100 Subject: [PATCH 47/49] extra test different years months --- ifrs17/Test/QueriesTest.ipynb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 7fea84e5..817f23b7 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -610,7 +610,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Values = new double[]{9.1,9.2,9.3,9.4,9.5,9.6} },", "\n new YieldCurve{ Currency = \"CHF\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{8.1,8.2,8.3,8.4,8.5,8.6} },", - "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"B\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }};", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"B\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 6.1, 0.1, 6.1);", @@ -629,6 +629,35 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "code", + "source": [ + "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Name = \"A\", Values = new double[]{1.1,1.2,1.3,1.4,1.5,1.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Name = \"A\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Name = \"A\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 6, Name = \"A\", Values = new double[]{3.1,3.2,3.3,3.4,3.5,3.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2017, Month = 6, Name = \"A\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", + "\n", + "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 2.1, 0.1, 6.1);", + "\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": [ From b4c37d6380ee6906b24dc0459cd31dbddaa8c415 Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 13 Jan 2023 09:12:27 +0100 Subject: [PATCH 48/49] MonthInAYiear and its test --- ifrs17/Test/QueriesTest.ipynb | 3 ++- ifrs17/Utils/Queries.ipynb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index 817f23b7..e3b1d03a 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -639,10 +639,11 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Name = \"A\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 6, Name = \"A\", Values = new double[]{3.1,3.2,3.3,3.4,3.5,3.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2017, Month = 6, Name = \"A\", Values = new double[]{4.1,4.2,4.3,4.4,4.5,4.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 12, Name = \"A\", Values = new double[]{8.1,8.2,8.3,8.4,8.5,8.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 2.1, 0.1, 6.1);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 2.1, 0.1, 8.1);", "\nactivity" ], "metadata": {}, diff --git a/ifrs17/Utils/Queries.ipynb b/ifrs17/Utils/Queries.ipynb index f94c0a42..2a102c0f 100644 --- a/ifrs17/Utils/Queries.ipynb +++ b/ifrs17/Utils/Queries.ipynb @@ -189,7 +189,7 @@ "\n var lockedInYieldCurveByGoc = new Dictionary();", "\n foreach (var dn in dataNodes.Where(x => x.ValuationApproach == ValuationApproaches.BBA))", "\n {", - "\n var argsNew = args with {Year = dn.Year, Month = dn.Month, Scenario = args.Scenario};", + "\n var argsNew = args with {Year = dn.Year, Month = MonthInAYear, Scenario = args.Scenario};", "\n var loadedYc = (await querySource.LoadCurrentParameterAsync(argsNew, x => x.Currency, x => x.Currency == dn.ContractualCurrency && x.Name == dn.YieldCurveName));", "\n ", "\n if (!loadedYc.TryGetValue(dn.ContractualCurrency, out var lockedYc))", From 9c5292fc189c223662d0101a5197e2e7f9717c1d Mon Sep 17 00:00:00 2001 From: Sara Colella Date: Fri, 13 Jan 2023 09:30:24 +0100 Subject: [PATCH 49/49] test improved --- ifrs17/Test/QueriesTest.ipynb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ifrs17/Test/QueriesTest.ipynb b/ifrs17/Test/QueriesTest.ipynb index e3b1d03a..d48841bd 100644 --- a/ifrs17/Test/QueriesTest.ipynb +++ b/ifrs17/Test/QueriesTest.ipynb @@ -633,8 +633,12 @@ "cell_type": "code", "source": [ "var args = new Args(\"CH\",2020,9,Periodicity.Monthly,null);", - "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{0.1,0.2,0.3,0.4,0.5,0.6} }, ", + "\nvar testData = new YieldCurve[] {new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 12, Name = \"A\", Values = new double[]{11.1,11.2,11.3,11.4,11.5,11.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 9, Name = \"A\", Values = new double[]{12.1,12.2,12.3,12.4,12.5,12.6} },", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 6, Name = \"A\", Values = new double[]{13.1,13.2,13.3,13.4,13.5,13.6} },", "\n new YieldCurve{ Currency = \"EUR\", Year = 2020, Month = 3, Name = \"A\", Values = new double[]{1.1,1.2,1.3,1.4,1.5,1.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 12, Name = \"A\", Values = new double[]{9.1,9.2,9.3,9.4,9.5,9.6} }, ", + "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 9, Name = \"A\", Values = new double[]{10.1,10.2,10.3,10.4,10.5,10.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 6, Name = \"A\", Values = new double[]{2.1,2.2,2.3,2.4,2.5,2.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2019, Month = 3, Name = \"A\", Values = new double[]{7.1,7.2,7.3,7.4,7.5,7.6} }, ", "\n new YieldCurve{ Currency = \"EUR\", Year = 2018, Month = 6, Name = \"A\", Values = new double[]{3.1,3.2,3.3,3.4,3.5,3.6} },", @@ -643,7 +647,7 @@ "\n new YieldCurve{ Currency = \"EUR\", Year = 2016, Month = 3, Name = \"A\", Values = new double[]{6.1,6.2,6.3,6.4,6.5,6.6} }};", "\n", "\n(int year , int month, string yieldCurveName, string valuationApproach) dataNodeTestData = (2016, 6, \"A\", \"BBA\");", - "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 2.1, 0.1, 8.1);", + "\nvar activity = await CheckLoadYieldCurveAsync(args, testData, dataNodeTestData, 9.1, 12.1, 8.1);", "\nactivity" ], "metadata": {},