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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ifrs17/Constants/Validations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"\n NotSupportedAocStepReference, MultipleEoP,",
"\n // Data completeness",
"\n MissingDataAtPosting, MissingCombinedLiability, MissingCoverageUnit, ",
"\n // Index",
"\n NegativeIndex,",
"\n // Default",
"\n Generic",
"\n};"
Expand Down Expand Up @@ -169,6 +171,8 @@
"\n (Error.MissingDataAtPosting , 1) => $\"Missing imported data for {s[0]} DataNode.\",",
"\n (Error.MissingCombinedLiability , 2) => $\"Missing Combined Liability AoC Type for DataNode {s[0]} and AmountType {s[1]}.\",",
"\n (Error.MissingCoverageUnit , 1) => $\"Missing Coverage Unit cash flow for {s[0]} DataNode.\",",
"\n // Index",
"\n (Error.NegativeIndex , 0) => $\"Index was out of range. Must be non-negative.\",",
"\n // Default",
"\n (Error.Generic , _) => $\"{s[0]}\",",
"\n (_ , _) => $\"Error not found.\"",
Expand Down
10 changes: 5 additions & 5 deletions ifrs17/Import/ImportScopeCalculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,11 @@
"\n switch (periodType) {",
"\n case PeriodType.BeginningOfPeriod :",
"\n for (var i = 0; i < parentDiscountedValues.Length; i++)",
"\n ret[i] = -1d * (parentDiscountedValues[i] - parentNominalValues[i]) * (GetElementOrDefault(monthlyInterestFactor, i/12) - 1d );",
"\n ret[i] = -1d * (parentDiscountedValues[i] - parentNominalValues[i]) * (monthlyInterestFactor.GetValidElement(i/12) - 1d );",
"\n break;",
"\n default :",
"\n for (var i = 0; i < parentDiscountedValues.Length; i++)",
"\n ret[i] = -1d * parentDiscountedValues[i] * (GetElementOrDefault(monthlyInterestFactor, i/12) - 1d );",
"\n ret[i] = -1d * parentDiscountedValues[i] * (monthlyInterestFactor.GetValidElement(i/12) - 1d );",
"\n break;",
"\n }",
"\n ",
Expand All @@ -830,8 +830,8 @@
"\n var interestOnClaimsCashflowCreditRisk = new double[nominalClaimsCashflow.Length];",
"\n var effectCreditRisk = new double[nominalClaimsCashflow.Length];",
"\n for (var i = nominalClaimsCashflow.Length - 1; i >= 0; i--) {",
"\n interestOnClaimsCashflow[i] = 1 / GetElementOrDefault(monthlyInterestFactor, i/12) * (interestOnClaimsCashflow.ElementAtOrDefault(i + 1) + nominalClaimsCashflow[i] - nominalClaimsCashflow.ElementAtOrDefault(i + 1));",
"\n interestOnClaimsCashflowCreditRisk[i] = 1 / GetElementOrDefault(monthlyInterestFactor, i/12) * (Math.Exp(-nonPerformanceRiskRate) * interestOnClaimsCashflowCreditRisk.ElementAtOrDefault(i + 1) + nominalClaimsCashflow[i] - nominalClaimsCashflow.ElementAtOrDefault(i + 1));",
"\n interestOnClaimsCashflow[i] = 1 / monthlyInterestFactor.GetValidElement(i/12) * (interestOnClaimsCashflow.ElementAtOrDefault(i + 1) + nominalClaimsCashflow[i] - nominalClaimsCashflow.ElementAtOrDefault(i + 1));",
"\n interestOnClaimsCashflowCreditRisk[i] = 1 / monthlyInterestFactor.GetValidElement(i/12) * (Math.Exp(-nonPerformanceRiskRate) * interestOnClaimsCashflowCreditRisk.ElementAtOrDefault(i + 1) + nominalClaimsCashflow[i] - nominalClaimsCashflow.ElementAtOrDefault(i + 1));",
"\n effectCreditRisk[i] = interestOnClaimsCashflow[i] - interestOnClaimsCashflowCreditRisk[i];",
"\n }",
"\n ",
Expand Down Expand Up @@ -1698,7 +1698,7 @@
"\n private double[] monthlyInterestFactor => GetScope<MonthlyRate>(Identity, o => o.WithContext(EconomicBasis)).Interest;",
"\n ",
"\n private double interestAccretionFactor => Enumerable.Range(shift,timeStep)",
"\n .Select(i => GetElementOrDefault(monthlyInterestFactor, i/12))",
"\n .Select(i => monthlyInterestFactor.GetValidElement(i/12))",
"\n .Aggregate(1d, (x, y) => x * y ) - 1d;",
"\n ",
"\n double TechnicalMargin.Value => AggregatedValue * interestAccretionFactor;",
Expand Down
6 changes: 3 additions & 3 deletions ifrs17/Utils/ApplicationMessage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
"\n Status = a.Status == ActivityLogStatus.Failed || b.Status == ActivityLogStatus.Failed ? ActivityLogStatus.Failed : ActivityLogStatus.Succeeded,",
"\n StartDateTime = a.StartDateTime < b.StartDateTime ? a.StartDateTime : b.StartDateTime,",
"\n FinishDateTime = a.FinishDateTime > b.FinishDateTime ? a.FinishDateTime : b.FinishDateTime,",
"\n Errors = a.Errors.Concat(b.Errors).ToList(),",
"\n Warnings = a.Warnings.Concat(b.Warnings).ToList(),",
"\n Infos = a.Infos.Concat(b.Infos).ToList(),",
"\n Errors = a.Errors.Concat(b.Errors).ToHashSet().ToList(),",
"\n Warnings = a.Warnings.Concat(b.Warnings).ToHashSet().ToList(),",
"\n Infos = a.Infos.Concat(b.Infos).ToHashSet().ToList(),",
"\n };",
"\n}",
"\n",
Expand Down
21 changes: 12 additions & 9 deletions ifrs17/Utils/Extensions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,21 @@
{
"cell_type": "code",
"source": [
"// because the default(T) is something else than the first/last element. What about \"static T GetValidElement<T>(this IList<T> array, int index)\"? ",
"\nstatic T GetElementOrDefault<T>(this ICollection<T> array, int index)",
"static T GetValidElement<T>(this ICollection<T> collection, int index)",
"\n{ ",
"\n var count = array.Count;",
"\n if (array == null || count == 0)",
"\n var count = collection.Count;",
"\n if (collection == null || count == 0)",
"\n return default(T);",
"\n",
"\n return index < 0",
"\n ? array.ElementAt(0) // should this case be removed?",
"\n : index < count",
"\n ? array.ElementAt(index)",
"\n : array.ElementAt(count -1);",
"\n if (index < 0)",
"\n {",
"\n ApplicationMessage.Log(Error.NegativeIndex);",
"\n return default;",
"\n }",
"\n",
"\n return index < count",
"\n ? collection.ElementAt(index)",
"\n : collection.ElementAt(count -1);",
"\n}"
],
"metadata": {},
Expand Down
10 changes: 5 additions & 5 deletions ifrs17/Utils/ImportCalculationMethods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@
"\n if(periodType == PeriodType.BeginningOfPeriod)",
"\n {",
"\n for (var i = nominalValues.Length - 1; i >= 0; i--)",
"\n ret[i] = nominalValues[i] + GetElementOrDefault(ret, i + 1) * GetElementOrDefault(monthlyDiscounting, i/12);",
"\n ret[i] = nominalValues[i] + ret.GetValidElement(i + 1) * monthlyDiscounting.GetValidElement(i/12);",
"\n return ret;",
"\n }",
"\n ",
"\n for (var i = nominalValues.Length - 1; i >= 0; i--)",
"\n ret[i] = ( nominalValues[i] + GetElementOrDefault(ret, i + 1) ) * GetElementOrDefault(monthlyDiscounting, i/12);",
"\n ret[i] = ( nominalValues[i] + ret.GetValidElement(i + 1) ) * monthlyDiscounting.GetValidElement(i/12);",
"\n ",
"\n return ret;",
"\n}"
Expand All @@ -130,7 +130,7 @@
"\n{ ",
"\n return Enumerable.Range(0, nominalValues.Length)",
"\n .Select( t => Enumerable.Range(t, nominalValues.Length-t)",
"\n .Select( tau => nominalValues[tau] * Math.Pow(GetElementOrDefault(monthlyDiscounting, t/12), tau-t+1) * (Math.Exp(-nonPerformanceRiskRate*(tau-t)) - 1) )",
"\n .Select( tau => nominalValues[tau] * Math.Pow(monthlyDiscounting.GetValidElement(t/12), tau-t+1) * (Math.Exp(-nonPerformanceRiskRate*(tau-t)) - 1) )",
"\n .Sum() )",
"\n .ToArray();",
"\n}"
Expand All @@ -155,12 +155,12 @@
"\n if(period == PeriodType.BeginningOfPeriod)",
"\n {",
"\n for (var i = cdcf.Length - 1; i >= 0; i--)",
"\n cdcf[i] = values[i] + GetElementOrDefault(cdcf, i + 1) * GetElementOrDefault(yearlyDiscountRates, i/12);",
"\n cdcf[i] = values[i] + cdcf.GetValidElement(i + 1) * yearlyDiscountRates.GetValidElement(i/12);",
"\n }",
"\n else",
"\n { ",
"\n for (var i = cdcf.Length - 1; i >= 0; i--)",
"\n cdcf[i] = ( values[i] + GetElementOrDefault(cdcf, i + 1) ) * GetElementOrDefault(yearlyDiscountRates, i/12);",
"\n cdcf[i] = ( values[i] + cdcf.GetValidElement(i + 1) ) * yearlyDiscountRates.GetValidElement(i/12);",
"\n }",
"\n return rv with { Values = cdcf };",
"\n })",
Expand Down