Beispiel #1
0
        public LimitDisplayModel CheckCountryLimit(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            Guid guExcludeID = Guid.Empty;

            if (trn.KK_PCCF != null)
            {
                List<CountryLimitModel> deal_conts = new List<CountryLimitModel>();

                if (trn.FLAG_SETTLE.HasValue && trn.FLAG_SETTLE.Value)
                {
                    deal_conts = (from f in trn.DA_TRN_FLOW
                                  where f.FLOW_AMOUNT_THB > 0
                                  select new CountryLimitModel
                                  {
                                      EXPOSURE_DATE = f.FLOW_DATE.Value,
                                      EXPOSURE = f.FLOW_AMOUNT_THB.Value + trn.KK_CONTRIBUTE
                                  }).ToList();
                }

                if (trn.TRADE_DATE.Value != trn.MATURITY_DATE.Value)
                    deal_conts.Add(new CountryLimitModel { EXPOSURE_DATE = trn.TRADE_DATE.Value, EXPOSURE = trn.KK_CONTRIBUTE.Value });

                //Find original deal for exclude it from limit calculation
                if (strExcludeID != null && Guid.TryParse(strExcludeID.Replace("\"", ""), out guExcludeID))
                    guExcludeID = Guid.Parse(strExcludeID.Replace("\"", ""));

                List<LimitCheckModel> ori_conts = _limitCheckBusiness.CheckAllCountry(sessioninfo.Process.CurrentDate, trn, guExcludeID, Guid.Empty);

                limitDisplay.LimitDisplayObject = GenerateCountryLimitDisplay(deal_conts, ori_conts, trn, null, sessioninfo.CountryOverwrite, ref limitDisplay);

                if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                    trn.OVER_COUNTRY_AMOUNT = limitDisplay.OverAmount;
            }
            else
            {
                limitDisplay.LimitCheckStatus = eLimitCheckStatus.ERROR;
                limitDisplay.Message = "This deal breach allowed tenor.";
            }
            return limitDisplay;
        }
Beispiel #2
0
        public LimitDisplayModel CheckFXSwapCountryLimit(SessionInfo sessioninfo, DA_TRN trn1, DA_TRN trn2, string strExcludeID)
        {
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            DA_TRN oldtrn1 = null;
            DA_TRN oldtrn2 = null;
            Guid guExcludeID1 = Guid.Empty;
            Guid guExcludeID2 = Guid.Empty;

            if (trn1.KK_PCCF != null && trn2.KK_PCCF != null)
            {

                List<CountryLimitModel> deal_conts = new List<CountryLimitModel>();

                if (trn1.FLAG_SETTLE.HasValue && trn1.FLAG_SETTLE.Value)
                {
                    deal_conts = (from f in trn1.DA_TRN_FLOW
                                  where f.FLOW_AMOUNT_THB > 0
                                  select new CountryLimitModel
                                  {
                                      EXPOSURE_DATE = f.FLOW_DATE.Value,
                                      EXPOSURE = f.FLOW_AMOUNT_THB.Value + trn1.KK_CONTRIBUTE
                                  }).Union(
                                  (from f in trn2.DA_TRN_FLOW
                                   where f.FLOW_AMOUNT_THB > 0
                                   select new CountryLimitModel
                                   {
                                       EXPOSURE_DATE = f.FLOW_DATE.Value,
                                       EXPOSURE = f.FLOW_AMOUNT_THB.Value + trn2.KK_CONTRIBUTE
                                   })).ToList();

                }

                if (trn1.TRADE_DATE.Value != trn1.MATURITY_DATE.Value)
                    deal_conts.Add(new CountryLimitModel { EXPOSURE_DATE = trn1.TRADE_DATE.Value, EXPOSURE = trn1.KK_CONTRIBUTE.Value + trn2.KK_CONTRIBUTE.Value });

                //Find original deals for exclude them from limit calculation
                if (strExcludeID != null && Guid.TryParse(strExcludeID.Replace("\"", ""), out guExcludeID1))
                {
                    guExcludeID1 = Guid.Parse(strExcludeID.Replace("\"", ""));

                    oldtrn1 = GetByID(guExcludeID1);
                    oldtrn2 = GetDealByProcessDate(sessioninfo.Process.CurrentDate).FirstOrDefault(p => p.INT_DEAL_NO == oldtrn1.INT_DEAL_NO && p.VERSION == oldtrn1.VERSION && p.ID != oldtrn1.ID);

                    if (oldtrn2 == null || oldtrn1 == null)
                        throw this.CreateException(new Exception(), "Cannot find original deals.");

                    guExcludeID1 = oldtrn1.ID;
                    guExcludeID2 = oldtrn2.ID;
                }

                List<LimitCheckModel> ori_conts = _limitCheckBusiness.CheckAllCountry(sessioninfo.Process.CurrentDate, trn2, guExcludeID1, guExcludeID2);

                limitDisplay.LimitDisplayObject = GenerateCountryLimitDisplay(deal_conts, ori_conts, trn1, trn2, sessioninfo.CountryOverwrite, ref limitDisplay);

                if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                {
                    trn1.OVER_COUNTRY_AMOUNT = limitDisplay.OverAmount;
                    trn2.OVER_COUNTRY_AMOUNT = limitDisplay.OverAmount;
                }
            }
            else
            {
                limitDisplay.LimitCheckStatus = eLimitCheckStatus.ERROR;
                limitDisplay.Message = "This deal breach allowed tenor.";
            }
            return limitDisplay;
        }
Beispiel #3
0
        public LimitDisplayModel CheckSwapCountryLimit(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            InstrumentBusiness _insBusiness = new InstrumentBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            Guid guExcludeID = Guid.Empty;

            if (trn.KK_PCCF != null)
            {
                List<CountryLimitModel> deal_conts = new List<CountryLimitModel>();

                MA_INSTRUMENT ins = _insBusiness.GetByID(sessioninfo, trn.INSTRUMENT_ID.Value);

                if (ins.LABEL == "CCS")
                {
                    deal_conts = (from f in trn.DA_TRN_FLOW
                                  where f.FLOW_AMOUNT > 0 // Receive cash flows only
                                  select new
                                  {
                                      Flow_Date = f.FLOW_DATE,
                                      Flow_Amount_THB = f.FLOW_AMOUNT_THB
                                  }).GroupBy(fl => new { fl.Flow_Date })
                                    .Select(p => new CountryLimitModel
                                    {
                                        EXPOSURE_DATE = p.Key.Flow_Date,
                                        EXPOSURE = p.Sum(x => x.Flow_Amount_THB) + trn.KK_CONTRIBUTE.Value
                                    }).OrderBy(p => p.EXPOSURE_DATE).ToList();
                }
                else //Net cashflow for IRS
                {
                    deal_conts = (from f in trn.DA_TRN_FLOW
                                  select new
                                  {
                                      Flow_Date = f.FLOW_DATE,
                                      Flow_ccy = f.FLAG_FIRST ? trn.FIRST.CCY_ID : trn.SECOND.CCY_ID,
                                      Flow_Amount_THB = f.FLOW_AMOUNT_THB
                                  }).GroupBy(fl => new { fl.Flow_Date, fl.Flow_ccy })
                                    .Select(p => new CountryLimitModel
                                    {
                                        EXPOSURE_DATE = p.Key.Flow_Date,
                                        EXPOSURE = p.Sum(x => x.Flow_Amount_THB) + trn.KK_CONTRIBUTE.Value
                                    }).Where(t => t.EXPOSURE > 0).OrderBy(p => p.EXPOSURE_DATE).ToList();
                }

                if (trn.TRADE_DATE.Value != trn.MATURITY_DATE.Value)
                    deal_conts.Add(new CountryLimitModel { EXPOSURE_DATE = trn.TRADE_DATE.Value, EXPOSURE = trn.KK_CONTRIBUTE.Value });

                //Find original deal for exclude it from limit calculation
                if (strExcludeID != null && Guid.TryParse(strExcludeID.Replace("\"", ""), out guExcludeID))
                    guExcludeID = Guid.Parse(strExcludeID.Replace("\"", ""));

                List<LimitCheckModel> ori_conts = _limitCheckBusiness.CheckAllCountry(sessioninfo.Process.CurrentDate, trn, guExcludeID, Guid.Empty);

                limitDisplay.LimitDisplayObject = GenerateCountryLimitDisplay(deal_conts, ori_conts, trn, null, sessioninfo.CountryOverwrite, ref limitDisplay);

                if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                    trn.OVER_COUNTRY_AMOUNT = limitDisplay.OverAmount;
            }
            else
            {
                limitDisplay.LimitCheckStatus = eLimitCheckStatus.ERROR;
                limitDisplay.Message = "This deal breach allowed tenor.";
            }

            return limitDisplay;
        }