internal List <StageClassification> ComputeStageClassification(List <Loanbook_Data> loanbook) { var stageClassification = new List <StageClassification>(); var sicrInput = GetSicrInputResult(); var assumption = GetImpairmentAssumptionsData(); var pdMapping = GetPdMappingResult(); //YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYy var lbContractIds = loanbook.Select(o => o.ContractId).ToList(); sicrInput = sicrInput.Where(o => lbContractIds.Contains(o.ContractId)).ToList(); pdMapping = pdMapping.Where(o => lbContractIds.Contains(o.ContractId)).ToList(); var overrides = GetOverrideDataResult(); foreach (var row in sicrInput) { try { if (string.IsNullOrEmpty(row.ContractId)) { continue; //YYYYYYYYYYYYYYYYYYYYYYYYYY } var newRow = new StageClassification(); if (row.ContractId.ToUpper().StartsWith(ECLStringConstants.i.ExpiredContractsPrefix)) { newRow.ContractId = row.ContractId; newRow.Stage = 3; newRow.projectionMonth = 0; stageClassification.Add(newRow); continue; } var loanbookRecord = loanbook.FirstOrDefault(x => x.ContractId == row.ContractId); var pdMappingRecord = pdMapping.FirstOrDefault(x => x.ContractId == row.ContractId); newRow.ContractId = row.ContractId; newRow.Stage = ComputeStage(row, loanbookRecord, assumption, pdMappingRecord.PdGroup); var overridestage = overrides.FirstOrDefault(o => o.ContractId == row.ContractId); if (overridestage != null) { if (overridestage.Stage != null) { newRow.Stage = overridestage.Stage ?? 1; } } newRow.projectionMonth = 0; try { newRow.projectionMonth = loanbookRecord.LIM_MONTH; } catch { } newRow.ContractId = newRow.ContractId; stageClassification.Add(newRow); }catch (Exception ex) { Log4Net.Log.Info(row.ContractId); Log4Net.Log.Error(ex); } } Console.WriteLine($"Got LGD_StatgeClassification"); return(stageClassification); }
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); }