Example #1
0
        public static object UpdateSpotRate(SessionInfo sessioninfo, MA_SPOT_RATE record)
        {
            try
            {
                LookupBusiness _lookupbusiness = new LookupBusiness();

                var updated = _lookupbusiness.UpdateSpotRate(sessioninfo, record);
                return new { Result = "OK" };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
 public static object Update(MA_SPOT_RATE record)
 {
     return LookupUIP.UpdateSpotRate(SessionInfo, record);
 }
Example #3
0
        public static object CreateSpotRate(SessionInfo sessioninfo, MA_SPOT_RATE record)
        {
            try
            {
                LookupBusiness _lookupbusiness = new LookupBusiness();
                record.ID = Guid.NewGuid();

                var added = _lookupbusiness.CreateSpotRate(sessioninfo, record);
                return new { Result = "OK", Record = added };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Example #4
0
        /// <summary>
        /// Generate DA_TRN object from Opics Transaction
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="opicdeal"></param>
        /// <param name="processdate"></param>
        private static DA_TRN GenerateTrnObject(SessionInfo sessioninfo, DEALModel opicdeal, DA_TRN dmkDeal, DateTime processdate)
        {
            StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();

            LoggingHelper.Debug("Generate transaction object : " + opicdeal.EXT_DEAL_NO);
            DA_TRN newDeal = CreateDealTemplate(sessioninfo);
            try
            {

            newDeal.ENGINE_DATE = processdate;
            newDeal.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.MATCHED.ToString()).ID;
            newDeal.PRODUCT_ID = _lookupvaluesRepository.ProductRepository.GetByLabel(opicdeal.PRODUCT.Trim()).ID;
            //newDeal.INT_DEAL_NO = dmkNo;
            newDeal.EXT_DEAL_NO = opicdeal.EXT_DEAL_NO;
            //newDeal.VERSION = 1;
            newDeal.SOURCE = SourceType.EXT.ToString();
            newDeal.CTPY_ID = _counterpartyBusiness.GetByUsercode(Convert.ToInt32(opicdeal.CPTY.Trim())).ID;
            newDeal.EXT_PORTFOLIO = opicdeal.EXT_PORTFOLIO;
            newDeal.FLAG_BUYSELL = opicdeal.BUY_SELL;
            if (!String.IsNullOrEmpty(opicdeal.PORTFOLIO.Trim()))
                newDeal.PORTFOLIO_ID = _lookupvaluesRepository.PortfolioRepository.GetByLabel(opicdeal.PORTFOLIO.Trim()).ID;
            newDeal.START_DATE = opicdeal.START_DATE;
            newDeal.MATURITY_DATE = opicdeal.MATURITY_DATE;
            newDeal.TRADE_DATE = opicdeal.TRADE_DATE;
            newDeal.INSERT_BY_EXT = opicdeal.INSERT_BY_EXT;
            newDeal.FLAG_SETTLE = dmkDeal != null && dmkDeal.FLAG_SETTLE != null ? dmkDeal.FLAG_SETTLE : opicdeal.FLAG_SETTLE == 1 ? true : false;

            if (dmkDeal != null)
            {
                newDeal.INT_DEAL_NO = dmkDeal.INT_DEAL_NO;
                newDeal.VERSION = dmkDeal.VERSION;
                newDeal.REMARK = dmkDeal.REMARK + " " + opicdeal.REMARK;

                newDeal.LOG.INSERTDATE = dmkDeal.LOG.INSERTDATE;
                newDeal.LOG.INSERTBYUSERID = dmkDeal.LOG.INSERTBYUSERID;

                //newDeal.FLAG_SETTLE = dmkDeal.FLAG_SETTLE;
                newDeal.OVER_AMOUNT = dmkDeal.OVER_AMOUNT;
                newDeal.OVER_APPROVER = dmkDeal.OVER_APPROVER;
                newDeal.OVER_COMMENT = dmkDeal.OVER_COMMENT;
                newDeal.OVER_SETTL_AMOUNT = dmkDeal.OVER_SETTL_AMOUNT;
            }
            else
            {
                newDeal.VERSION = 1;
            }

            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            MA_SPOT_RATE firstrate = new MA_SPOT_RATE();
            MA_SPOT_RATE secondRate = new MA_SPOT_RATE();

            switch ((ProductCode)Enum.Parse(typeof(ProductCode), opicdeal.PRODUCT.Replace(" ", string.Empty)))
            {
                case ProductCode.BOND:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetByLabel(sessioninfo, opicdeal.INSTRUMENT.Trim()).ID;

                    //First only
                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;
                    newDeal.FIRST.NOTIONAL = opicdeal.NOTIONAL1;

                    //THB Notional
                    var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.FIRST.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);

                    if (firstRate != null)
                    {
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE);
                    }
                    else
                    {
                        throw new UIPException(new Exception(), "Error : There is no " + opicdeal.CCY1 + " spot rate on " + newDeal.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL));
                    }
                    newDeal.FLAG_PCE = dmkDeal != null && dmkDeal.FLAG_PCE != null ? dmkDeal.FLAG_PCE : false;

                    newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                    newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);

                    break;
                case ProductCode.REPO:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetByLabel(sessioninfo, opicdeal.INSTRUMENT.Trim()).ID;

                    //First only
                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;
                    newDeal.FIRST.NOTIONAL = newDeal.NOTIONAL_THB = opicdeal.NOTIONAL1;

                    newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                    newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);

                    break;
                case ProductCode.SWAP:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetByLabel(sessioninfo, opicdeal.INSTRUMENT.Trim()).ID;

                    //First and Second
                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;

                    if (!String.IsNullOrEmpty(opicdeal.FREQ1))
                        newDeal.FIRST.FREQTYPE_ID = _lookupvaluesRepository.FrequencyRepository.GetByUsercode(opicdeal.FREQ1).ID;

                    newDeal.FIRST.FIRSTFIXINGAMT = opicdeal.FIRST_FIXING1;
                    newDeal.FIRST.FLAG_FIXED = opicdeal.FIXED_FLOAT1 == CouponType.FIXED.ToString() ? true : false;
                    newDeal.FIRST.FLAG_PAYREC = opicdeal.PAY_REC1;
                    newDeal.FIRST.NOTIONAL = newDeal.NOTIONAL_THB = opicdeal.NOTIONAL1;
                    newDeal.FIRST.RATE = opicdeal.RATE1;

                    //Second
                    if (!String.IsNullOrEmpty(opicdeal.CCY2))
                        newDeal.SECOND.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY2).ID;

                    if (!String.IsNullOrEmpty(opicdeal.FREQ2))
                        newDeal.SECOND.FREQTYPE_ID = _lookupvaluesRepository.FrequencyRepository.GetByUsercode(opicdeal.FREQ2).ID;

                    newDeal.SECOND.FIRSTFIXINGAMT = opicdeal.FIRST_FIXING2;
                    newDeal.SECOND.FLAG_FIXED = opicdeal.FIXED_FLOAT2 == CouponType.FIXED.ToString() ? true : false;
                    newDeal.SECOND.FLAG_PAYREC = opicdeal.PAY_REC2;
                    newDeal.SECOND.NOTIONAL = opicdeal.NOTIONAL2;
                    newDeal.SECOND.RATE = opicdeal.RATE2;

                    //THB Notional
                    if (opicdeal.CCY1 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value);
                    else if (opicdeal.CCY2 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value);
                    else
                    {
                        firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.FIRST.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);
                        secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.SECOND.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);

                        if (firstRate != null && secondRate != null)
                        {
                            if (Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE))
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE);
                            else
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE);
                        }
                        else
                        {
                            string mess = string.Empty;
                            mess += firstRate == null ? opicdeal.CCY1 : string.Empty;
                            mess += secondRate == null ? (mess != string.Empty ? " and " + opicdeal.CCY2 : opicdeal.CCY2) : string.Empty;
                            throw new UIPException(new Exception(), "Error : There is no " + mess + " spot rate on " + newDeal.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL));
                        }
                    }

                    newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                    newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);

                    //newDeal.BOT_PCCF = _staticdataBusiness.GetSwapBOTPCCF(sessioninfo, newDeal);
                    //newDeal.BOT_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.BOT_PCCF.Value / 100);

                    break;
                case ProductCode.FXSPOT:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetFXInstrumentByCCY(sessioninfo, ProductCode.FXSPOT, opicdeal.CCY1, opicdeal.CCY2).ID;

                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;
                    newDeal.FIRST.FLAG_PAYREC = opicdeal.PAY_REC1;
                    newDeal.FIRST.NOTIONAL = opicdeal.NOTIONAL1;
                    newDeal.FIRST.RATE = opicdeal.RATE1;

                    if (!String.IsNullOrEmpty(opicdeal.CCY2))
                        newDeal.SECOND.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY2).ID;
                    newDeal.SECOND.FLAG_PAYREC = opicdeal.PAY_REC2;
                    newDeal.SECOND.NOTIONAL = opicdeal.NOTIONAL2;

                    //THB Notional
                    if (opicdeal.CCY1 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value);
                    else if (opicdeal.CCY2 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value);
                    else
                    {
                        firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.FIRST.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);
                        secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.SECOND.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);

                        if (firstRate != null && secondRate != null)
                        {
                            if (Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE))
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE);
                            else
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE);
                        }
                        else
                        {
                            string mess = string.Empty;
                            mess += firstRate == null ? opicdeal.CCY1 : string.Empty;
                            mess += secondRate == null ? (mess != string.Empty ? " and " + opicdeal.CCY2 : opicdeal.CCY2) : string.Empty;
                            throw new UIPException(new Exception(), "Error : There is no " + mess + " spot rate on " + newDeal.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL));
                        }
                    }

                    newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                    newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);

                    break;

                case ProductCode.FXFORWARD:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetFXInstrumentByCCY(sessioninfo, ProductCode.FXFORWARD, opicdeal.CCY1, opicdeal.CCY2).ID;
                    newDeal.START_DATE = dmkDeal != null ? dmkDeal.START_DATE : opicdeal.START_DATE;

                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;
                    newDeal.FIRST.FLAG_PAYREC = opicdeal.PAY_REC1;
                    newDeal.FIRST.NOTIONAL = opicdeal.NOTIONAL1;
                    newDeal.FIRST.RATE = opicdeal.RATE1;
                    newDeal.FIRST.SWAP_POINT = opicdeal.SWAP_POINT1;

                    if (!String.IsNullOrEmpty(opicdeal.CCY2))
                        newDeal.SECOND.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY2).ID;
                    newDeal.SECOND.FLAG_PAYREC = opicdeal.PAY_REC2;
                    newDeal.SECOND.NOTIONAL = opicdeal.NOTIONAL2;
                    newDeal.SECOND.SWAP_POINT = opicdeal.SWAP_POINT2;

                    //THB Notional
                    if (opicdeal.CCY1 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value);
                    else if (opicdeal.CCY2 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value);
                    else
                    {
                        firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.FIRST.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);
                        secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.SECOND.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);

                        if (firstRate != null && secondRate != null)
                        {
                            if (Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE))
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE);
                            else
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE);
                        }
                        else
                        {
                            string mess = string.Empty;
                            mess += firstRate == null ? opicdeal.CCY1 : string.Empty;
                            mess += secondRate == null ? (mess != string.Empty ? " and " + opicdeal.CCY2 : opicdeal.CCY2) : string.Empty;
                            throw new UIPException(new Exception(), "Error : There is no " + mess + " spot rate on " + newDeal.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL));
                        }
                    }

                    newDeal.SPOT_DATE = opicdeal.SPOT_DATE;

                    newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                    newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);

                    break;

                case ProductCode.FXSWAP:
                    newDeal.INSTRUMENT_ID = _instrumentBusiness.GetFXInstrumentByCCY(sessioninfo, ProductCode.FXSWAP, opicdeal.CCY1, opicdeal.CCY2).ID;
                    newDeal.FLAG_NEARFAR = opicdeal.FLAG_NEARFAR;
                    newDeal.START_DATE = dmkDeal != null ? dmkDeal.START_DATE : opicdeal.START_DATE;

                    if (!String.IsNullOrEmpty(opicdeal.CCY1))
                        newDeal.FIRST.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY1).ID;
                    newDeal.FIRST.FLAG_PAYREC = opicdeal.PAY_REC1;
                    newDeal.FIRST.NOTIONAL = opicdeal.NOTIONAL1;
                    newDeal.FIRST.RATE = opicdeal.RATE1;
                    newDeal.FIRST.SWAP_POINT = opicdeal.SWAP_POINT1;

                    if (!String.IsNullOrEmpty(opicdeal.CCY2))
                        newDeal.SECOND.CCY_ID = _lookupvaluesRepository.CurrencyRepository.GetByLabel(opicdeal.CCY2).ID;
                    newDeal.SECOND.FLAG_PAYREC = opicdeal.PAY_REC2;
                    newDeal.SECOND.NOTIONAL = opicdeal.NOTIONAL2;
                    newDeal.SECOND.SWAP_POINT = opicdeal.SWAP_POINT2;

                    //THB Notional
                    if (opicdeal.CCY1 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value);
                    else if (opicdeal.CCY2 == "THB")
                        newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value);
                    else
                    {
                        firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.FIRST.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);
                        secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == newDeal.SECOND.CCY_ID && p.PROC_DATE == newDeal.TRADE_DATE);

                        if (firstRate != null && secondRate != null)
                        {
                            if (Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE))
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.FIRST.NOTIONAL.Value * firstRate.RATE);
                            else
                                newDeal.NOTIONAL_THB = Math.Abs(newDeal.SECOND.NOTIONAL.Value * secondRate.RATE);
                        }
                        else
                        {
                            string mess = string.Empty;
                            mess += firstRate == null ? opicdeal.CCY1 : string.Empty;
                            mess += secondRate == null ? (mess != string.Empty ? " and " + opicdeal.CCY2 : opicdeal.CCY2) : string.Empty;
                            throw new UIPException(new Exception(), "Error : There is no " + mess + " spot rate on " + newDeal.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL));
                        }
                    }

                    newDeal.SPOT_DATE = opicdeal.SPOT_DATE;

                    //Exposure include far leg only -> set near leg to 0
                    if (newDeal.FLAG_NEARFAR == "N")
                    {
                        newDeal.KK_PCCF = 0;
                        newDeal.KK_CONTRIBUTE = 0;
                    }
                    else
                    {
                        newDeal.KK_PCCF = _staticdataBusiness.GetPCCF(sessioninfo, newDeal);
                        newDeal.KK_CONTRIBUTE = Math.Ceiling(newDeal.NOTIONAL_THB.Value * newDeal.KK_PCCF.Value / 100);
                    }

                    break;
                default:
                    throw new UIPException(new Exception(), String.Format("The product is not defined in the OPICS deal no {0}.", opicdeal.EXT_DEAL_NO));
            }
            }

            catch (Exception ex)
            {
                throw new UIPException(new Exception(), ex.Message);
            }
            return newDeal;
        }