Exemplo n.º 1
0
        public List<LimitCheckModel> CheckAllPCE(DateTime ProcessingDate, DA_TRN trn, Guid ExcludeID1, Guid ExcludeID2)
        {
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();

            List<LimitCheckModel> results = GetPCEByCriteria(ProcessingDate, trn.CTPY_ID, trn.PRODUCT_ID.Value, "", ExcludeID1, ExcludeID2);

            //Get group exposure
            MA_COUTERPARTY ctpy = _counterpartyBusiness.GetCounterpartyAll().FirstOrDefault(p => p.ID == trn.CTPY_ID);
            if (ctpy != null && ctpy.GROUP_CTPY_ID != null)
            {
                var group = GetPCEByCriteria(ProcessingDate, ctpy.GROUP_CTPY_ID.Value, trn.PRODUCT_ID.Value, "", ExcludeID1, ExcludeID2);
                results = results.Union(group).ToList();
            }

            //Get temp limit
            //Look for temp limit when all conditions meet
            // 1. Transaction maturity date <= Temp limit maturity date
            foreach (LimitCheckModel result in results)
            {
                MA_TEMP_CTPY_LIMIT temp_limit = _counterpartyBusiness.GetActiveTempByID(ProcessingDate, trn.MATURITY_DATE.Value, result.CTPY_LIMIT_ID);

                if (temp_limit != null)
                    result.TEMP_AMOUNT = temp_limit.AMOUNT;
                    //result.AMOUNT = result.AMOUNT + temp_limit.AMOUNT;
            }

            return results.OrderBy(p => p.SNAME).ThenBy(p => p.SORT_INDEX).ToList();
        }
Exemplo n.º 2
0
 public DA_TRN CancelDeal(SessionInfo sessioninfo, DA_TRN trn)
 {
     LookupBusiness _lookupBusiness = new LookupBusiness();
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var foundTrn = unitOfWork.DA_TRNRepository.GetById(trn.ID,true);
         if (foundTrn == null)
             throw this.CreateException(new Exception(), "Data not found!");
         else if (!Guid.Equals(foundTrn.LOG.INSERTBYUSERID, sessioninfo.CurrentUserId))
         {
             throw this.CreateException(new Exception(), "You have no right to cancel this transaction");
         }
         else if (!(foundTrn.ENGINE_DATE.Date == sessioninfo.Process.CurrentDate && foundTrn.SOURCE == "INT"))
         {
             throw this.CreateException(new Exception(), "You cannot cancel the past deals");
         }
         else
         {
             //foundTrn.STATUS_ID = new Guid("1ccd7506-b98c-4afa-838e-24378d9b3c2e");
             foundTrn.REMARK = trn.REMARK;
             foundTrn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
             foundTrn.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
             foundTrn.LOG.MODIFYDATE = DateTime.Now;
             trn = foundTrn;
             unitOfWork.Commit();
         }
     }
     return trn;
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            PCCFConfigBusiness pccfBusiness = new PCCFConfigBusiness();

            DA_TRN record = new DA_TRN();
            record.ID = Guid.NewGuid();
            record.ENGINE_DATE = DateTime.Now;
            record.STATUS_ID = new Guid("9161ED18-1298-44FA-BA7D-34522CB40D66");
            record.INSTRUMENT_ID = new Guid("33F88EB3-46C0-4667-BCF6-05426321B71B");
            record.PRODUCT_ID = new Guid("F85252D1-BC58-4AC6-8B56-2E228FB0A367");
            record.LOG.INSERTBYUSERID = new Guid("F85252D1-BC58-4AC6-8B56-2E228FB0A367");
            record.LOG.INSERTDATE = DateTime.Now;

            record.FIRST.CCY_ID = new Guid("825F343B-CAEA-409B-AE92-CCA2DAB3765E");
            record.FIRST.FLAG_PAYREC = "R";
            record.FIRST.FLAG_FIXED = false;
            record.SECOND.CCY_ID = new Guid("825F343B-CAEA-409B-AE92-CCA2DAB3765E");
            record.SECOND.FLAG_PAYREC = "P";
            record.SECOND.FLAG_FIXED = false ;

            var temp = pccfBusiness.ValidatePCCFConfig(null, record);
            if(temp!=null)
                Console.WriteLine("PCCF:" + temp.LABEL);
            else
                Console.WriteLine("PCCF is not match");
            Console.WriteLine("End");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        public List<LimitCheckModel> CheckAllCountry(DateTime ProcessingDate, DA_TRN trn, Guid ExcludeID1, Guid ExcludeID2)
        {
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            CountryBusiness _countryBusiness = new CountryBusiness();
            List<LimitCheckModel> results = new List<LimitCheckModel>();
            LimitCheckModel result;
            LimitCheckModel temp = new LimitCheckModel();
            LimitCheckModel pce = new LimitCheckModel();
            MA_COUTERPARTY ctpy = _counterpartyBusiness.GetCounterpartyAll().FirstOrDefault(p => p.ID == trn.CTPY_ID);

            List<LimitCheckModel> sets = GetCountrySETByCriteria(ProcessingDate, ctpy.COUNTRY_ID, "", ExcludeID1, ExcludeID2);
            List<LimitCheckModel> pces = GetCountryPCEByCriteria(ProcessingDate, ctpy.COUNTRY_ID, "", ExcludeID1, ExcludeID2);

            if (pces.Count != 1)
                throw new Exception("Invalid country limit data. Please contact administrator");
            else
                pce = pces.FirstOrDefault();

            MA_COUNTRY_LIMIT temp_limit = _countryBusiness.GetActiveTempByCountryID(ProcessingDate, trn.MATURITY_DATE.Value, ctpy.COUNTRY_ID);

            DateTime dateStart = trn.TRADE_DATE.Value;
            DateTime dateEnd = trn.FLAG_SETTLE.HasValue && trn.FLAG_SETTLE.Value ? trn.DA_TRN_FLOW.Max(p => p.FLOW_DATE).Value : trn.TRADE_DATE.Value;

            while (dateStart <= dateEnd)
            {
                result = new LimitCheckModel();

                temp = sets.FirstOrDefault(p => p.FLOW_DATE == dateStart);

                result.COUNTRY_LABEL = pce.COUNTRY_LABEL;
                result.COUNTRY_ID = pce.COUNTRY_ID;
                result.FLAG_CONTROL = pce.FLAG_CONTROL;
                result.GEN_AMOUNT = pce.GEN_AMOUNT;
                result.TEMP_AMOUNT = temp_limit != null ? temp_limit.AMOUNT : 0;
                //result.AMOUNT = pce.AMOUNT + (temp_limit != null ? temp_limit.AMOUNT : 0);
                result.PROCESSING_DATE = pce.PROCESSING_DATE;
                result.EXPIRE_DATE = pce.EXPIRE_DATE;
                result.FLOW_DATE = dateStart;
                result.ORIGINAL_KK_CONTRIBUTE = pce.ORIGINAL_KK_CONTRIBUTE;

                if (temp != null)
                    result.ORIGINAL_KK_CONTRIBUTE = result.ORIGINAL_KK_CONTRIBUTE + temp.ORIGINAL_KK_CONTRIBUTE;

                results.Add(result);

                //if (dateStart.DayOfWeek == DayOfWeek.Friday)
                //    dateStart = dateStart.AddDays(3);
                //else
                dateStart = dateStart.AddDays(1);
            }

            return results;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        private static void CheckRepoLimit(Boolean blnIsSubmit, DA_TRN record, out object PCESCEObject)
        {
            try
            {
                LimitDisplayModel PCECheckRecords = DealUIP.CheckPCE(SessionInfo, record, ProductId);
                LimitDisplayModel CountryCheckRecords = DealUIP.CheckCountryLimit(SessionInfo, record, ProductId);

                PCESCEObject = ConsoLimitDisplay(blnIsSubmit, PCECheckRecords, null, CountryCheckRecords);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 7
0
        public static LimitDisplayModel CheckFXSwapCountryLimit(SessionInfo sessioninfo, DA_TRN trn1, DA_TRN trn2, string strExcludeID)
        {
            DealBusiness _dealBusiness = new DealBusiness();

            return _dealBusiness.CheckFXSwapCountryLimit(sessioninfo, trn1, trn2, strExcludeID);
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        public string SubmitSwapDeal(SessionInfo sessioninfo
										, DA_TRN trn
										, string strOverApprover
										, string strOverComment
										, string strProductId)
        {
            //trn.STATUS_ID = Guid.Parse("9161ed18-1298-44fa-ba7d-34522cb40d66");
            //trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);

            //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            //trn.KK_PCCF = _staticdataBusiness.GetSwapKKPCCF(sessioninfo, trn);
            //trn.KK_CONTRIBUTE = trn.FIRST.NOTIONAL * trn.KK_PCCF / 100;
            //trn.BOT_PCCF = _staticdataBusiness.GetSwapBOTPCCF(sessioninfo, trn);
            //trn.BOT_CONTRIBUTE = trn.FIRST.NOTIONAL * trn.BOT_PCCF / 100;
            LookupBusiness _lookupBusiness = new LookupBusiness();
            if (!String.IsNullOrEmpty(strOverApprover))
            {
                trn.OVER_APPROVER = strOverApprover;
                trn.OVER_COMMENT = strOverComment;
            }

            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                Guid guTemp;
                if (Guid.TryParse(strProductId, out guTemp))
                {
                    var foundDeal = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == guTemp);
                    if (foundDeal == null)
                        throw this.CreateException(new Exception(), "Data not found!");
                    else
                    {
                        foundDeal.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
                        foundDeal.REMARK = trn.REMARK;
                    }
                }
                trn.REMARK = null;
                if (trn.INT_DEAL_NO == null)
                    trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);
                unitOfWork.DA_TRNRepository.Add(trn);
                unitOfWork.Commit();
            }
            return trn.INT_DEAL_NO;
        }
Exemplo n.º 10
0
        private List<LimitCheckModel> GenerateCountryLimitDisplay(List<CountryLimitModel> deal_conts, List<LimitCheckModel> ori_conts, DA_TRN trn1, DA_TRN trn2, bool blnOverwrite, ref LimitDisplayModel limitDisplay)
        {
            CountryLimitModel tempCountry = null;
            List<LimitCheckModel> limits = new List<LimitCheckModel>();
            decimal decExp = trn1.KK_CONTRIBUTE.Value + (trn2 != null ? trn2.KK_CONTRIBUTE.Value : 0);

            foreach (var ori_cont in ori_conts)
            {
                tempCountry = deal_conts.FirstOrDefault(f => f.EXPOSURE_DATE == ori_cont.FLOW_DATE);

                ori_cont.DEAL_CONTRIBUTION = tempCountry != null ? tempCountry.EXPOSURE.Value : decExp;

                SetLimitDisplayStatus(ori_cont, blnOverwrite, ref limitDisplay);

                if ((ori_cont.FLOW_DATE == trn1.TRADE_DATE || ori_cont.FLOW_DATE == trn1.MATURITY_DATE)
                    || (trn2 != null && (ori_cont.FLOW_DATE == trn2.TRADE_DATE || ori_cont.FLOW_DATE == trn2.MATURITY_DATE))
                    || (ori_cont.STATUS == eLimitStatusCode.EXCEED.ToString() || ori_cont.STATUS == eLimitStatusCode.EXPIRED.ToString()))
                {
                    limits.Add(ori_cont);
                }
            }

            return limits;
        }
Exemplo n.º 11
0
        public string SubmitRepoDeal(SessionInfo sessioninfo
												 , DA_TRN trn
												 , string strOverApprover
												 , string strOverComment
												 , string strProductId)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
             if (!String.IsNullOrEmpty(strOverApprover))
             {
                 trn.OVER_APPROVER = strOverApprover;
                 trn.OVER_COMMENT = strOverComment;
             }

             using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
             {
                 Guid guTemp;
                 if (Guid.TryParse(strProductId, out guTemp))
                 {
                     var foundDeal = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == guTemp);
                     if (foundDeal == null)
                         throw this.CreateException(new Exception(), "Data not found!");
                     else
                     {
                         foundDeal.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
                         foundDeal.REMARK = trn.REMARK;
                     }
                 }
                 trn.REMARK = null;
                 if (trn.INT_DEAL_NO == null)
                     trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);
                 unitOfWork.DA_TRNRepository.Add(trn);
                 unitOfWork.Commit();
             }
             return trn.INT_DEAL_NO;
        }
Exemplo n.º 12
0
        public DA_TRN Update(SessionInfo sessioninfo, DA_TRN trn)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var foundData = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == trn.ID);
                if (foundData == null)
                    throw this.CreateException(new Exception(), "Data not found!");
                else
                {
                    foundData.LOG.MODIFYBYUSERID = trn.LOG.MODIFYBYUSERID;
                    foundData.LOG.MODIFYDATE = trn.LOG.MODIFYDATE;
                    foundData.EXT_DEAL_NO = trn.EXT_DEAL_NO;
                    foundData.EXT_PORTFOLIO = trn.EXT_PORTFOLIO;
                    foundData.STATUS_ID = trn.STATUS_ID;

                    unitOfWork.Commit();

                }
            }

            return trn;
        }
Exemplo n.º 13
0
        public static LimitDisplayModel CheckSwapSCE(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            DealBusiness _dealBusiness = new DealBusiness();

            return _dealBusiness.CheckSwapSCE(sessioninfo, trn, strExcludeID);
        }
Exemplo n.º 14
0
        public LimitDisplayModel CheckSwapSCE(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            InstrumentBusiness _insBusiness = new InstrumentBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            Guid guExcludeID = Guid.Empty;
            List<DA_TRN_CASHFLOW> deal_conts = new List<DA_TRN_CASHFLOW>();

            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 DA_TRN_CASHFLOW
                                {
                                    FLOW_DATE = p.Key.Flow_Date,
                                    FLOW_AMOUNT_THB = p.Sum(x => x.Flow_Amount_THB)
                                }).OrderBy(p => p.FLOW_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 DA_TRN_CASHFLOW
                                {
                                    FLOW_DATE = p.Key.Flow_Date,
                                    FLOW_AMOUNT_THB = p.Sum(x => x.Flow_Amount_THB)
                                }).Where(t => t.FLOW_AMOUNT_THB > 0).OrderBy(p => p.FLOW_DATE).ToList();
            }

            //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.CheckAllSET(sessioninfo.Process.CurrentDate, trn, guExcludeID, Guid.Empty);

            limitDisplay.LimitDisplayObject = GenerateSETDisplay(deal_conts, ori_conts, sessioninfo.SETOverwrite, ref limitDisplay);

            if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                trn.OVER_SETTL_AMOUNT = limitDisplay.OverAmount;

            return limitDisplay;
        }
Exemplo n.º 15
0
        public void CreatingTBMAReportFile(SessionInfo session, DA_TRN trn, MA_TBMA_CONFIG config)
        {
            string delimiter = "|";
             StringBuilder sb = new StringBuilder();
             string filePath = config.TBMA_RPT_PATH + (config.TBMA_RPT_PATH.EndsWith("\\") ? "" : "\\");

             if (!Directory.Exists(filePath))
                 Directory.CreateDirectory(filePath);

             filePath = filePath + config.TBMA_RPT_PREFIX + session.UserLogon + "-" + Guid.NewGuid().ToString().Replace("-","") + ".txt";

             sb.AppendLine(string.Join(delimiter, new string[]{"ORDER_NUM"
                                                                ,"TRADER_ID"
                                                                ,"PURPOSE"
                                                                ,"TRADE_TIME"
                                                                ,"TRADE_DATE"
                                                                ,"SETTLEMENT_DATE"
                                                                ,"TYPE","ISSUE_SYMBOL"
                                                                ,"YIELD","YIELD_TYPE"
                                                                ,"PRICE","VOLUME"
                                                                ,"COUNTER_PARTY"
                                                                ,"TERM"
                                                                ,"RATE"
                                                                ,"REMARK"}));

             sb.AppendLine(string.Join(delimiter, new string[]{"1"
                                                            , config.TBMA_RPT_TRADERID
                                                            , trn.DA_TMBA_EXTENSION.PURPOSE
                                                            , trn.LOG.INSERTDATE.ToString(FormatTemplate.TIMESTAMP_LABEL)
                                                            , trn.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL)
                                                            , trn.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL)
                                                            , trn.FLAG_BUYSELL
                                                            , trn.MA_INSRUMENT.LABEL
                                                            , trn.FIRST.RATE.Value.ToString("0.000000")
                                                            , trn.DA_TMBA_EXTENSION.YIELD_TYPE
                                                            , trn.DA_TMBA_EXTENSION.IS_REPORT_CLEAN ? trn.DA_TMBA_EXTENSION.CLEAN_PRICE.ToString() : trn.DA_TMBA_EXTENSION.GROSS_PRICE.ToString()
                                                            , trn.DA_TMBA_EXTENSION.UNIT.ToString()
                                                            , trn.MA_COUTERPARTY.TBMA_NAME
                                                            , trn.DA_TMBA_EXTENSION.TERM.ToString()
                                                            , trn.DA_TMBA_EXTENSION.RATE.ToString()
                                                            , trn.DA_TMBA_EXTENSION.REMARK }));

            File.AppendAllText(filePath, sb.ToString());

             if (!File.Exists(filePath))
                 throw this.CreateException(new Exception(), "Create file fail");
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
        public LimitDisplayModel CheckSCE(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            Guid guExcludeID = Guid.Empty;

            List<DA_TRN_CASHFLOW> deal_conts = (from f in trn.DA_TRN_FLOW
                                                where f.FLOW_AMOUNT_THB > 0
                                                select new DA_TRN_CASHFLOW
                                                {
                                                    FLOW_DATE = f.FLOW_DATE.Value,
                                                    FLOW_AMOUNT_THB = f.FLOW_AMOUNT_THB.Value
                                                }).ToList();

            //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.CheckAllSET(sessioninfo.Process.CurrentDate, trn, guExcludeID, Guid.Empty);

            limitDisplay.LimitDisplayObject = GenerateSETDisplay(deal_conts, ori_conts, sessioninfo.SETOverwrite , ref limitDisplay);

            if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                trn.OVER_SETTL_AMOUNT = limitDisplay.OverAmount;

            return limitDisplay;
        }
Exemplo n.º 18
0
        //public LimitDisplayModel CheckPCE(SessionInfo sessioninfo, DA_TRN trn)
        //{
        //    StaticDataBusiness _staticDataBusiness = new StaticDataBusiness();
        //    LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
        //    LimitDisplayModel limitDisplay = new LimitDisplayModel();
        //    trn.KK_PCCF = _staticDataBusiness.GetPCCF(sessioninfo, trn);
        //    if (trn.KK_PCCF != null)
        //    {
        //        trn.KK_CONTRIBUTE = Math.Ceiling(trn.NOTIONAL_THB.Value * trn.KK_PCCF.Value / 100);
        //        List<LimitCheckModel> limits = _limitCheckBusiness.GetPCEByCriteria(sessioninfo.Process.CurrentDate, trn.CTPY_ID, trn.PRODUCT_ID.Value, "", Guid.Empty, Guid.Empty);
        //        foreach (LimitCheckModel limit in limits)
        //        {
        //            limit.DEAL_CONTRIBUTION = trn.KK_CONTRIBUTE.Value;
        //            SetLimitDisplayStatus(limit, ref limitDisplay);
        //        }
        //        limitDisplay.LimitDisplayObject = limits;
        //    }
        //    else
        //    {
        //        limitDisplay.LimitCheckStatus = eLimitCheckStatus.NOTALLOW;
        //        limitDisplay.LimitErrorObj = new { Result = "ERROR", Message = "This deal breach allowed tenor." };
        //    }
        //    return limitDisplay;
        //}
        public LimitDisplayModel CheckPCE(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            StaticDataBusiness _staticDataBusiness = new StaticDataBusiness();
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            Guid guExcludeID = Guid.Empty;

            trn.KK_PCCF = _staticDataBusiness.GetPCCF(sessioninfo, trn);

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

            if (trn.KK_PCCF != null)
            {
                trn.KK_CONTRIBUTE = Math.Ceiling(trn.NOTIONAL_THB.Value * trn.KK_PCCF.Value / 100);

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

                foreach (LimitCheckModel limit in limits)
                {
                    limit.DEAL_CONTRIBUTION = trn.KK_CONTRIBUTE.Value;
                    SetLimitDisplayStatus(limit, sessioninfo.PCEOverwrite, ref limitDisplay);
                }

                if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                    trn.OVER_AMOUNT = limitDisplay.OverAmount;

                limitDisplay.LimitDisplayObject = limits;
            }
            else
            {
                limitDisplay.LimitCheckStatus = eLimitCheckStatus.ERROR;
                limitDisplay.Message = "This deal breach allowed tenor.";
            }

            return limitDisplay;
        }
Exemplo n.º 19
0
        public static object SubmitFXSwapDeal(SessionInfo sessioninfo
                                                , DA_TRN trn1
                                                , DA_TRN trn2
                                                , string strOverApprover
                                                , string strOverComment
                                                , string strProductId1
                                                , string strProductId2)
        {
            try
             {
                 DealBusiness _dealBusiness = new DealBusiness();

                 string strDealNO1 = _dealBusiness.SubmitFXDeal(sessioninfo
                                                                 , trn1
                                                                 , strOverApprover
                                                                 , strOverComment
                                                                 , strProductId1);
                 trn2.INT_DEAL_NO = strDealNO1;
                 string strDealNO2 = _dealBusiness.SubmitFXDeal(sessioninfo
                                                                 , trn2
                                                                 , strOverApprover
                                                                 , strOverComment
                                                                 , strProductId2
                                                                 );
                 return new { Result = "OK", Message = strDealNO1 };
             }
             catch (Exception ex)
             {
                 return new { Result = "ERROR", Message = ex.Message };
             }
        }
Exemplo n.º 20
0
 public static object CancelDeal(DA_TRN record)
 {
     return DealViewUIP.CancelDeal(SessionInfo, record);
 }
Exemplo n.º 21
0
        public static object SubmitSwapDeal(SessionInfo sessioninfo
                                                , DA_TRN trn
                                                , string strOverApprover
                                                , string strOverComment
                                                , string strProductId)
        {
            try
                {
                    DealBusiness _dealBusiness = new DealBusiness();

                    string strDealNO = _dealBusiness.SubmitSwapDeal(sessioninfo
                                                                    , trn
                                                                    , strOverApprover
                                                                    , strOverComment
                                                                    , strProductId);

                    return new { Result = "OK", Message = strDealNO };
                }
                catch (Exception ex)
                {
                    return new { Result = "ERROR", Message = ex.Message };
                }
        }
Exemplo n.º 22
0
        private static void CheckFXSpotLimits(Boolean blnIsSubmit, DA_TRN record, DA_TRN record2, out object PCESCEObject)
        {
            try
            {
                LimitDisplayModel PCECheckRecords = DealUIP.CheckFXSwapPCE(SessionInfo, record, record2, ProductId);
                LimitDisplayModel SCECheckRecords = record.FLAG_SETTLE.Value ?  DealUIP.CheckFXSwapSCE(SessionInfo, record, record2, ProductId) : null;
                LimitDisplayModel CountryCheckRecords = DealUIP.CheckFXSwapCountryLimit(SessionInfo, record, record2, ProductId);

                PCESCEObject = ConsoLimitDisplay(blnIsSubmit, PCECheckRecords, SCECheckRecords, CountryCheckRecords);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 23
0
        public void GenerateCashFlows(SessionInfo sessioninfo, DA_TRN trn, int intDaySpan, decimal firstRate, decimal secondRate)
        {
            DateTime dteActualFlow;
            DateTime dteLastActualFlow;
            DateTime dteEstFlow;
            int intCFSeq;
            decimal spotrate;
            //string strLegFreq;

            DA_TRN_CASHFLOW flow;

            LookupBusiness _lookupBusiness = new LookupBusiness();
            int addMonth = 1; //default for Month
            int addDay = 1;
            MA_FREQ_TYPE freq = null;
            InstrumentBusiness _insBusiness = new InstrumentBusiness();

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

            for (int intLeg = 1; intLeg <= 2; intLeg++)
            {
                dteActualFlow = dteEstFlow = dteLastActualFlow = trn.START_DATE.Value.Date;

                //CCS : 4 priciple payment flows will be generated, 2 on initial payment date and 2 on maturity date
                if (ins.LABEL == "CCS")
                {
                    //Initial Exchange
                    flow = new DA_TRN_CASHFLOW();

                    flow.FLAG_FIRST = intLeg == 1 ? true : false;
                    flow.SEQ = 1;
                    flow.FLOW_DATE = trn.START_DATE;
                    flow.FLOW_AMOUNT = intLeg == 1 ? trn.FIRST.NOTIONAL : -trn.SECOND.NOTIONAL;
                    flow.FLOW_AMOUNT_THB = intLeg == 1 ? Math.Ceiling(flow.FLOW_AMOUNT.Value * firstRate) : Math.Ceiling(flow.FLOW_AMOUNT.Value * secondRate);

                    flow.ID = Guid.NewGuid();
                    flow.DA_TRN_ID = trn.ID;
                    flow.LOG.INSERTDATE = trn.LOG.INSERTDATE;
                    flow.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;
                    trn.DA_TRN_FLOW.Add(flow);
                }

                intCFSeq = 2;

                freq = intLeg == 1 ? _lookupBusiness.GetFreqByID(trn.FIRST.FREQTYPE_ID.Value) : _lookupBusiness.GetFreqByID(trn.SECOND.FREQTYPE_ID.Value);

                do
                {
                    if ((FrequencyType)Enum.Parse(typeof(FrequencyType), freq.USERCODE) == FrequencyType.W)
                    {
                        dteActualFlow = dteActualFlow.AddDays(7);
                    }
                    else if ((FrequencyType)Enum.Parse(typeof(FrequencyType), freq.USERCODE) == FrequencyType.B)
                    {
                        dteActualFlow = trn.MATURITY_DATE.Value;
                    }
                    else if (((FrequencyType)Enum.Parse(typeof(FrequencyType), freq.USERCODE)).ToString().StartsWith("D"))
                    {
                        addDay = (int)Enum.Parse(typeof(FrequencyType), freq.USERCODE).GetHashCode();
                        dteActualFlow = dteActualFlow.AddDays(addDay);
                    }
                    else
                    {
                        addMonth = (int)Enum.Parse(typeof(FrequencyType), freq.USERCODE).GetHashCode();
                        dteActualFlow = dteActualFlow.AddMonths(addMonth);
                    }

                    for (int i = -intDaySpan; i <= intDaySpan; i++)
                    {
                        flow = new DA_TRN_CASHFLOW();

                        dteEstFlow = dteActualFlow.AddDays(i);

                        flow.FLAG_FIRST = intLeg == 1 ? true : false;
                        flow.SEQ = intCFSeq;

                        if (intLeg == 1)
                        {
                            flow.RATE = trn.FIRST.FLAG_FIXED == true ? trn.FIRST.RATE : trn.FIRST.RATE + trn.FIRST.FIRSTFIXINGAMT;
                            flow.FLOW_AMOUNT = trn.FIRST.NOTIONAL * flow.RATE / 100 * Convert.ToDecimal((dteEstFlow - dteLastActualFlow).TotalDays) / 365;
                            spotrate = firstRate;
                        }
                        else
                        {
                            flow.RATE = trn.SECOND.FLAG_FIXED == true ? trn.SECOND.RATE : trn.SECOND.RATE + trn.SECOND.FIRSTFIXINGAMT;
                            flow.FLOW_AMOUNT = trn.SECOND.NOTIONAL * flow.RATE / 100 * Convert.ToDecimal((dteEstFlow - dteLastActualFlow).TotalDays) / 365;
                            spotrate = secondRate;
                        }

                        flow.FLOW_DATE = dteEstFlow;

                        if (intLeg == 1) //flow amount is negative for pay leg
                            flow.FLOW_AMOUNT = -flow.FLOW_AMOUNT;

                        flow.FLOW_AMOUNT_THB = flow.FLOW_AMOUNT > 0 ? Math.Ceiling(flow.FLOW_AMOUNT.Value * spotrate) : Math.Floor(flow.FLOW_AMOUNT.Value * spotrate);

                        flow.ID = Guid.NewGuid();
                        flow.DA_TRN_ID = trn.ID;
                        flow.LOG.INSERTDATE = trn.LOG.INSERTDATE;
                        flow.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

                        trn.DA_TRN_FLOW.Add(flow);
                        intCFSeq += 1;
                    }

                    dteLastActualFlow = dteActualFlow;
                } while (dteActualFlow < trn.MATURITY_DATE.Value.Date);

                if (ins.LABEL == "CCS")
                {
                    //Maturity Exchange
                    flow = new DA_TRN_CASHFLOW();

                    flow.FLAG_FIRST = intLeg == 1 ?  true : false;
                    flow.SEQ = intCFSeq;
                    flow.FLOW_DATE = trn.MATURITY_DATE;
                    flow.FLOW_AMOUNT = intLeg == 1 ? -trn.FIRST.NOTIONAL : trn.SECOND.NOTIONAL;
                    flow.FLOW_AMOUNT_THB = intLeg == 1 ? Math.Ceiling(flow.FLOW_AMOUNT.Value * firstRate) : Math.Ceiling(flow.FLOW_AMOUNT.Value * secondRate);

                    flow.ID = Guid.NewGuid();
                    flow.DA_TRN_ID = trn.ID;
                    flow.LOG.INSERTDATE = trn.LOG.INSERTDATE;
                    flow.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;
                    trn.DA_TRN_FLOW.Add(flow);
                }
            }
        }
Exemplo n.º 24
0
        public LimitDisplayModel CheckFXSwapSCE(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;

            List<DA_TRN_CASHFLOW> deal_conts = ((from f in trn1.DA_TRN_FLOW
                                               where f.FLOW_AMOUNT_THB > 0
                                                 select new DA_TRN_CASHFLOW
                                               {
                                                   FLOW_DATE = f.FLOW_DATE.Value,
                                                   FLOW_AMOUNT_THB = f.FLOW_AMOUNT_THB.Value
                                               }).Union(
                                              (from f in trn2.DA_TRN_FLOW
                                               where f.FLOW_AMOUNT_THB > 0
                                               select new DA_TRN_CASHFLOW
                                               {
                                                   FLOW_DATE = f.FLOW_DATE.Value,
                                                   FLOW_AMOUNT_THB = f.FLOW_AMOUNT_THB.Value
                                               })
                                               )).ToList();

            //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.CheckAllSET(sessioninfo.Process.CurrentDate, trn1, guExcludeID1, guExcludeID2);

            limitDisplay.LimitDisplayObject = GenerateSETDisplay(deal_conts, ori_conts, sessioninfo.SETOverwrite, ref limitDisplay);

            if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
            {
                trn1.OVER_SETTL_AMOUNT = limitDisplay.OverAmount;
                trn2.OVER_SETTL_AMOUNT = limitDisplay.OverAmount;
            }

            return limitDisplay;
        }
Exemplo n.º 25
0
        public decimal? GetPCCF(SessionInfo sessioninfo, DA_TRN trn)
        {
            try
            {
                decimal? decPCCF = null;
                LookupBusiness _lookupBusiness = new LookupBusiness();
                PCCFConfigBusiness _pccfBusiness = new PCCFConfigBusiness();

                MA_PRODUCT product = _lookupBusiness.GetProductByID(sessioninfo, trn.PRODUCT_ID.Value);
                ProductCode nProduct = (ProductCode)Enum.Parse(typeof(ProductCode), product.LABEL.Replace(" ", string.Empty));

                MA_PCCF pccf = _pccfBusiness.ValidatePCCFConfig(sessioninfo, trn);

                //if (pccf == null)
                //    throw this.CreateException(new Exception(), "Cannot find PCCF for transaction #" + trn.EXT_DEAL_NO);

                if (nProduct == ProductCode.BOND || nProduct == ProductCode.REPO)
                {
                    InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();

                    //------Check whether seleted bond can be used.---------
                    MA_INSTRUMENT ins = _instrumentBusiness.GetByID(sessioninfo, trn.INSTRUMENT_ID.Value);

                    if (trn.MATURITY_DATE >= ins.MATURITY_DATE)
                    {
                        throw this.CreateException(new Exception(), "Settlement date cannot be equal or after bond maturity date.");
                    }

                    if (pccf == null)
                        throw this.CreateException(new Exception(), "Selected instrument cannot be used.");
                    //-------------------------------------------------------

                    decPCCF = LimitHelper.GetPCCFValue(pccf, LimitHelper.GetYearBucket(trn.START_DATE.Value, ins.MATURITY_DATE.Value));
                }
                else
                {
                    if (pccf == null)
                        throw this.CreateException(new Exception(), "PCCF is not defined in the system." + "RF");

                    if (nProduct == ProductCode.SWAP)
                    {
                        decPCCF = LimitHelper.GetPCCFValue(pccf, LimitHelper.GetYearBucket(trn.START_DATE.Value, trn.MATURITY_DATE.Value));
                    }
                    else if (nProduct == ProductCode.FXSPOT)
                    {
                        decPCCF = pccf.DEFAULT;
                    }
                    else if (nProduct == ProductCode.FXFORWARD)
                    {
                        decPCCF = LimitHelper.GetPCCFValue(pccf, LimitHelper.GetMonthBucket(trn.START_DATE.Value, trn.MATURITY_DATE.Value));
                    }
                    else if (nProduct == ProductCode.FXSWAP)
                    {
                        if (trn.TRADE_DATE == trn.MATURITY_DATE)
                        {
                            decPCCF = pccf.C0D;
                        }
                        else if (trn.MATURITY_DATE < trn.SPOT_DATE)
                        {
                            decPCCF = pccf.C1D;
                        }
                        else if (trn.MATURITY_DATE == trn.SPOT_DATE)
                        {
                            decPCCF = pccf.DEFAULT;
                        }
                        else
                        {
                            decPCCF = LimitHelper.GetPCCFValue(pccf, LimitHelper.GetMonthBucket(trn.START_DATE.Value, trn.MATURITY_DATE.Value));
                        }
                    }
                }

                return decPCCF;
            }
            catch (Exception ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Exemplo n.º 26
0
        public DA_TRN GenerateFITransactionObject(SessionInfo sessionInfo
                                                    , string strTradeDate
                                                    , string strBuySell
                                                    , string strInstrument
                                                    , string strCtpy
                                                    , string strPortfolio
                                                    , string strSettlementDate
                                                    , string strYield
                                                    , string strUnit
                                                    , string strCleanPrice
                                                    , string strGrossPrice
                                                    , string strNotional
                                                    , string strCCY
                                                    , string strPceFlag
                                                    , string strSettleFlag
                                                    , string strYeildType
                                                    , string strReportBy
                                                    , string strPurpose
                                                    , string strTerm
                                                    , string strRate
                                                    , string strTBMARemark
                                                    , string strRemark
                                                    , string strProductId)
        {
            //Validate business logics here
            //throw error to UI if fail validation
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn = null;
            DateTime dteTemp;
            Decimal decTemp;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp))
            {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;

            if (strCtpy == "null")
                throw this.CreateException(new Exception(), "Please input counterparty.");
            else
                trn.CTPY_ID = Guid.Parse(strCtpy);

            if (String.IsNullOrEmpty(strTradeDate))
                throw this.CreateException(new Exception(), "Please input trade date.");
            else if (!DateTime.TryParseExact(strTradeDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid trade date.");
            else
                trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);

            if (String.IsNullOrEmpty(strSettlementDate))
                throw this.CreateException(new Exception(), "Please input settlement date.");
            else if (!DateTime.TryParseExact(strSettlementDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid settlement date.");
            else
            {
                trn.MATURITY_DATE = DateTime.ParseExact(strSettlementDate, "dd/MM/yyyy", null);
                trn.START_DATE = trn.MATURITY_DATE;
            }

            if (strInstrument == "null")
                throw this.CreateException(new Exception(), "Please input instrument.");
            else
                trn.INSTRUMENT_ID = Guid.Parse(strInstrument);

            if (String.IsNullOrEmpty(strNotional))
                throw this.CreateException(new Exception(), "Please input notional amount.");
            else if (!Decimal.TryParse(strNotional, out decTemp))
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else if (Convert.ToDecimal(strNotional) <= 0)
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else
                trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional);

            if (strPortfolio == "-1")
                throw this.CreateException(new Exception(), "Please select portfolio.");
            else
                trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);

            if (trn.MATURITY_DATE < trn.TRADE_DATE)
            {
                throw this.CreateException(new Exception(), "Settlement date cannot be before trade date.");
            }
            if ((strPurpose.Trim() == TBMA_PURPOSE.FIN.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINB.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINP.ToString()) && (strTBMARemark.Trim() == string.Empty || strRate.Trim() == string.Empty || strTerm.Trim() == string.Empty))
            {
                throw this.CreateException(new Exception(), "Please input Term, Rate and Remark.");
            }
            if (lastrn != null) {
                if (strRemark == "")
                    throw this.CreateException(new Exception(), "Please input comment.");
                else trn.REMARK = strRemark;
            }
            trn.ID = Guid.NewGuid();
            trn.FLAG_SETTLE = strSettleFlag == "1" ? true : false;
            trn.FLAG_BUYSELL = strBuySell;
            trn.FIRST.CCY_ID = Guid.Parse(strCCY);
            trn.FIRST.RATE = Convert.ToDecimal(strYield);
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.SOURCE = SourceType.INT.ToString();
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == trn.TRADE_DATE);
            if (a == null)
            {
                var ccys = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                throw this.CreateException(new Exception(), "Error : There is no " + ccys.LABEL + " spot rate on " + strTradeDate + " trade date.");
            }
            trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
            trn.FLAG_PCE = strPceFlag == "1" ? true : false;
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();
            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FLAG_BUYSELL == "B" ? -trn.FIRST.NOTIONAL : trn.FIRST.NOTIONAL;
            flow1.FLOW_AMOUNT_THB = trn.FLAG_BUYSELL == "B" ? -trn.NOTIONAL_THB : trn.NOTIONAL_THB;
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;
            trn.DA_TRN_FLOW.Add(flow1);

            DA_TMBA_EXTENSION tbma = new DA_TMBA_EXTENSION();
            tbma.ID = trn.ID;
            tbma.PURPOSE = strPurpose;
            tbma.YIELD_TYPE = strYeildType;
            tbma.CLEAN_PRICE = Convert.ToDecimal(strCleanPrice);
            tbma.GROSS_PRICE = Convert.ToDecimal(strGrossPrice);
            tbma.UNIT = Convert.ToInt32(strUnit);
            if (strTerm != string.Empty)
                tbma.TERM = Convert.ToInt32(strTerm);
            if (strRate != string.Empty)
                tbma.RATE = Convert.ToDecimal(strRate);
            if (strTBMARemark != string.Empty)
                tbma.REMARK = strTBMARemark;
            tbma.IS_REPORT_CLEAN = strReportBy == "0" ? true : false;

            if (lastrn != null)
            {
                tbma.SEND_DATE = lastrn.DA_TMBA_EXTENSION.SEND_DATE;
                tbma.SENDER_ID = lastrn.DA_TMBA_EXTENSION.SENDER_ID;
            }

            trn.DA_TMBA_EXTENSION = tbma;
            return trn;
        }
Exemplo n.º 27
0
        private static void CheckFILimit(Boolean blnIsSubmit, DA_TRN record, out object PCESCEObject)
        {
            try
            {
                LimitDisplayModel PCECheckRecords = DealUIP.CheckPCE(SessionInfo, record, ProductId);
                LimitDisplayModel SCECheckRecords = null;
                LimitDisplayModel CountryCheckRecords = DealUIP.CheckCountryLimit(SessionInfo, record, ProductId);

                var flagSettle = record.FLAG_SETTLE.Value && record.NOTIONAL_THB.Value > 0;

                if (flagSettle) {
                    SCECheckRecords = DealUIP.CheckSCE(SessionInfo, record, ProductId);
                }

                PCESCEObject = ConsoLimitDisplay(blnIsSubmit, PCECheckRecords, SCECheckRecords, CountryCheckRecords);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 28
0
        public DA_TRN GenerateFXSpotTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strSpotDate, string strCtpy, string strPortfolio
														, string strCurrencyPair, string strBS, string strContractCcy, string strCounterCcy
                                                        , string strSpotRate, string strContractAmt, string strCounterAmt, string strRemark, bool settleFlag, string strProductId)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn  = null;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp)) {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ID = Guid.NewGuid();
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
            trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
            trn.START_DATE = trn.TRADE_DATE;
            trn.MATURITY_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null);
            trn.CTPY_ID = Guid.Parse(strCtpy);
            trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
            trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair);
            trn.FIRST.CCY_ID = Guid.Parse(strContractCcy);
            trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy);
            trn.FIRST.RATE = Convert.ToDecimal(strSpotRate);
            trn.FLAG_BUYSELL = strBS;
            trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmt) : -Convert.ToDecimal(strContractAmt);
            trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmt) : Convert.ToDecimal(strCounterAmt);
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            trn.SOURCE = SourceType.INT.ToString();
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID;
            trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P";
            trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R";
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.FLAG_SETTLE = !settleFlag;
            trn.REMARK = strRemark;
            var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
            var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID  && p.LABEL == "THB");
            var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID  && p.LABEL == "THB");
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            if (n1 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value);
            else if (n2 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value);
            else
            {
                var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);

                if (firstRate != null && secondRate != null)
                {
                    if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                        trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                    else
                        trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
             }

            //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn);
            //trn.KK_CONTRIBUTE = trn.NOTIONAL_THB.Value * trn.KK_PCCF / 100;

            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.RATE = trn.FIRST.RATE;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL;
            if (n1 != null)
                flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null){
                    flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
                }
                else{
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }

            }
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

            flow2.ID = Guid.NewGuid();
            flow2.DA_TRN_ID = trn.ID;
            flow2.FLAG_FIRST = false;
            flow2.FLOW_DATE = trn.MATURITY_DATE;
            flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL;
            if (n2 != null)
                flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null)
                {
                    flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
            }

            flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            trn.DA_TRN_FLOW.Add(flow1);
            trn.DA_TRN_FLOW.Add(flow2);
            return trn;
        }
Exemplo n.º 29
0
        public static object CancelDeal(SessionInfo sessioninfo, DA_TRN trn)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                UserBusiness _userBusiness = new UserBusiness();
                DealBusiness _dealbusiness = new DealBusiness();
                DA_TRN t = _dealbusiness.CancelDeal(sessioninfo, trn);
                DA_TRN t2 = _dealbusiness.GetDealByDealNo(t.INT_DEAL_NO,t.VERSION).FirstOrDefault(p => p.ID != t.ID);
                if (t2 != null) _dealbusiness.CancelDeal(sessioninfo, t2);
                var inputuser = _userBusiness.GetAll().FirstOrDefault(u => u.ID == t.LOG.INSERTBYUSERID);

                var query = new DealViewModel
                            {
                                ID = t.ID,
                                EntryDate = t.LOG.INSERTDATE,
                                DMK_NO = t.INT_DEAL_NO
                                ,
                                OPICS_NO = t.EXT_DEAL_NO,
                                TradeDate = t.TRADE_DATE.Value
                                ,
                                EffectiveDate = t.START_DATE,
                                Instrument = t.MA_INSRUMENT.LABEL
                                ,
                                MaturityDate = t.MATURITY_DATE,
                                BuySell = t.FLAG_BUYSELL
                                ,
                                Product = t.MA_PRODUCT.LABEL,
                                Portfolio = t.MA_PORTFOLIO.LABEL
                                ,
                                Counterparty = t.MA_COUTERPARTY.SNAME,
                                Notional1 = t.FIRST.NOTIONAL
                                ,
                                PayRec1 = t.FIRST.FLAG_PAYREC,
                                FixedFloat1 = !t.FIRST.FLAG_FIXED.HasValue ? null : t.FIRST.FLAG_FIXED.Value ? "FIXED" : "FLOAT"
                                ,
                                Rate1 = t.FIRST.RATE,
                                Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                                SwapPoint1 = t.FIRST.SWAP_POINT,
                                Notional2 = t.SECOND.NOTIONAL
                                ,
                                PayRec2 = t.SECOND.FLAG_PAYREC,
                                FixedFloat2 = !t.SECOND.FLAG_FIXED.HasValue ? null : t.SECOND.FLAG_FIXED == true ? "FIXED" : "FLOAT"
                                ,
                                Rate2 = t.SECOND.RATE,
                                Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                                SwapPoint2 = t.SECOND.SWAP_POINT,
                                Status =  _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.ID == t.STATUS_ID).LABEL
                                ,
                                KKContribute = t.KK_CONTRIBUTE,
                                BotContribute = t.BOT_CONTRIBUTE
                                ,
                                LimitOverwrite = string.IsNullOrEmpty(t.OVER_APPROVER) ? "No" : t.OVER_AMOUNT > 0 && t.OVER_SETTL_AMOUNT > 0 ? "Yes" : t.OVER_AMOUNT > 0 ? "PCE" : "SET"
                                ,
                                LimitApprover = t.OVER_APPROVER
                                ,
                                Trader = inputuser != null ? inputuser.USERCODE : ""
                                ,
                                Remark = t.REMARK
                            };
                return new { Result = "OK", Record = query, DealPairID = t2 != null? t2.ID.ToString() : string.Empty };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Exemplo n.º 30
0
        public LimitDisplayModel CheckFXSwapPCE(SessionInfo sessioninfo, DA_TRN trn1, DA_TRN trn2, string strExcludeID)
        {
            StaticDataBusiness _staticDataBusiness = new StaticDataBusiness();
            LimitCheckBusiness _limitCheckBusiness = new LimitCheckBusiness();
            LimitDisplayModel limitDisplay = new LimitDisplayModel();
            DA_TRN oldtrn1 = null;
            DA_TRN oldtrn2 = null;
            Guid guExcludeID1 = Guid.Empty;
            Guid guExcludeID2 = Guid.Empty;

            //Exposure include far leg only -> set near leg to 0
            trn1.KK_PCCF = 0;
            trn2.KK_PCCF = _staticDataBusiness.GetPCCF(sessioninfo, trn2);

            //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;
            }

            if (trn1.KK_PCCF != null && trn2.KK_PCCF != null)
            {
                trn1.KK_CONTRIBUTE = 0;
                trn2.KK_CONTRIBUTE = Math.Ceiling(trn2.NOTIONAL_THB.Value * trn2.KK_PCCF.Value / 100);

                List<LimitCheckModel> limits = _limitCheckBusiness.CheckAllPCE(sessioninfo.Process.CurrentDate, trn1, guExcludeID1, guExcludeID2);

                foreach (LimitCheckModel limit in limits)
                {
                    limit.DEAL_CONTRIBUTION = trn1.KK_CONTRIBUTE.Value + trn2.KK_CONTRIBUTE.Value;
                    SetLimitDisplayStatus(limit, sessioninfo.PCEOverwrite, ref limitDisplay);
                }

                if (limitDisplay.LimitCheckStatus == eLimitCheckStatus.NEEDAPPROVE)
                {
                    trn1.OVER_AMOUNT = limitDisplay.OverAmount;
                    trn2.OVER_AMOUNT = limitDisplay.OverAmount;
                }

                limitDisplay.LimitDisplayObject = limits;
            }
            else
            {
                limitDisplay.LimitCheckStatus = eLimitCheckStatus.ERROR;
                limitDisplay.Message = "This deal breach allowed tenor.";
            }

            return limitDisplay;
        }