private double ComputeFinalEclValue(List <FinalEcl> monthlyEcl, List <IrFactor> cummulativeDiscountFactor, List <LifetimeEad> lifetimeEad, List <LifetimeLgd> lifetimeLGD, string contractId, StageClassification stage, string eirGroup) { //xxxxxxxxxxxxxxxxxxx double lifetimeLgdMonth0Value = 0; try { lifetimeLgdMonth0Value = lifetimeLGD.FirstOrDefault(o => o.ContractId == contractId && o.Month == 0).Value; } catch { } double lifetimeEadMonth0Value = 0; try { lifetimeEadMonth0Value = lifetimeEad.FirstOrDefault(o => o.ContractId == contractId && o.ProjectionMonth == 0).ProjectionValue; } catch { } double finalEclValue = 0; switch (stage.Stage) { //case 1: // double[] monthEclArray = monthlyEcl.Where(o => o.ContractId == contractId && o.EclMonth >= 1 && o.EclMonth <= FrameworkConstants.ScenerioWorkingMaxMonth).OrderBy(m => m.EclMonth).Select(n => n.MonthlyEclValue).ToArray(); // double[] monthCdfArray = cummulativeDiscountFactor.Where(o => o.EirGroup == eirGroup && o.ProjectionMonth >= 1 && o.ProjectionMonth <= FrameworkConstants.ScenerioWorkingMaxMonth).OrderBy(m => m.ProjectionMonth).Select(n => n.ProjectionValue).ToArray(); // finalEclValue = ExcelFormulaUtil.SumProduct(monthEclArray, monthCdfArray); // break; //case 2: // double[] monthEclArray2 = monthlyEcl.Where(o => o.ContractId == contractId && o.EclMonth >= 1).OrderBy(m => m.EclMonth).Select(n => n.MonthlyEclValue).ToArray();// && o.EclMonth <= FrameworkConstants.ProjectionMonth).Select(n => n.MonthlyEclValue).ToArray(); // double[] monthCdfArray2 = cummulativeDiscountFactor.Where(o => o.EirGroup == eirGroup && o.ProjectionMonth >= 1).OrderBy(m => m.ProjectionMonth).Select(n => n.ProjectionValue).ToArray();// && o.ProjectionMonth < FrameworkConstants.ProjectionMonth).Select(n => n.ProjectionValue).ToArray(); //FrameworkConstants.ProjectionMonth // finalEclValue = ExcelFormulaUtil.SumProduct(monthEclArray2, monthCdfArray2); // break; case 1: double[] monthEclArray = monthlyEcl.Where(o => o.ContractId == contractId && o.EclMonth >= 1 && o.EclMonth <= FrameworkConstants.ScenerioWorkingMaxMonth).OrderBy(m => m.EclMonth).Select(n => n.MonthlyEclValue).ToArray(); double[] monthCdfArray = cummulativeDiscountFactor.Where(o => o.EirGroup == eirGroup && o.ProjectionMonth >= 1 && o.ProjectionMonth <= FrameworkConstants.ScenerioWorkingMaxMonth).OrderBy(m => m.ProjectionMonth).Select(n => n.ProjectionValue).ToArray(); finalEclValue = ExcelFormulaUtil.SumProduct(monthEclArray, monthCdfArray); break; case 2: double[] monthEclArray2 = monthlyEcl.Where(o => o.ContractId == contractId && o.EclMonth >= 1).OrderBy(m => m.EclMonth).Select(n => n.MonthlyEclValue).ToArray(); // && o.EclMonth <= FrameworkConstants.ProjectionMonth).Select(n => n.MonthlyEclValue).ToArray(); double[] monthCdfArray2 = cummulativeDiscountFactor.Where(o => o.EirGroup == eirGroup && o.ProjectionMonth >= 1).OrderBy(m => m.ProjectionMonth).Select(n => n.ProjectionValue).ToArray(); // && o.ProjectionMonth < FrameworkConstants.ProjectionMonth).Select(n => n.ProjectionValue).ToArray(); //FrameworkConstants.ProjectionMonth finalEclValue = ExcelFormulaUtil.SumProduct(monthEclArray2, monthCdfArray2); break; default: finalEclValue = lifetimeEadMonth0Value * lifetimeLgdMonth0Value; break; } return(finalEclValue); }
private double GetSumProductValue(List <LgdCollateralProjection> collateralProjections, long ttrMonth, double[] fsvArray, long month) { long minMonth = Math.Min(month + ttrMonth, FrameworkConstants.TempExcelVariable_LIM_CM); var projectionsDr = collateralProjections.FirstOrDefault(x => x.Month == minMonth); double[] projections = new double[9]; projections[0] = projectionsDr.Cash; projections[1] = projectionsDr.Commercial_Property; projections[2] = projectionsDr.Debenture; projections[3] = projectionsDr.Inventory; projections[4] = projectionsDr.Plant_And_Equipment; projections[5] = projectionsDr.Receivables; projections[6] = projectionsDr.Residential_Property; projections[7] = projectionsDr.Shares; projections[8] = projectionsDr.Vehicle; double sumProduct = ExcelFormulaUtil.SumProduct(fsvArray, projections); return(sumProduct); }
protected List <IndexForecast> ComputeScenarioPrincipalComponents(List <PDI_StatisticalInputs> statisticalInputs) { var principalData = new List <IndexForecast>(); var standardisedData = ComputeScenarioStandardisedData(statisticalInputs); standardisedData = standardisedData.OrderBy(o => o.Date).ToList(); var macroeconomicPrincipal1 = statisticalInputs.Where(o => o.Mode == StatisticalInputsRowKeys.PrincipalScore1).ToList(); var macroeconomicPrincipal2 = statisticalInputs.Where(o => o.Mode == StatisticalInputsRowKeys.PrincipalScore2).ToList(); var macroeconomicPrincipal3 = statisticalInputs.Where(o => o.Mode == StatisticalInputsRowKeys.PrincipalScore3).ToList(); var macroeconomicPrincipal4 = statisticalInputs.Where(o => o.Mode == StatisticalInputsRowKeys.PrincipalScore4).ToList(); var groupedDate = standardisedData.GroupBy(x => x.Date).Select(x => new { Date = x.Key, Cnt = x.Count() }).ToList(); var macroEconomicCount = 0; if (groupedDate.Count > 0) { macroEconomicCount = groupedDate.Max(r => r.Cnt); } foreach (var dt in groupedDate) { var date_standardisedData = standardisedData.Where(o => o.Date == dt.Date).ToList(); double[] standardised = new double[date_standardisedData.Count]; double[] principal1 = new double[macroeconomicPrincipal1.Count]; double[] principal2 = new double[macroeconomicPrincipal2.Count]; double[] principal3 = new double[macroeconomicPrincipal3.Count]; double[] principal4 = new double[macroeconomicPrincipal4.Count]; for (int i = 0; i < date_standardisedData.Count; i++) { standardised[i] = date_standardisedData[i].MacroEconomicValue; if (principal1.Length - 1 >= i) { var p1 = macroeconomicPrincipal1.FirstOrDefault(o => o.MacroEconomicVariableId == date_standardisedData[i].MacroEconomicVariableId); principal1[i] = p1 != null ? p1.MacroEconomicValue : 0; } if (principal2.Length - 1 >= i) { var p2 = macroeconomicPrincipal2.FirstOrDefault(o => o.MacroEconomicVariableId == date_standardisedData[i].MacroEconomicVariableId); principal2[i] = p2 != null ? p2.MacroEconomicValue : 0; } if (principal3.Length - 1 >= i) { var p3 = macroeconomicPrincipal3.FirstOrDefault(o => o.MacroEconomicVariableId == date_standardisedData[i].MacroEconomicVariableId); principal3[i] = p3 != null ? p3.MacroEconomicValue : 0; } if (principal4.Length - 1 >= i) { var p4 = macroeconomicPrincipal4.FirstOrDefault(o => o.MacroEconomicVariableId == date_standardisedData[i].MacroEconomicVariableId); principal4[i] = p4 != null ? p4.MacroEconomicValue : 0; } } var itm = standardisedData.FirstOrDefault(o => o.Date == dt.Date); itm.Principal1 = ExcelFormulaUtil.SumProduct(standardised, principal1); itm.Principal2 = ExcelFormulaUtil.SumProduct(standardised, principal2); itm.Principal3 = ExcelFormulaUtil.SumProduct(standardised, principal3); itm.Principal4 = ExcelFormulaUtil.SumProduct(standardised, principal4); //Log4Net.Log.Info($"{itm.Date},{itm.MacroEconomicVariableId},{itm.MacroEconomicValue},{this._Scenario.ToString()}++++++"); principalData.Add(itm); } return(principalData); }