示例#1
0
        public List <LifeTimeObject> ComputeRedefaultLifetimePd()
        {
            var redefaultLifetimePd = new List <LifeTimeObject>();

            var    marginalPd         = GetScenarioMarginalPd();
            var    pdCali             = new CalibrationInput_PD_CR_RD_Processor().GetPDRedefaultFactorCureRate(this._eclId, this._eclType);
            double readjustmentFactor = pdCali[0];

            //double test = GetMonthMarginalPdForPdGroup(marginalPd, "2", 10, readjustmentFactor);
            //double test2 = marginalPd.FirstOrDefault(row => row.PdGroup == "2" && row.Month == 10).Value;

            //double test3 = test2 * readjustmentFactor;
            //double test4 = test3 * test;

            foreach (var row in marginalPd)
            {
                double prevValue = GetMonthMarginalPdForPdGroup(marginalPd, row.PdGroup,
                                                                row.Month,
                                                                readjustmentFactor);
                double marginalPdValue = row.Value;

                var dr = new LifeTimeObject();
                dr.PdGroup = row.PdGroup;
                dr.Month   = row.Month;
                dr.Value   = row.Month == 1 ? Math.Min(marginalPdValue * readjustmentFactor, 1.0) : prevValue *Math.Min(marginalPdValue *readjustmentFactor, 1.0);

                redefaultLifetimePd.Add(dr);
            }

            return(redefaultLifetimePd);
        }
示例#2
0
        private PDParameters BuildPDParameter(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    pdCali             = new CalibrationInput_PD_CR_RD_Processor().GetPDRedefaultFactorCureRate(eclId, eclType);
            double readjustmentFactor = pdCali[0];

            var obj = new PDParameters
            {
                BasePath     = AppSettings.ECLBasePath,
                Expired      = bt_ead_data.Expired,
                NonExpired   = bt_ead_data.NonExpired,
                ReportDate   = reportingDate,
                SandPMapping = "Best Fit",
                RedefaultAdjustmentFactor = readjustmentFactor
            };


            obj.NonExpired = 19;
            obj.Expired    = 26;
            obj.RedefaultAdjustmentFactor = 1;
            return(obj);
        }
示例#3
0
        protected List <LogOddRatio> ComputeLogsOddsRatio()
        {
            var pd12MonthAssumption = new CalibrationInput_PD_CR_RD_Processor().GetPD12MonthsPD(this._eclId, this._eclType);// new ProcessECL_Wholesale_PD(this._eclId).Get_PDI_Assumptions(); //.Get_PDI_12MonthPds();
            var pdInputAssumptions  = new ProcessECL_PD(this._eclId, this._eclType).Get_PDI_Assumptions();
            var logRates            = ComputeLogRates();

            var logOddsRatioResult = new List <LogOddRatio>();
            //**********************************************
            string snpMappingInput = PdAssumptionsRowKey.SnpMappingValueBestFit;

            try { snpMappingInput = pdInputAssumptions.FirstOrDefault(o => o.PdGroup == PdInputAssumptionGroupEnum.General && o.Key == ECLNonStringConstants.i.SnpMapping).Value; } catch { }

            for (int rank = 1; rank <= _maxRatingRank; rank++)
            {
                //*****************************
                var _12MonthAssumption = new PDI_Assumptions {
                    Value = PdAssumptionsRowKey.SnpMappingValueBestFit
                };
                if (snpMappingInput == PdAssumptionsRowKey.SnpMappingValueBestFit)
                {
                    _12MonthAssumption = pdInputAssumptions.Where(o => o.PdGroup == PdInputAssumptionGroupEnum.CreditBestFit).FirstOrDefault(o => o.InputName == rank.ToString());
                }
                if (snpMappingInput == PdAssumptionsRowKey.SnpMappingValueEtiCreditPolicy)
                {
                    _12MonthAssumption = pdInputAssumptions.Where(o => o.PdGroup == PdInputAssumptionGroupEnum.CreditEtiPolicy).FirstOrDefault(o => o.InputName == rank.ToString());
                }

                string rating = _12MonthAssumption.Value;// snpMappingInput == _12MonthAssumption.Policy ? _12MonthAssumption.Policy : _12MonthAssumption.Fit;

                //Year 1 computation
                double pdValue = 0;
                try { pdValue = pd12MonthAssumption.FirstOrDefault(o => o.Rating == rank).Months_PDs_12; } catch { pdValue = 0; }// double.Parse(pdInputAssumptions.FirstOrDefault(o => o.PdGroup == PdInputAssumptionGroupEnum.CreditPD && o.InputName == rank.ToString()).Value);

                double year1LogOddRatio = Math.Log((1 - pdValue) / pdValue);

                var dataRow = new LogOddRatio();
                dataRow.Rank         = rank;
                dataRow.Rating       = rating;
                dataRow.Year         = 1;
                dataRow.LogOddsRatio = year1LogOddRatio;
                logOddsRatioResult.Add(dataRow);

                //Year to Max computation
                double year1RatingLogRate = 0;
                try { year1RatingLogRate = logRates.FirstOrDefault(row => row.Rating == rating && row.Year == 1).LogOddsRatio; } catch { }

                for (int year = 2; year <= _maxRatingYear; year++)
                {
                    double currentYearRatingLogRate = logRates.FirstOrDefault(row => row.Rating == rating && row.Year == Math.Min(year, _maxLogRateYear)).LogOddsRatio;

                    double currentYearLogOddRatio = year1LogOddRatio + currentYearRatingLogRate - year1RatingLogRate;

                    var currentYeardataRow = new LogOddRatio();
                    currentYeardataRow.Rank         = rank;
                    currentYeardataRow.Rating       = rating;
                    currentYeardataRow.Year         = year;
                    currentYeardataRow.LogOddsRatio = currentYearLogOddRatio;
                    logOddsRatioResult.Add(currentYeardataRow);
                }
            }

            return(logOddsRatioResult);
        }
示例#4
0
        protected List <LgdInputAssumptions_UnsecuredRecovery> GetLgdAssumptionsData()
        {
            //var qry = Queries.LGD_InputAssumptions_UnsecuredRecovery(this._eclId, this._eclType);
            //var dt = DataAccess.i.GetData(qry);
            var ldg_inputassumption = new List <LgdInputAssumptions_UnsecuredRecovery>();

            var pdCali      = new CalibrationInput_PD_CR_RD_Processor().GetPDRedefaultFactorCureRate(this._eclId, this._eclType);
            var rcvCaliRate = new CalibrationInput_LGD_RecoveryRate_Processor().GetLGDRecoveryRateData(this._eclId, this._eclType);

            //foreach (DataRow dr in dt.Rows)
            var rcvCaliRate_ = 0.0;

            for (int i = 0; i < 3; i++)
            {
                var _lgdAssumption = new LgdInputAssumptions_UnsecuredRecovery();

                if (i == 0)
                {
                    _lgdAssumption.Cure_Rate            = pdCali[2];
                    rcvCaliRate_                        = rcvCaliRate.Commercial_RecoveryRate;
                    _lgdAssumption.Segment_Product_Type = "Commercial";
                }
                else if (i == 1)
                {
                    _lgdAssumption.Cure_Rate            = pdCali[3];
                    rcvCaliRate_                        = rcvCaliRate.Consumer_RecoveryRate;
                    _lgdAssumption.Segment_Product_Type = "Consumer";
                }
                else if (i == 2)
                {
                    _lgdAssumption.Cure_Rate            = pdCali[1];
                    rcvCaliRate_                        = rcvCaliRate.Corporate_RecoveryRate;
                    _lgdAssumption.Segment_Product_Type = "Corporate";
                }
                else
                {
                    rcvCaliRate_ = 0;
                    _lgdAssumption.Segment_Product_Type = "";
                }
                _lgdAssumption.Days_0   = rcvCaliRate_;
                _lgdAssumption.Days_90  = rcvCaliRate_ - (rcvCaliRate_ * 0.25);
                _lgdAssumption.Days_180 = _lgdAssumption.Days_90 - (rcvCaliRate_ * 0.25);
                _lgdAssumption.Days_270 = _lgdAssumption.Days_180 - (rcvCaliRate_ * 0.25);
                _lgdAssumption.Days_360 = _lgdAssumption.Days_270 - (rcvCaliRate_ * 0.25);


                //_lgdAssumption.Days_90 = rcvCaliRate_ - (rcvCaliRate.Commercial_RecoveryRate * 0.25);
                //_lgdAssumption.Days_180 = _lgdAssumption.Days_90 - (rcvCaliRate.Commercial_RecoveryRate * 0.25);
                //_lgdAssumption.Days_270 = _lgdAssumption.Days_180 - (rcvCaliRate.Commercial_RecoveryRate * 0.25);
                //_lgdAssumption.Days_360 = _lgdAssumption.Days_270 - (rcvCaliRate.Commercial_RecoveryRate * 0.25);

                _lgdAssumption.Downturn_Days_0   = 1 - ((1 - rcvCaliRate_) * 0.92 + 0.08);
                _lgdAssumption.Downturn_Days_90  = 1 - ((1 - _lgdAssumption.Days_90) * 0.92 + 0.08);
                _lgdAssumption.Downturn_Days_180 = 1 - ((1 - _lgdAssumption.Days_180) * 0.92 + 0.08);
                _lgdAssumption.Downturn_Days_270 = 1 - ((1 - _lgdAssumption.Days_270) * 0.92 + 0.08);
                _lgdAssumption.Downturn_Days_360 = 1 - ((1 - _lgdAssumption.Days_360) * 0.92 + 0.08);

                ldg_inputassumption.Add(_lgdAssumption);
            }

            var _ldg_inputassumption = new List <LgdInputAssumptions_UnsecuredRecovery>();

            foreach (var itm in ldg_inputassumption)
            {
                itm.Segment_Product_Type = itm.Segment_Product_Type ?? "";
                if (itm.Segment_Product_Type.ToLower().EndsWith("curerate"))
                {
                    itm.Days_0 = 0;
                    var sub_itm = ldg_inputassumption.FirstOrDefault(o => o.Segment_Product_Type.ToLower().Contains(itm.Segment_Product_Type.ToLower().Replace("curerate", "timeIndefault")));
                    if (sub_itm != null)
                    {
                        itm.Days_0 = sub_itm.Days_0;
                    }
                    _ldg_inputassumption.Add(itm);
                }
            }
            Log4Net.Log.Info($"Got ldg_inputassumption");
            return(ldg_inputassumption);
        }
示例#5
0
        public bool ProcessCalibrationRunTask()
        {
            try
            {
                var cali = Queries.CalibrationBehavioural();
                var dt   = DataAccess.i.GetData(cali);
                if (dt.Rows.Count > 0)
                {
                    var qry    = "";
                    var caliId = Guid.NewGuid();
                    try
                    {
                        var affId = (long)dt.Rows[0]["AffiliateId"];
                        caliId = (Guid)dt.Rows[0]["Id"];


                        //qry = Queries.UpdateGuidTableServiceId("CalibrationRunEadBehaviouralTerms", this.serviceId, caliId);
                        //var resp = DataAccess.i.ExecuteQuery(qry);

                        //if (resp == 0)
                        //{
                        //    Log4Net.Log.Info($"Another service has picked Behavioural Calibration with ID {caliId.ToString()}.");
                        //    return true;
                        //}

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 4, "Processing", "CalibrationRunEadBehaviouralTerms");
                        DataAccess.i.ExecuteQuery(qry);


                        var ead_bahavioural = new CalibrationInput_EAD_Behavioural_Terms_Processor();
                        ead_bahavioural.ProcessCalibration(caliId, affId);


                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 5, "Completed", "CalibrationRunEadBehaviouralTerms");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.Log.Info("At Calibration");
                        Log4Net.Log.Error(ex.ToString());
                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 10, ex.ToString(), "CalibrationRunEadBehaviouralTerms");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                }
                else
                {
                    Log4Net.Log.Info("No new Calibration found!");
                }


                cali = Queries.CalibrationCCF();
                dt   = DataAccess.i.GetData(cali);
                if (dt.Rows.Count > 0)
                {
                    var qry    = "";
                    var caliId = Guid.NewGuid();
                    try
                    {
                        var affId = (long)dt.Rows[0]["AffiliateId"];
                        caliId = (Guid)dt.Rows[0]["Id"];

                        qry = Queries.UpdateGuidTableServiceId("CalibrationRunEadCcfSummary", this.serviceId, caliId);
                        var resp = DataAccess.i.ExecuteQuery(qry);
                        if (resp == 0)
                        {
                            Log4Net.Log.Info($"Another service has picked CCF Calibration with ID {caliId.ToString()}.");
                            return(true);
                        }

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 4, "Processing", "CalibrationRunEadCcfSummary");
                        DataAccess.i.ExecuteQuery(qry);

                        var ead_ccf = new CalibrationInput_EAD_CCF_Summary_Processor();
                        ead_ccf.ProcessCalibration(caliId, affId);

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 5, "Completed", "CalibrationRunEadCcfSummary");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.Log.Info("At Calibration");
                        Log4Net.Log.Error(ex.ToString());
                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 10, ex.ToString(), "CalibrationRunEadCcfSummary");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                }


                cali = Queries.CalibrationHaircut();
                dt   = DataAccess.i.GetData(cali);
                if (dt.Rows.Count > 0)
                {
                    var qry    = "";
                    var caliId = Guid.NewGuid();
                    try
                    {
                        var affId = (long)dt.Rows[0]["AffiliateId"];
                        caliId = (Guid)dt.Rows[0]["Id"];


                        qry = Queries.UpdateGuidTableServiceId("CalibrationRunLgdHairCut", this.serviceId, caliId);
                        var resp = DataAccess.i.ExecuteQuery(qry);
                        if (resp == 0)
                        {
                            Log4Net.Log.Info($"Another service has picked Haircut Calibration with ID {caliId.ToString()}.");
                            return(true);
                        }

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 4, "Processing", "CalibrationRunLgdHairCut");
                        DataAccess.i.ExecuteQuery(qry);


                        var lgd_haircut = new CalibrationInput_LGD_Haricut_Processor();
                        lgd_haircut.ProcessCalibration(caliId, affId);


                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 5, "Completed", "CalibrationRunLgdHairCut");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.Log.Error(ex.ToString());
                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 10, ex.ToString(), "CalibrationRunLgdHairCut");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                }


                cali = Queries.CalibrationRecovery();
                dt   = DataAccess.i.GetData(cali);
                if (dt.Rows.Count > 0)
                {
                    var qry    = "";
                    var caliId = Guid.NewGuid();
                    try
                    {
                        var affId = (long)dt.Rows[0]["AffiliateId"];
                        caliId = (Guid)dt.Rows[0]["Id"];

                        qry = Queries.UpdateGuidTableServiceId("CalibrationRunLgdRecoveryRate", this.serviceId, caliId);
                        var resp = DataAccess.i.ExecuteQuery(qry);
                        if (resp == 0)
                        {
                            Log4Net.Log.Info($"Another service has picked Recovery Rate Calibration with ID {caliId.ToString()}.");
                            return(true);
                        }

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 4, "Processing", "CalibrationRunLgdRecoveryRate");
                        DataAccess.i.ExecuteQuery(qry);

                        var lgd_recoveryR = new CalibrationInput_LGD_RecoveryRate_Processor();
                        lgd_recoveryR.ProcessCalibration(caliId, affId);


                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 5, "Completed", "CalibrationRunLgdRecoveryRate");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.Log.Error(ex.ToString());
                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 10, ex.ToString(), "CalibrationRunLgdRecoveryRate");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                }


                cali = Queries.CalibrationPD();
                dt   = DataAccess.i.GetData(cali);
                if (dt.Rows.Count > 0)
                {
                    var qry    = "";
                    var caliId = Guid.NewGuid();
                    try
                    {
                        var affId = (long)dt.Rows[0]["AffiliateId"];
                        caliId = (Guid)dt.Rows[0]["Id"];

                        qry = Queries.UpdateGuidTableServiceId("CalibrationRunPdCrDrs", this.serviceId, caliId);
                        var resp = DataAccess.i.ExecuteQuery(qry);
                        if (resp == 0)
                        {
                            Log4Net.Log.Info($"Another service has picked PD CR DR Calibration with ID {caliId.ToString()}.");
                            return(true);
                        }

                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 4, "Processing", "CalibrationRunPdCrDrs");
                        DataAccess.i.ExecuteQuery(qry);

                        var pd_cr_dr = new CalibrationInput_PD_CR_RD_Processor();
                        pd_cr_dr.ProcessCalibration(caliId, affId);


                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 5, "Completed", "CalibrationRunPdCrDrs");
                        DataAccess.i.ExecuteQuery(qry);
                    }catch (Exception ex)
                    {
                        Log4Net.Log.Error(ex);
                        qry = Queries.CalibrationRegisterUpdate(caliId.ToString(), 10, ex.ToString(), "CalibrationRunPdCrDrs");
                        DataAccess.i.ExecuteQuery(qry);
                    }
                }
            }catch (Exception ex)
            {
                Log4Net.Log.Info("At Calibration");
                Log4Net.Log.Error(ex.ToString());
                var x = 0;
            }

            return(true);
        }