示例#1
0
        public static object GetBondsByFilter(SessionInfo sessioninfo, string label, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                //Get data from database
                List<MA_INSTRUMENT> ins = _instrumentBusiness.GetBondsByFilter(sessioninfo, label, jtSorting);

                //Return result to jTable
                return new
                {
                    Result = "OK",
                    Records = jtPageSize > 0 ? ins.Skip(jtStartIndex).Take(jtPageSize).ToList() : ins,
                    TotalRecordCount = ins.Count
                };
            }
            catch (BusinessWorkflowsException bex)
            {
                return new { Result = "ERROR", Message = bex.Message };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
 public void CreateTest()
 {
     InstrumentBusiness target = new InstrumentBusiness(); // TODO: Initialize to an appropriate value
     SessionInfo sessioninfo = null; // TODO: Initialize to an appropriate value
     MA_INSTRUMENT instrument = null; // TODO: Initialize to an appropriate value
     MA_INSTRUMENT expected = null; // TODO: Initialize to an appropriate value
     MA_INSTRUMENT actual;
     actual = target.Create(sessioninfo, instrument);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void GetByFilterTest()
 {
     InstrumentBusiness target = new InstrumentBusiness(); // TODO: Initialize to an appropriate value
     SessionInfo sessioninfo = null; // TODO: Initialize to an appropriate value
     string label = string.Empty; // TODO: Initialize to an appropriate value
     int startIndex = 0; // TODO: Initialize to an appropriate value
     int count = 0; // TODO: Initialize to an appropriate value
     string sorting = string.Empty; // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> expected = null; // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> actual;
     actual = target.GetByFilter(sessioninfo, label, startIndex, count, sorting);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#4
0
        public static object Create(SessionInfo sessioninfo, MA_INSTRUMENT record)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                ILookupValuesRepository _lookupvaluesRepository = RepositorySesssion.GetRepository();
                MA_PRODUCT product = _lookupvaluesRepository.ProductRepository.GetByID(record.PRODUCT_ID);

                ProductCode eProduct = (ProductCode)Enum.Parse(typeof(ProductCode), product.LABEL.Replace(" ", string.Empty));

                record.ID = Guid.NewGuid();
                record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE ? false : true;
                record.LABEL = record.LABEL.ToUpper();

                if (eProduct != ProductCode.BOND)
                {
                    record.INS_MKT = null;
                    record.ISSUER = null;
                    record.LOT_SIZE = null;
                    record.COUPON = null;
                    record.MATURITY_DATE = null;
                    record.CAL_METHOD = null;
                    record.FLAG_FIXED = null;
                    record.COUPON_FREQ_TYPE_ID = null;
                }

                record.LOG.INSERTDATE = DateTime.Now;
                record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;
                var addedRecord = _instrumentBusiness.Create(sessioninfo, record, eProduct);
                return new { Result = "OK", Record = addedRecord };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
示例#5
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;
        }
示例#6
0
        public static object GetOptionsByProduct(SessionInfo sessioninfo, ProductCode productcode)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                //Get data from database
                var ins = _instrumentBusiness.GetByProduct(sessioninfo, productcode)
                                .OrderBy(p => p.LABEL)
                                .Select(c => new { DisplayText = c.LABEL, Value = c.ID });

                //Return result to jTable
                return new { Result = "OK", Options = ins };
            }
            catch (BusinessWorkflowsException bex)
            {
                return new { Result = "ERROR", Message = bex.Message };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
        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);
            }
        }
示例#8
0
        public static object GetInstrumentOptions(SessionInfo sessioninfo)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                //Get data from database
                var instruments = _instrumentBusiness.GetInstrumentAll()
                                        .Where(t => t.ISACTIVE == true)
                                        .OrderBy(p => p.LABEL)
                                        .Select(c => new { DisplayText = c.LABEL, Value = c.ID });

                //Return result to jTable
                return new { Result = "OK", Options = instruments };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
示例#9
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);
                }
            }
        }
示例#10
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);
            }
        }
示例#11
0
        /// <summary>
        /// Validation OPICS deal as CPTY, INSTRUMENT
        /// </summary>
        /// <param name="opicdeal"></param>
        /// <returns></returns>
        private static bool ValidateOPICS(DEALModel opicdeal)
        {
            bool found = true;
            InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            MA_INSTRUMENT ins = null;

            LoggingHelper.Debug("Validate OPICS data");

            MA_COUTERPARTY counterparty = _counterpartyBusiness.GetByUsercode(Convert.ToInt32(opicdeal.CPTY));

            if (counterparty == null) //counterparty must be check whether it exist in  DMK
                throw new UIPException(new Exception(), String.Format("Counterparty {0} is not defined in Dealmaker.", opicdeal.SNAME.Trim()));

            ProductCode eProductCode = (ProductCode)Enum.Parse(typeof(ProductCode), opicdeal.PRODUCT.Replace(" ", string.Empty));

            if (eProductCode == ProductCode.BOND || eProductCode == ProductCode.REPO)
            {
                ins = _instrumentBusiness.GetByLabel(null, opicdeal.INSTRUMENT);

                if (ins == null)
                {
                    found = false;
                    throw new UIPException(new Exception(), String.Format("Instrument {0} is not defined in Dealmaker.", opicdeal.INSTRUMENT));
                }
            }
            else if (eProductCode == ProductCode.FXSPOT || eProductCode == ProductCode.FXFORWARD || eProductCode == ProductCode.FXSWAP)
            {
                ins = _instrumentBusiness.GetFXInstrumentByCCY(null, eProductCode, opicdeal.CCY1, opicdeal.CCY2);

                if (ins == null)
                {
                    found = false;
                    throw new UIPException(new Exception(), String.Format("Currency pair {0} is not defined in Dealmaker.", opicdeal.CCY1 + "/" + opicdeal.CCY2));
                }
            }

            return found;
        }
示例#12
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;
        }
示例#13
0
        /// <summary>
        /// Build Transation for Matching Deal between DMK Deal No. and OPICS Deal No.
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="opicdeals"></param>
        /// <param name="deal"></param>
        /// <param name="UpdateDeals"></param>
        private static void BuildTransation(SessionInfo sessioninfo, List<DEALModel> opicdeals, 
            DA_TRN deal, ref List<DA_TRN> UpdateDeals)
        {
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();

            DA_TRN newDeal = null;
            LoggingHelper.Debug("BuildTransation OPICS data and DMK deal");

            if (opicdeals != null)
            {
                bool flag = true;
                foreach (DEALModel opicdeal in opicdeals)
                {
                    flag = ValidateOPICS(opicdeal);
                    if( !flag ) break;
                }
                if (flag)
                {
                    //Begin transaction - Update DMK Deal No
                    deal.EXT_DEAL_NO = opicdeals[0].EXT_DEAL_NO;
                    deal.EXT_PORTFOLIO = opicdeals[0].EXT_PORTFOLIO;
                    deal.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.MATCHED.ToString()).ID;
                    deal.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                    deal.LOG.MODIFYDATE = DateTime.Now;
                    deal.INSERT_BY_EXT = opicdeals[0].INSERT_BY_EXT;

                    ProductCode eProduct = (ProductCode)Enum.Parse(typeof(ProductCode), opicdeals[0].PRODUCT.Replace(" ", string.Empty));

                    //Update dealmaker data
                    DealTrans.Add(new DealTranModel() { UpdateStates = UpdateStates.Editing, Transaction = deal, ProductTransaction = eProduct });

                    //Create DMK Deal from OPICS Deal
                    foreach (DEALModel opicdeal in opicdeals)
                    {
                        newDeal = GenerateTrnObject(sessioninfo, opicdeal, deal, sessioninfo.Process.NextDate);

                        //Import Opics transaction
                        DealTrans.Add(new DealTranModel() { UpdateStates = UpdateStates.Adding, Transaction = newDeal, ProductTransaction = eProduct });
                    }
                    //Update transaction
                    _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);
                }
            }
        }
示例#14
0
 public static MA_INSTRUMENT GetByID(SessionInfo sessioninfo, Guid id )
 {
     InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
         var ins = _instrumentBusiness.GetByID(sessioninfo, id);
         return ins;
 }
 public void InstrumentBusinessConstructorTest()
 {
     InstrumentBusiness target = new InstrumentBusiness();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
 public void GetInstrumentAllTest()
 {
     InstrumentBusiness target = new InstrumentBusiness(); // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> expected = null; // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> actual;
     actual = target.GetInstrumentAll();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void GetByProductTest1()
 {
     InstrumentBusiness target = new InstrumentBusiness(); // TODO: Initialize to an appropriate value
     SessionInfo sessioninfo = null; // TODO: Initialize to an appropriate value
     Guid productID = new Guid(); // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> expected = null; // TODO: Initialize to an appropriate value
     List<MA_INSTRUMENT> actual;
     actual = target.GetByProduct(sessioninfo, productID);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void GetByLabelTest()
 {
     InstrumentBusiness target = new InstrumentBusiness(); // TODO: Initialize to an appropriate value
     SessionInfo sessioninfo = null; // TODO: Initialize to an appropriate value
     string strLabel = string.Empty; // TODO: Initialize to an appropriate value
     MA_INSTRUMENT expected = null; // TODO: Initialize to an appropriate value
     MA_INSTRUMENT actual;
     actual = target.GetByLabel(sessioninfo, strLabel);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#19
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;
        }
示例#20
0
        public static object GetInstrumentByName(SessionInfo sessioninfo, ProductCode productcode,string name)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                //Get data from database
                var ins = _instrumentBusiness.GetByProduct(sessioninfo, productcode).Where(c => c.ISACTIVE == true && c.LABEL.StartsWith(name)).OrderBy(c => c.LABEL);

                //Return result to jTable
                return new { Result = "OK", Records = ins };
            }
            catch (BusinessWorkflowsException bex)
            {
                return new { Result = "ERROR", Message = bex.Message };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
示例#21
0
        /// <summary>
        /// Import Passed for OPICS Deal to DA_TRN table
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="opicdeal"></param>
        private static void ImportPassedOPICSDeal(SessionInfo sessioninfo, DEALModel opicdeal, DateTime processdate, ref List<DealTranModel> DealTrans)
        {
            StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();

            DA_TRN pastimported = _dealBusiness.GetPastImportedDealsByExtNo(opicdeal.EXT_DEAL_NO);

            DA_TRN newDeal = GenerateTrnObject(sessioninfo, opicdeal, pastimported, processdate);

            DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), opicdeal.PRODUCT.Replace(" ", string.Empty)), Transaction = newDeal, UpdateStates = UpdateStates.Adding });
        }