Exemplo n.º 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);
        }
        private LifeTimeObject GetPdGroupForConsAndComm(LifeTimeObject dr, List <PdInputAssumptionNonInternalModels> nonInternalModelInput, string columnName, int month, double vasicekIndexMonthValue)
        {
            if (columnName == "10" || columnName == ECLStringConstants.i.ExpiredContractsPrefix)
            {
                dr.PdGroup = columnName;
                dr.Month   = month;
                dr.Value   = month == 1 ? 1 : 0;

                return(dr);
            }
            else
            {
                var consStageObj = nonInternalModelInput.FirstOrDefault(row => row.Month == month && row.PdGroup == columnName);
                //************************
                if (consStageObj == null)
                {
                    consStageObj = new PdInputAssumptionNonInternalModels {
                        PdGroup = "CONS_STAGE_1"
                    };
                }
                //var consStageVal = 0.0;
                //if(columnName== "CONS_STAGE_1")
                //{
                //    consStageVal = consStageObj.CONS_STAGE_1;
                //}
                //if (columnName == "CONS_STAGE_2")
                //{
                //    consStageVal = consStageObj.CONS_STAGE_2;
                //}
                //if (columnName == "COMM_STAGE_1")
                //{
                //    consStageVal = consStageObj.COMM_STAGE_1;
                //}
                //if (columnName == "COMM_STAGE_2")
                //{
                //    consStageVal = consStageObj.COMM_STAGE_2;
                //}

                dr.PdGroup = consStageObj.PdGroup;
                dr.Month   = month;
                dr.Value   = consStageObj.MarginalDefaultRate * vasicekIndexMonthValue;

                return(dr);
            }
        }
Exemplo n.º 3
0
        public string Run()
        {
            var output = ComputeRedefaultLifetimePd();

            var dt = new DataTable();


            var c = new LifeTimeObject();

            Type myObjOriginalType = c.GetType();

            PropertyInfo[] myProps = myObjOriginalType.GetProperties();

            for (int i = 0; i < myProps.Length; i++)
            {
                dt.Columns.Add(myProps[i].Name, myProps[i].PropertyType);
            }
            dt.Columns.Add($"{this._eclType.ToString()}EclId", typeof(Guid));

            foreach (var _d in output)
            {
                _d.Id = Guid.NewGuid();
                dt.Rows.Add(new object[]
                {
                    _d.Id, _d.PdGroup, _d.Month, _d.Value, _eclId
                });
            }
            var tableName = "";

            if (_scenario == ECL_Scenario.Best)
            {
                tableName = ECLStringConstants.i.PdRedefaultLifetimeBests_Table(this._eclType);
            }
            else if (_scenario == ECL_Scenario.Downturn)
            {
                tableName = ECLStringConstants.i.PdRedefaultLifetimeDownturns_Table(this._eclType);
            }
            else if (_scenario == ECL_Scenario.Optimistic)
            {
                tableName = ECLStringConstants.i.PdRedefaultLifetimeOptimistics_Table(this._eclType);
            }
            var r = FileSystemStorage <LifeTimeObject> .WriteCsvData(_eclId, tableName, output);

            return(r? "" : $"Could not Bulk Insert [{tableName}]");
        }
        public List <LifeTimeObject> ComputeLifetimePd()
        {
            var lifetimePd = new List <LifeTimeObject>();

            var marginalPd = GetScenarioMarginalPd();

            foreach (var row in marginalPd)
            {
                double month1 = GetMonth1MarginalPdForPdGroup(marginalPd, row.PdGroup, row.Month);
                double pd     = row.Value;

                var dr = new LifeTimeObject();
                dr.PdGroup = row.PdGroup;
                dr.Month   = row.Month;
                dr.Value   = row.Month == 1 ? row.Value : month1 * row.Value;

                lifetimePd.Add(dr);
            }

            return(lifetimePd);
        }
        public List <LifeTimeObject> ComputeMaginalPd()
        {
            var marginalPds = new List <LifeTimeObject>();

            var logOddsRatio  = GetMonthlyLogOddsRatio();
            var varsicekIndex = GetVasicekScenario();

            varsicekIndex = varsicekIndex.OrderBy(o => o.Date).ToList();
            var lstVarsicekIndex = new List <VasicekEtiNplIndex>();

            lstVarsicekIndex = varsicekIndex.Take(24).ToList();

            //int i = 0;
            //int j = 1;

            //while (lstVarsicekIndex.Count < 24)
            //{
            //    if (varsicekIndex.Count > i)
            //    {
            //        varsicekIndex[i].Month = j;
            //        lstVarsicekIndex.Add(varsicekIndex[i]);
            //    }
            //    else
            //    {
            //        var adhoc = lstVarsicekIndex.Last();
            //        var itm = new VasicekEtiNplIndex { Month = j, Date = EndOfMonth(adhoc.Date, 3), EtiNpl = adhoc.EtiNpl, Fitted = adhoc.Fitted, Index = adhoc.Fitted, Residuals = adhoc.Residuals, ScenarioFactor = adhoc.ScenarioFactor, ScenarioIndex = adhoc.ScenarioIndex, ScenarioPd = adhoc.ScenarioPd };
            //        //adhocvarsicekIndex.Month = j;
            //        lstVarsicekIndex.Add(itm);
            //    }

            //    i = i + 3;
            //    j = j + 1;
            //}


            var nonInternalModelInput = GetNonInternalModelInputsData();

            for (int month = 1; month <= ECLNonStringConstants.i.MaxMarginalLifetimeRedefaultPdMonth; month++)
            {
                int    vasicekSearchMonth     = Convert.ToInt32((month - 1) / 3) + 1;
                double vasicekIndexMonthValue = 0;

                try
                {
                    vasicekIndexMonthValue = lstVarsicekIndex.FirstOrDefault(row => row.Month == (vasicekSearchMonth < 24 ? vasicekSearchMonth : 24)).ScenarioFactor;
                }
                catch
                {
                    try
                    {
                        var lstV = lstVarsicekIndex.LastOrDefault();
                        vasicekIndexMonthValue = lstV.ScenarioFactor;
                    }
                    catch { }
                }
                //Pd group 1 to 9
                for (int pdGroup = 1; pdGroup < 10; pdGroup++)
                {
                    string pdGroupName = pdGroup.ToString();
                    double logOddsRatioMonthRankValue = 0;

                    try
                    {
                        logOddsRatioMonthRankValue = logOddsRatio.FirstOrDefault(row => row.Rank == pdGroup && row.Month == month).CreditRating;
                    }
                    catch {
                        try
                        {
                            var lstOddRatio = logOddsRatio.LastOrDefault(row => row.Rank == pdGroup);
                            logOddsRatioMonthRankValue = lstOddRatio.CreditRating;
                        }
                        catch { }
                    }

                    var dr = new LifeTimeObject();
                    dr.PdGroup = pdGroupName;
                    dr.Month   = month;
                    dr.Value   = logOddsRatioMonthRankValue * vasicekIndexMonthValue;

                    marginalPds.Add(dr);
                }

                //Pd Group Cons Stage 1
                var pdGroup10     = new LifeTimeObject();
                var consStage1Row = new LifeTimeObject();
                var consStage2Row = new LifeTimeObject();
                var commStage1Row = new LifeTimeObject();
                var commStage2Row = new LifeTimeObject();
                var pdGroupExp    = new LifeTimeObject();

                pdGroup10     = GetPdGroupForConsAndComm(pdGroup10, nonInternalModelInput, "10", month, vasicekIndexMonthValue);
                consStage1Row = GetPdGroupForConsAndComm(consStage1Row, nonInternalModelInput, nonInternalModelInput_Types.CONS_STAGE_1, month, vasicekIndexMonthValue);
                consStage2Row = GetPdGroupForConsAndComm(consStage2Row, nonInternalModelInput, nonInternalModelInput_Types.CONS_STAGE_2, month, vasicekIndexMonthValue);
                commStage1Row = GetPdGroupForConsAndComm(commStage1Row, nonInternalModelInput, nonInternalModelInput_Types.COMM_STAGE_1, month, vasicekIndexMonthValue);
                commStage2Row = GetPdGroupForConsAndComm(commStage2Row, nonInternalModelInput, nonInternalModelInput_Types.COMM_STAGE_2, month, vasicekIndexMonthValue);
                pdGroupExp    = GetPdGroupForConsAndComm(pdGroupExp, nonInternalModelInput, ECLStringConstants.i.ExpiredContractsPrefix, month, vasicekIndexMonthValue);

                marginalPds.Add(pdGroup10);
                marginalPds.Add(consStage1Row);
                marginalPds.Add(consStage2Row);
                marginalPds.Add(commStage1Row);
                marginalPds.Add(commStage2Row);
                marginalPds.Add(pdGroupExp);
            }


            return(marginalPds);
        }