private void DoEIRProjectionTask(List <LifeTimeEADs> lifeTimeEAD, Guid masterGuid, int maxProjectionMonth) { //populate for EIR projections var eirProjections = new ECLTasks(this._eclId, this._eclType).EAD_EIRProjections(lifeTimeEAD, maxProjectionMonth); Log4Net.Log.Info("Completed EAD_EIRProjections"); //insert into DB ExecuteNative.SaveEIRProjections(eirProjections, masterGuid, this._eclType); Log4Net.Log.Info("Completed SaveEIRProjections"); }
public List <Refined_Raw_Wholesale> GetRefinedLoanBookData(List <Loanbook_Data> loanbook) { //var qry = Queries.Raw_Data(this._eclId, this._eclType); var lstRaw = loanbook; if (lstRaw == null) { lstRaw = new List <Loanbook_Data>(); } var refined_lstRaw = new ECLTasks(this._eclId, this._eclType).GenerateContractIdandRefinedData(lstRaw); return(refined_lstRaw); }
private void RunEADJob(List <Loanbook_Data> _loanBookData, Guid eclId) { Log4Net.Log.Info("Completed pass raw data to object"); var refined_lstRaw = new ECLTasks(eclId, this._eclType).GenerateContractIdandRefinedData(_loanBookData); Log4Net.Log.Info("Completed GenerateContractIdandRefinedData"); var lifeTimeEAD = new ECLTasks(eclId, this._eclType).GenerateLifeTimeEAD(refined_lstRaw); lock (refined_lstRaws) refined_lstRaws.AddRange(refined_lstRaw); lock (lifetimeEADs) lifetimeEADs.AddRange(lifeTimeEAD); }
private bool RunLGDJob(List <Loanbook_Data> lstRaw, Guid _eclId, EclType _eclType) { //lstRaw = lstRaw.Where(o => o.ContractNo.Contains("182NIFC162940002") || o.ContractId.Contains("182NIFC162940002")).ToList(); //Next Line to be removed //lstRaw = lstRaw.Where(o => o.ContractStartDate == null && o.ContractEndDate == null).Take(5).ToList(); _eclTask = new ECLTasks(_eclId, _eclType); var LGDPreCalc = _eclTask.LGDPreCalculation(lstRaw); Log4Net.Log.Info($"Done with LGD Precalculation - {DateTime.Now}"); var collateral_R = _eclTask.Collateral_OMV_FSV(lstRaw, LGDPreCalc); Log4Net.Log.Info($"Computed Collateral OVM - {DateTime.Now}"); /// /// Save Collateral OMV_FSV /// //Insert to Database ExecuteNative.SaveLGDCollaterals(collateral_R, _eclId, _eclType); Log4Net.Log.Info($"Save LGD Collateral - {DateTime.Now}"); var corTable = _eclTask.CalculateCoR_Main(LGDPreCalc, lstRaw, collateral_R); Log4Net.Log.Info($"Done with Calculate CoR main - {DateTime.Now}"); var accountData = _eclTask.AccountData(lstRaw, LGDPreCalc, collateral_R, corTable); Log4Net.Log.Info($"Done Calculating Account data - {DateTime.Now}"); //Insert to Database ExecuteNative.SaveLGDAccountdata(accountData, _eclId, _eclType); Log4Net.Log.Info($"Saved LGD Account Data - {DateTime.Now}"); return(true); }
private EADParameters BuildEADParameter(Guid eclId, DateTime reportingDate, EclType eclType) { var bt_ead = new CalibrationInput_EAD_Behavioural_Terms_Processor(); var bt_ead_data = bt_ead.GetBehaviouralData(eclId, eclType); var eclTsk = new ECLTasks(eclId, eclType); var exchangeRate = eclTsk._eclEadInputAssumption.Where(o => o.Key.StartsWith("ExchangeRate")).ToList(); var er = new List <ExchangeRate>(); foreach (var _er in exchangeRate) { er.Add(new ExchangeRate { Currency = _er.InputName.ToUpper(), Value = Convert.ToDouble(_er.Value) }); } var vir = new List <VariableInterestRate>(); foreach (var _vir in eclTsk.ViR) { vir.Add(new VariableInterestRate { VIR_Name = _vir.InputName.ToUpper(), Value = Convert.ToDouble(_vir.Value) }); } var CCF_OBE = 1.0; try { CCF_OBE = Convert.ToDouble(eclTsk._eclEadInputAssumption.FirstOrDefault(o => o.Key == "ConversionFactorOBE").Value); } catch { } var PrePaymentFactor = 0.0; try { PrePaymentFactor = Convert.ToDouble(eclTsk._eclEadInputAssumption.FirstOrDefault(o => o.Key == "PrePaymentFactor)").Value); } catch { } var ccfData = new CalibrationInput_EAD_CCF_Summary_Processor().GetCCFData(eclId, eclType); var ccfOverall = ccfData.Overall_CCF ?? 0.0; var obj = new EADParameters { ExchangeRates = er, VariableInterestRates = vir, Expired = bt_ead_data.Expired, NonExpired = bt_ead_data.NonExpired, ReportDate = reportingDate, ConversionFactorObe = CCF_OBE, PrePaymentFactor = PrePaymentFactor, CCF_Commercial = ccfOverall, CCF_Consumer = ccfOverall, CCF_Corporate = ccfOverall, CCF_OBE = CCF_OBE, BasePath = AppSettings.ECLBasePath }; obj.NonExpired = 19; obj.Expired = 26; obj.ConversionFactorObe = 0.29; obj.PrePaymentFactor = 0; obj.ExchangeRates = new List <ExchangeRate>(); obj.ExchangeRates.Add(new ExchangeRate { Currency = "EUR", Value = 6.3613 }); obj.ExchangeRates.Add(new ExchangeRate { Currency = "GBP", Value = 7.00375 }); obj.ExchangeRates.Add(new ExchangeRate { Currency = "GHS", Value = 1 }); obj.ExchangeRates.Add(new ExchangeRate { Currency = "USD", Value = 5.6674 }); obj.ExchangeRates.Add(new ExchangeRate { Currency = "XOF", Value = 0.00969773921721742 }); obj.ExchangeRates.Add(new ExchangeRate { Currency = "ZAR", Value = 0.326 }); obj.VariableInterestRates = new List <VariableInterestRate>(); obj.VariableInterestRates.Add(new VariableInterestRate { VIR_Name = "EGH GHS BASE RATE", Value = 0.2595 }); obj.VariableInterestRates.Add(new VariableInterestRate { VIR_Name = "EGH USD BASE RATE", Value = 0.326 }); obj.VariableInterestRates.Add(new VariableInterestRate { VIR_Name = "GHANA REFERENCE RATE", Value = 0.1475 }); obj.CCF_Commercial = 0.9997; obj.CCF_Consumer = 0.9997; obj.CCF_Corporate = 0.9997; obj.CCF_OBE = 0.29; return(obj); }
public bool ProcessTask(List <Loanbook_Data> loanbooks) { try { paymentScheduleProjections = new List <PaymentSchedule>(); var qry = Queries.PaymentSchedule(this._eclId, this._eclType); var _payment_schedule = DataAccess.i.GetData(qry); Log4Net.Log.Info("Completed Getting Payment Schedule"); var payment_schedule = new List <PaymentSchedule>(); foreach (DataRow dr in _payment_schedule.Rows) { var itm = DataAccess.i.ParseDataToObject(new TempPaymentSchedule(), dr); itm.ContractRefNo = itm.ContractRefNo.ToUpper(); itm.Component = itm.Component.ToUpper(); payment_schedule.Add(new PaymentSchedule { Amount = itm.Amount, Component = itm.Component, ContractRefNo = itm.ContractRefNo, StartDate = itm.StartDate, Frequency = itm.Frequency, NoOfSchedules = itm.NoOfSchedules }); } //var ps_contract_nos = payment_schedule.Select(o => o.ContractRefNo).ToList(); //var non_ps_lb = loanbooks.Where(o => !ps_contract_nos.Contains(o.ContractNo)).ToList(); //var crt_non_ps_lb = non_ps_lb.Select(o=>o.ContractNo).Distinct().ToList(); //foreach (var itm in crt_non_ps_lb) //{ // // payment_schedule.Add(new PaymentSchedule { ContractRefNo = itm, Component= "AMORTISE" }); //} var tskStatusLst = new List <TaskStatus> { TaskStatus.RanToCompletion, TaskStatus.Faulted, TaskStatus.Canceled }; if (1 != 1)//loanbooks.Count<=1000) { RunEADJob(loanbooks, this._eclId); } else { //var checker = loanbooks.Count / 30; var threads = loanbooks.Count / 500; threads = threads + 1; var taskLst = new List <Task>(); for (int i = 0; i < threads; i++) { var sub_LoanBook = loanbooks.Skip(i * 500).Take(500).ToList(); //var contractIds = sub_LoanBook.Select(o => o.ContractNo).ToList(); //var sub_payment_schedule = payment_schedule.Where(o => contractIds.Contains(o.ContractRefNo)).ToList(); var task = Task.Run(() => { RunEADJob(sub_LoanBook, this._eclId); }); taskLst.Add(task); } Log4Net.Log.Info($"Total Task : {taskLst.Count()}"); //Task t = Task.WhenAll(taskLst); //try //{ // t.Wait(); //} //catch(Exception ex) //{ // Log4Net.Log.Error(ex); //} // Log4Net.Log.Info($"All Task status: {t.Status}"); //if (t.Status== TaskStatus.RanToCompletion) //{ // Log4Net.Log.Info($"All Task ran to completion"); //} //if (t.Status == TaskStatus.Faulted) //{ // Log4Net.Log.Info($"All Task ran to fault"); //} while (0 < 1) { if (taskLst.All(o => tskStatusLst.Contains(o.Status))) { break; } //Do Nothing } } //EIR //Task.Run(() => { // DoEIRProjectionTask(lifetimeEADs, this._eclId); //}); var maxProjectionMonth = Convert.ToInt32(loanbooks.Max(o => o.LIM_MONTH)); DoEIRProjectionTask(lifetimeEADs, this._eclId, maxProjectionMonth); // DoEIRProjectionTask(lifeTimeEAD, lstContractIds, masterGuid); //populate for CIR projections var cirProjections = new ECLTasks(this._eclId, this._eclType).EAD_CIRProjections(lifetimeEADs, maxProjectionMonth); Log4Net.Log.Info("Completed EAD_CIRProjections"); //insert into DB ExecuteNative.SaveCIRProjections(cirProjections, this._eclId, this._eclType); Log4Net.Log.Info("Completed SaveCIRProjections"); Log4Net.Log.Info("Completed Parsing Payment Schedule to object"); //if (item.ContractRefNo != "701SMGA132120001") //{ // // continue; //} //payment_schedule = payment_schedule.Where(o => o.ContractRefNo == "701SMGA132120001").ToList(); if (1 != 1)//payment_schedule.Count <= 1000) { PaymentSchedule_Projection(payment_schedule, 1); } else { //var checker = loanbooks.Count / 30; //payment_schedule = payment_schedule.Where(o => o.ContractRefNo == "701SMGA132120001").ToList(); //============== payment_schedule = payment_schedule.OrderBy(o => o.ContractRefNo).ToList(); var groupedPS = new List <List <PaymentSchedule> >(); var threads = payment_schedule.Count / 500; threads = threads + 1; for (int i = 0; i < threads; i++) { var sub_items = payment_schedule.Skip(i * 500).Take(500).ToList(); if (sub_items.Count > 0) { groupedPS.Add(sub_items); } } var allAccountsGrouped = false; try { while (!allAccountsGrouped) { allAccountsGrouped = true; for (int i = 1; i < groupedPS.Count; i++) { var lstfromPrev = groupedPS[i - 1].LastOrDefault(); var fstfromCurr = groupedPS[i].FirstOrDefault(); if (lstfromPrev.ContractRefNo == fstfromCurr.ContractRefNo) { groupedPS[i - 1].Add(fstfromCurr); groupedPS[i].RemoveAt(0); allAccountsGrouped = false; } } } } catch (Exception ex) { } //============== var taskLst = new List <Task>(); for (int i = 0; i < threads; i++) { try{ var sub_payment_schedule = groupedPS[i]; var task = Task.Run(() => { PaymentSchedule_Projection(sub_payment_schedule, i); }); taskLst.Add(task); }catch (Exception ex) { } } Log4Net.Log.Info($"Total Task : {taskLst.Count()}"); //Task t = Task.WhenAll(taskLst); //try //{ // t.Wait(); //} //catch (Exception ex) //{ // Log4Net.Log.Error(ex); //} //Log4Net.Log.Info($"All Task status: {t.Status}"); //if (t.Status == TaskStatus.RanToCompletion) //{ // Log4Net.Log.Info($"All Task ran to completion"); //} //if (t.Status == TaskStatus.Faulted) //{ // Log4Net.Log.Info($"All Task ran to fault"); //} while (0 < 1) { if (taskLst.All(o => tskStatusLst.Contains(o.Status))) { break; } //Do Nothing } } Log4Net.Log.Info("Completed Parsing PaymentSchedule_Projection"); //var sb = new StringBuilder(); //sb.Append($"Contract,StartDate,Component,Month,Value{Environment.NewLine}"); //foreach (var itm in paymentScheduleProjections) //{ // sb.Append($"{itm.ContractId},{itm.StartDate},{itm.Component},{itm.Months},{itm.Value}{Environment.NewLine}"); //} //File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PS.csv"), sb.ToString()); var ccfData = new CalibrationInput_EAD_CCF_Summary_Processor().GetCCFData(this._eclId, this._eclType); ////populate for LifeTime projections //var lifetimeProjections_ = new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(refined_lstRaws, lifetimeEADs, cirProjections, PaymentScheduleProjection, ccfData); //Log4Net.Log.Info("Completed EAD_LifeTimeProjections"); //ExecuteNative.SaveLifeTimeProjections(lifetimeProjections_, this._eclId, _eclType); //Log4Net.Log.Info("All Jobs Completed"); // refined_lstRaws = refined_lstRaws.Where(o => o.contract_no == "7010121400169701").ToList(); if (1 != 1)//loanbooks.Count <= 1000) //1 != 1) // { //var _lifetimeProjections = new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(refined_lstRaws, lifetimeEADs, cirProjections, paymentScheduleProjections, ccfData); //lifeTimeProjections.AddRange(_lifetimeProjections); } else { //var checker = loanbooks.Count / 60; Log4Net.Log.Info($"refined_lstRaws.Count - {refined_lstRaws.Count}"); var threads = refined_lstRaws.Count / 500; threads = threads + 1; Log4Net.Log.Info($"No of Thread - {threads}"); var taskLst = new List <Task>(); for (int i = 0; i < threads; i++) { Log4Net.Log.Info($"Thread - {i}"); var sub_refined_lstRaws = refined_lstRaws.Skip(i * 500).Take(500).ToList(); var contractnos = sub_refined_lstRaws.Where(p => !string.IsNullOrEmpty(p.contract_no)).Select(o => o.contract_no).ToList(); var sub_lifetimeEADs = lifetimeEADs.Where(o => o != null && contractnos.Contains(o.contract_no)).ToList(); var actualContract = contractnos.Select(o => Computation.GetActualContractId(o)).ToList(); paymentScheduleProjections = paymentScheduleProjections.Where(a => a != null).ToList(); var sub_PaymentScheduleProjection = paymentScheduleProjections.Where(o => actualContract.Contains(o.ContractId)).ToList(); var task = Task.Run(() => { //populate for LifeTime projections //var _lifetimeProjections = new ECLTasks(this._eclId, this._eclType).EAD_LifeTimeProjections(sub_refined_lstRaws, sub_lifetimeEADs, cirProjections, sub_PaymentScheduleProjection, ccfData); // lifeTimeProjections.AddRange(_lifetimeProjections); ////Console.ReadKey(); /// }); taskLst.Add(task); } Log4Net.Log.Info($"Total Task : {taskLst.Count()}"); //var completedTask = taskLst.Where(o => o.Status == TaskStatus.RanToCompletion).Count(); //Log4Net.Log.Info($"Task Completed: {completedTask}"); //while (taskLst.Count != tasks.Count) //while (!taskLst.Any(o => o.IsCompleted)) while (0 < 1) { if (taskLst.All(o => tskStatusLst.Contains(o.Status))) { break; } //Do Nothing } //Task t = Task.WhenAll(taskLst); //try //{ // t.Wait(); //} //catch (Exception ex) //{ // Log4Net.Log.Error(ex); //} //Log4Net.Log.Info($"All Task status: {t.Status}"); //if (t.Status == TaskStatus.RanToCompletion) //{ // Log4Net.Log.Info($"All Task ran to completion"); //} //if (t.Status == TaskStatus.Faulted) //{ // Log4Net.Log.Info($"All Task ran to fault"); //} } Log4Net.Log.Info("Completed EAD_LifeTimeProjections"); return(true); } catch (Exception ex) { Log4Net.Log.Error(ex.ToString()); // //Console.ReadKey(); return(false); } }