Ejemplo n.º 1
0
        public MA_INSTRUMENT GetByLabel(SessionInfo sessioninfo, string strLabel)
        {
            try
            {
                MA_INSTRUMENT instrument = null;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    instrument = unitOfWork.MA_INSTRUMENTRepository.GetByLabel(strLabel);
                }

                //if (instruments.Count == 1)
                //{
                //    return instruments[0];
                //}
                //else
                //{
                //    throw this.CreateException(new Exception() , "Found multiple instruments with label " + strLabel);
                //}
                return(instrument);
            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
 public static object GetEditByID(Guid id)
 {
     try
     {
         DA_TRN        trn   = DealUIP.GetByID(id);
         MA_INSTRUMENT ins   = InstrumentUIP.GetByID(SessionInfo, trn.MA_INSRUMENT.ID);
         var           query = new
         {
             ID           = trn.ID,
             TradeDate    = trn.TRADE_DATE.HasValue ? trn.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
             SpotDate     = trn.SPOT_DATE.HasValue ? trn.SPOT_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
             MaturityDate = trn.MATURITY_DATE.HasValue ? trn.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
             Counterparty = trn.CTPY_ID.ToString(),
             Portfolio    = trn.PORTFOLIO_ID.ToString(),
             Instrument   = trn.INSTRUMENT_ID.ToString(),
             BuySell      = trn.FLAG_BUYSELL,
             CCY1         = trn.FIRST.CCY_ID.ToString(),
             SpotRate     = trn.FIRST.RATE - (trn.FIRST.SWAP_POINT.HasValue ?  trn.FIRST.SWAP_POINT : 0),
             SwapPoint    = trn.FIRST.SWAP_POINT,
             Remark       = trn.REMARK,
             flag_settle  = trn.FLAG_SETTLE,
             Notional1    = Math.Abs(trn.FIRST.NOTIONAL.Value),
             Notional2    = Math.Abs(trn.SECOND.NOTIONAL.Value)
         };
         return(new { Result = "OK", record = query, CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } });
     }
     catch (Exception ex)
     {
         return(new { Result = "ERROR", Message = ex.Message });
     }
 }
Ejemplo n.º 3
0
        public static object Create(MA_INSTRUMENT record)
        {
            ILookupValuesRepository _lookupvaluesRepository = RepositorySesssion.GetRepository();

            record.PRODUCT_ID = _lookupvaluesRepository.ProductRepository.GetByLabel(ProductCode.BOND.ToString()).ID;

            return(InstrumentUIP.Create(SessionInfo, record));
        }
Ejemplo n.º 4
0
 public static object GetInstrument(Guid id)
 {
     try
     { MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, id);
       return(new { Result = "OK", Message = "", CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } }); }
     catch (Exception ex)
     {
         return(new { Result = "ERROR", Message = ex.Message });
     }
 }
Ejemplo n.º 5
0
        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.");
        }
Ejemplo n.º 6
0
 public static object GetCCYByInstrumentID(Guid id)
 {
     try
     {
         MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, id);
         return(new { Result = "OK", record = new { id = ins.MA_CURRENCY.ID.ToString(), label = ins.MA_CURRENCY.LABEL } });
     }
     catch (Exception ex)
     {
         return(new { Result = "ERROR", Message = ex.Message });
     }
 }
Ejemplo n.º 7
0
        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.");
        }
Ejemplo n.º 8
0
 public static object GetLotSizeByInstrumentID(string ID)
 {
     try
     {
         MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, new Guid(ID));
         if (!ins.LOT_SIZE.HasValue)
         {
             return new { Result = "ERROR", Message = "Instrument's lot size is empty." }
         }
         ;
         return(new { Result = "OK", lotsize = ins.LOT_SIZE });
     }
     catch (Exception ex)
     {
         return(new { Result = "ERROR", Message = ex.Message });
     }
 }
Ejemplo n.º 9
0
 public MA_INSTRUMENT GetFXInstrumentByCCY(SessionInfo sessioninfo, ProductCode eProductCode, string strCCY1, string strCCY2)
 {
     try
     {
         MA_INSTRUMENT instrument = null;
         using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
         {
             instrument = unitOfWork.MA_INSTRUMENTRepository
                          .GetAllByProductCode(eProductCode.ToString())
                          .FirstOrDefault(p => p.LABEL.Equals(strCCY1 + "/" + strCCY2) || p.LABEL.Equals(strCCY2 + "/" + strCCY1));
         }
         return(instrument);
     }
     catch (DataServicesException ex)
     {
         throw this.CreateException(ex, null);
     }
 }
Ejemplo n.º 10
0
        public MA_INSTRUMENT Create(SessionInfo sessioninfo, MA_INSTRUMENT instrument, ProductCode product)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_INSTRUMENTRepository.GetAllByProductCode(product.ToString()).FirstOrDefault(p => p.LABEL == instrument.LABEL);
                if (checkDuplicate != null)
                {
                    throw this.CreateException(new Exception(), "Label is duplicated");
                }
                if (product == ProductCode.BOND)
                {
                    LogBusiness logBusiness = new LogBusiness();
                    unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, instrument.ID, LogEvent.INSTRUMENT_AUDIT.ToString(), LookupFactorTables.MA_INSTRUMENT, "BOND", new { }));
                }
                unitOfWork.MA_INSTRUMENTRepository.Add(instrument);
                unitOfWork.Commit();
            }

            return(instrument);
        }
Ejemplo n.º 11
0
        public static object GetEditByID(Guid id)
        {
            try
            {
                DA_TRN lastTrn1 = DealUIP.GetByID(id);
                DA_TRN lastTrn2 = DealUIP.GetFXSwapPair(SessionInfo, lastTrn1.INT_DEAL_NO, lastTrn1.VERSION, lastTrn1.ID);

                MA_INSTRUMENT ins     = InstrumentUIP.GetByID(SessionInfo, lastTrn1.MA_INSRUMENT.ID);
                var           NearLeg = lastTrn1.FLAG_NEARFAR == "N" ? lastTrn1 : lastTrn2;
                var           FarLeg  = lastTrn2.FLAG_NEARFAR == "F" ? lastTrn2 : lastTrn1;
                var           query   = new
                {
                    TradeDate    = lastTrn1.TRADE_DATE.HasValue ? lastTrn1.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
                    Counterparty = lastTrn1.CTPY_ID.ToString(),
                    Portfolio    = lastTrn1.PORTFOLIO_ID.ToString(),
                    Instrument   = lastTrn1.INSTRUMENT_ID.ToString(),
                    ContractCcy  = lastTrn1.FIRST.CCY_ID.ToString(),
                    SpotDate     = lastTrn1.SPOT_DATE.HasValue ? lastTrn1.SPOT_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
                    SpotRate     = lastTrn1.FIRST.RATE.Value - lastTrn1.FIRST.SWAP_POINT.Value,
                    BSN          = NearLeg.FLAG_BUYSELL,
                    BSF          = FarLeg.FLAG_BUYSELL,
                    SetDateN     = NearLeg.MATURITY_DATE.HasValue ? NearLeg.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
                    SetDateF     = FarLeg.MATURITY_DATE.HasValue ? FarLeg.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty,
                    SwapPoitN    = NearLeg.FIRST.SWAP_POINT,
                    SwapPoitF    = FarLeg.FIRST.SWAP_POINT,
                    ContAmtN     = Math.Abs(NearLeg.FIRST.NOTIONAL.Value),
                    CountAmtN    = Math.Abs(NearLeg.SECOND.NOTIONAL.Value),
                    ContAmtF     = Math.Abs(FarLeg.FIRST.NOTIONAL.Value),
                    CountAmtF    = Math.Abs(FarLeg.SECOND.NOTIONAL.Value),
                    flag_settle  = lastTrn1.FLAG_SETTLE,
                };
                return(new { Result = "OK", record = query, productid2 = lastTrn2.ID.ToString(), CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 12
0
        //public static object CreateBondInstruments(SessionInfo sessioninfo, MA_INSTRUMENT record)
        //{
        //    try
        //    {
        //        InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
        //        ILookupValuesRepository _lookupvaluesRepository = RepositorySesssion.GetRepository();

        //        record.ID = Guid.NewGuid();
        //        record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE ? false : true;
        //        record.PRODUCT_ID = _lookupvaluesRepository.ProductRepository.GetByLabel(ProductCode.BOND.ToString()).ID;
        //        record.LOG.INSERTDATE = DateTime.Now;
        //        record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;

        //        var addedRecord = _instrumentBusiness.Create(sessioninfo, record);
        //        return new { Result = "OK", Record = addedRecord };
        //    }
        //    catch (Exception ex)
        //    {
        //        return new { Result = "ERROR", Message = ex.Message };
        //    }
        //}

        public static object Update(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.LABEL      = record.LABEL.ToUpper();
                record.ISACTIVE   = record.ISACTIVE == null || !record.ISACTIVE ? false : true;
                record.FLAG_FIXED = record.FLAG_FIXED == null || !record.FLAG_FIXED.Value ? false : true;

                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.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                record.LOG.MODIFYDATE     = DateTime.Now;
                var addedRecord = _instrumentBusiness.Update(sessioninfo, record, eProduct);
                return(new { Result = "OK" });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 13
0
        public MA_PCCF ValidatePCCFConfig(SessionInfo sessioninfo, DA_TRN record)
        {
            MA_PCCF val = null;
            bool    blnResult;

            //enter conditions
            LoggingHelper.Debug("Begin validate PCCF from config");
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var props   = record.GetType().GetProperties();
                var configs = unitOfWork.MA_PCCF_CONFIGRepository.GetAll()
                              .Where(p => p.PRODUCT_ID.Equals(record.PRODUCT_ID))
                              .OrderBy(p => p.PRIORITY);

                //bool isBond = string.Compare(unitOfWork.MA_PRODUCTRepository.GetById(record.PRODUCT_ID.Value).LABEL, ProductCode.BOND.ToString(), true) == 0;

                if (configs != null)
                {
                    List <bool> ismatchs = new List <bool>();
                    object      obj;
                    foreach (MA_PCCF_CONFIG p in configs.ToList())
                    {
                        ismatchs.Clear();
                        blnResult = false;

                        //List<MA_CONFIG_ATTRIBUTE> atts = unitOfWork.MA_CONFIG_ATTRIBUTERepository.All().Where(t => t.PCCF_CONFIG_ID == p.ID && t.ISACTIVE == true).ToList() ;

                        foreach (MA_CONFIG_ATTRIBUTE ca in p.MA_CONFIG_ATTRIBUTE.Where(t => t.ISACTIVE == true).ToList())
                        {
                            //Fix for Tables
                            switch (ca.TABLE)
                            {
                            case "DA_TRN":
                                var sel = props.FirstOrDefault(t => t.Name.Equals(ca.ATTRIBUTE));
                                if (sel != null)
                                {
                                    if (sel.GetValue(record, null).GetType() == typeof(Guid))
                                    {
                                        switch (ca.ATTRIBUTE)
                                        {
                                        //Fix for fields
                                        case "INSTRUMENT_ID":
                                            obj = new MA_INSTRUMENT();
                                            obj = unitOfWork.MA_INSTRUMENTRepository.GetByIDWithOutInclude(new Guid(sel.GetValue(record, null).ToString()));

                                            blnResult = ((MA_INSTRUMENT)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);
                                            //ismatchs.Add(blnResult);

                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    else if (sel.GetValue(record, null).GetType() == typeof(Boolean))
                                    {
                                        blnResult = sel.GetValue(record, null).Equals(ca.VALUE == "0" ? false : true);    // ismatchs.Add(fsel.GetValue(record.FIRST, null).Equals(ca.VALUE=="0" ? false : true));
                                    }
                                    else
                                    {
                                        blnResult = sel.GetValue(record, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);
                                        //ismatchs.Add(blnResult);
                                    }
                                }
                                break;

                            case "BOND_MARKET":
                                MA_INSTRUMENT insMkt = unitOfWork.MA_INSTRUMENTRepository.GetByIDWithInsMarket(record.INSTRUMENT_ID.Value);

                                if (insMkt.MA_BOND_MARKET != null)
                                {
                                    blnResult = insMkt.MA_BOND_MARKET.LABEL.Equals(ca.VALUE);
                                    //ismatchs.Add(blnResult);
                                }
                                //else
                                //ismatchs.Add(false);

                                break;

                            case "FIRST":
                                var fsel = record.FIRST.GetType().GetProperties().FirstOrDefault(f => f.Name.Equals(ca.ATTRIBUTE));
                                if (fsel != null)
                                {
                                    if (fsel.GetValue(record.FIRST, null) != null)
                                    {
                                        if (fsel.GetValue(record.FIRST, null).GetType() == typeof(Guid))
                                        {
                                            switch (ca.ATTRIBUTE)
                                            {
                                            //Fix for fields
                                            case "CCY_ID":
                                                obj = new MA_CURRENCY();
                                                obj = unitOfWork.MA_CURRENCYRepository.GetByID(new Guid(fsel.GetValue(record.FIRST, null).ToString()));

                                                blnResult = ((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);
                                                //ismatchs.Add();

                                                break;

                                            default:
                                                break;
                                            }
                                        }
                                        else if (fsel.GetValue(record.FIRST, null).GetType() == typeof(Boolean))
                                        {
                                            blnResult = fsel.GetValue(record.FIRST, null).Equals(ca.VALUE == "0" ? false : true);    // ismatchs.Add(fsel.GetValue(record.FIRST, null).Equals(ca.VALUE=="0" ? false : true));
                                        }
                                        else
                                        {
                                            blnResult = fsel.GetValue(record.FIRST, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);     //ismatchs.Add(fsel.GetValue(record.FIRST, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase));
                                        }
                                    }
                                    //else ismatchs.Add(false);
                                }
                                break;

                            case "SECOND":
                                //var secprop = props.FirstOrDefault(f => f.Name.Equals("SECOND"));
                                var ssel = record.SECOND.GetType().GetProperties().FirstOrDefault(f => f.Name.Equals(ca.ATTRIBUTE));
                                if (ssel != null)
                                {
                                    if (ssel.GetValue(record.SECOND, null) != null)
                                    {
                                        if (ssel.GetValue(record.SECOND, null).GetType() == typeof(Guid))
                                        {
                                            switch (ca.ATTRIBUTE)
                                            {
                                            //Fix for fields
                                            case "CCY_ID":
                                                obj = new MA_CURRENCY();
                                                obj = unitOfWork.MA_CURRENCYRepository.GetByID(new Guid(ssel.GetValue(record.SECOND, null).ToString()));

                                                blnResult = ((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);
                                                //ismatchs.Add(((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase));

                                                break;

                                            default:
                                                break;
                                            }
                                        }
                                        else if (ssel.GetValue(record.SECOND, null).GetType() == typeof(Boolean))
                                        {
                                            blnResult = ssel.GetValue(record.SECOND, null).Equals(ca.VALUE == "0" ? false : true);    // ismatchs.Add(ssel.GetValue(record.SECOND, null).Equals(ca.VALUE == "0" ? false : true));
                                        }
                                        else
                                        {
                                            blnResult = ssel.GetValue(record.SECOND, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase);    // ismatchs.Add(ssel.GetValue(record.SECOND, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase));
                                        }
                                    }
                                    //else ismatchs.Add(false);
                                }
                                break;

                            case "COUNTERPARTY":
                                MA_COUTERPARTY ctpy = unitOfWork.MA_COUTERPARTYRepository.GetAll().FirstOrDefault(z => z.ID == record.CTPY_ID);

                                switch (ca.ATTRIBUTE)
                                {
                                case "SNAME":
                                    blnResult = ctpy.SNAME.ToUpper() == ca.VALUE.ToUpper();

                                    break;

                                case "CSA_TYPE":

                                    MA_CSA_AGREEMENT csa = unitOfWork.MA_CSA_AGREEMENTRepository.GetAll().FirstOrDefault(y => y.ID == record.CTPY_ID);

                                    if (csa != null &&
                                        csa.MA_CSA_TYPE.LABEL.ToUpper() == ca.VALUE.ToUpper() &&
                                        csa.MA_CSA_PRODUCT.FirstOrDefault(y => y.PRODUCT_ID == record.PRODUCT_ID) != null)
                                    {
                                        blnResult = true;
                                    }
                                    //else if (csa == null && ca.VALUE == "")
                                    //    blnResult = true;
                                    else
                                    {
                                        blnResult = false;
                                    }

                                    break;

                                default:
                                    break;
                                }

                                break;
                            }

                            ismatchs.Add(blnResult);

                            //Check result -> if false then go to next config
                            if (!blnResult)
                            {
                                break;
                            }
                        }

                        if (ismatchs.Where(m => m.Equals(false)).Count() == 0)
                        {
                            val = unitOfWork.MA_PCCFRepository.GetByID(p.PCCF_ID);
                            LoggingHelper.Debug("PCCF: " + val.LABEL);
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    val = null;
                }
            }
            LoggingHelper.Debug("End validate PCCF from config");
            return(val);
        }
Ejemplo n.º 14
0
        public static object CallTBMA(string instrumentid, string setdate, double yield, double cprice, string ytype, bool y2p)
        {
            try
            {
                MA_TBMA_CONFIG config = LookupUIP.GetTBMAConfig(SessionInfo);

                string username, userpassword, token, Key, ErrorMessage;
                username     = config.TBMA_CAL_USERNAME;
                userpassword = config.TBMA_CAL_PASSWORD;
                MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, new Guid(instrumentid));
                if (ins == null)
                {
                    throw new Exception("Instrument is not found");
                }

                LoggingHelper.Info("TBMA Calculation Service has been called by " + SessionInfo.UserLogon);

                //Step 1 Create new instant object
                ThaiBMACalc.ThaiBMA_Claculation_Service calc = new ThaiBMACalc.ThaiBMA_Claculation_Service(); //Service Object
                ThaiBMACalc.BondFactor   BF     = new ThaiBMACalc.BondFactor();                               //input object
                ThaiBMACalc.AuthenHeader header = new ThaiBMACalc.AuthenHeader();                             //authen object
                //Step 2 Get token
                Authen.ThaiBMA_Calculation_Auth authen = new Authen.ThaiBMA_Calculation_Auth();
                token = authen.GetToken(username);

                //Step 3 Get Key for access
                Key             = GetKey.getKeyLogin(token, username, userpassword);
                header.key      = Key;
                header.username = username;

                //Step 4 Set auhen value
                calc.AuthenHeaderValue = header;

                //Step 5 Set input value to object
                BF.Symbol           = ins.LABEL;
                BF.SettlementDate   = DateTime.ParseExact(setdate, "dd/MM/yyyy", null);
                BF.TradeDateAndTime = System.DateTime.Now;
                BF.Yield            = yield;
                BF.Percent_Price    = cprice;
                BF.isYield2Price    = y2p;
                BF.isCallPutOption  = false;
                BF.Unit             = 1;
                BF.PriceType        = ThaiBMACalc.PriceType.Clean;

                if (ins.LABEL.StartsWith("ILB"))
                {
                    BF.isILB = true;
                }

                if (ytype == "DM")
                {
                    BF.YieldType = ThaiBMACalc.YieldType.DM;
                }
                else
                {
                    BF.YieldType = ThaiBMACalc.YieldType.YTM;
                }

                //Step 6 Call calc method
                ThaiBMACalc.CalculationOutput result  = calc.BondCalculation(BF);
                ThaiBMACalc.ServiceError      sresult = (ThaiBMACalc.ServiceError)result.ServiceResult;

                //Error while calling service
                if (sresult != null && !sresult.Result)
                {
                    ErrorMessage = sresult.ErrorMessage;
                    string ErrorNo = sresult.ErrorNo;
                    bool   rtn     = sresult.Result;
                    string attime  = sresult.TimeStamp.ToString();
                    LoggingHelper.Error("ThaiBMA service is fail. " + ErrorMessage);
                    return(new { Result = "ERROR", Message = "ThaiBMA service is fail. " + ErrorMessage });
                }

                if ((result.CalcError == null) && (result.CalcResult != null))
                {
                    ThaiBMACalc.CalcResult myResult = (ThaiBMACalc.CalcResult)result.CalcResult;

                    //Calculation Result
                    double RGrossPrice = 0;
                    double RCleanPrice = 0;
                    double RYield      = 0;

                    if (myResult.Symbol.StartsWith("ILB"))
                    {
                        RCleanPrice = (double)myResult.Percent_Unadjusted_CleanPrice;
                        RYield      = (double)myResult.Percent_RealYield;
                        RGrossPrice = (double)myResult.Percent_Unadjusted_GrossPrice;
                    }
                    else
                    {
                        RYield      = ytype == "DM" ? (double)myResult.Percent_DM : (double)myResult.Percent_Yield;
                        RCleanPrice = (double)myResult.Percent_CleanPrice;
                        RGrossPrice = (double)myResult.Percent_GrossPrice;
                    }
                    return(new { Result = "OK", gprice = RGrossPrice, cprice = RCleanPrice, yield = RYield });
                    //.... and more
                }
                else
                {
                    Type error = result.CalcError.GetType();
                    IList <PropertyInfo> props = new List <PropertyInfo>(error.GetProperties());

                    string errmsg = string.Join(",", props.Where(p => p.GetValue(result.CalcError, null).ToString() != "").Select(p => p.GetValue(result.CalcError, null)).ToList());

                    LoggingHelper.Error("ThaiBMA Caculation is fail. " + errmsg);
                    return(new { Result = "ERROR", Message = "ThaiBMA Caculation is fail. " + errmsg });
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.Error("ThaiBMA service is fail. " + ex.Message);
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 15
0
 public static object Update(MA_INSTRUMENT record)
 {
     return(InstrumentUIP.Update(SessionInfo, record));
 }
Ejemplo n.º 16
0
        public MA_INSTRUMENT Update(SessionInfo sessioninfo, MA_INSTRUMENT instrument, ProductCode product)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_INSTRUMENTRepository.GetAllByProductCode(product.ToString()).FirstOrDefault(p => p.LABEL == instrument.LABEL && p.ID != instrument.ID);
                if (checkDuplicate != null)
                {
                    throw this.CreateException(new Exception(), "Label is duplicated");
                }
                var foundData = unitOfWork.MA_INSTRUMENTRepository.GetAll().FirstOrDefault(p => p.ID == instrument.ID);
                if (foundData == null)
                {
                    throw this.CreateException(new Exception(), "Data not found!");
                }
                else
                {
                    if (product == ProductCode.BOND)
                    {
                        LogBusiness logBusiness = new LogBusiness();
                        var         oldRecord   = new
                        {
                            ISACTIVE         = foundData.ISACTIVE,
                            CAL_METHOD       = foundData.CAL_METHOD,
                            COUPON           = foundData.COUPON,
                            COUPON_FREQ_TYPE = foundData.MA_FREQ_TYPE != null ?foundData.MA_PRODUCT.LABEL:string.Empty,
                            FLAG_FIXED       = foundData.FLAG_FIXED,
                            INS_MKT          = foundData.INS_MKT,
                            ISSUER           = foundData.ISSUER,
                            LABEL            = foundData.LABEL,
                            LOT_SIZE         = foundData.LOT_SIZE,
                            MATURITY_DATE    = foundData.MATURITY_DATE,
                            PRODUCT          = foundData.MA_PRODUCT != null ? foundData.MA_PRODUCT.LABEL:string.Empty,
                            CURRENCY         = foundData.MA_CURRENCY != null ? foundData.MA_CURRENCY.LABEL:string.Empty
                        };
                        var newRecord = new
                        {
                            ISACTIVE         = instrument.ISACTIVE,
                            CAL_METHOD       = instrument.CAL_METHOD,
                            COUPON           = instrument.COUPON,
                            COUPON_FREQ_TYPE = unitOfWork.MA_FREQ_TYPERepository.All().FirstOrDefault(f => f.ID == instrument.COUPON_FREQ_TYPE_ID).LABEL,
                            FLAG_FIXED       = instrument.FLAG_FIXED,
                            INS_MKT          = instrument.INS_MKT,
                            ISSUER           = instrument.ISSUER,
                            LABEL            = instrument.LABEL,
                            LOT_SIZE         = instrument.LOT_SIZE,
                            MATURITY_DATE    = instrument.MATURITY_DATE,
                            PRODUCT          = unitOfWork.MA_PRODUCTRepository.All().FirstOrDefault(p => p.ID == instrument.PRODUCT_ID).LABEL,
                            CURRENCY         = unitOfWork.MA_CURRENCYRepository.All().FirstOrDefault(c => c.ID == instrument.CURRENCY_ID1).LABEL,
                        };
                        var log = logBusiness.UpdateLogging(sessioninfo, foundData.ID, LogEvent.INSTRUMENT_AUDIT.ToString(), LookupFactorTables.MA_INSTRUMENT, oldRecord, newRecord);
                        if (log != null)
                        {
                            unitOfWork.DA_LOGGINGRepository.Add(log);
                        }
                    }
                    foundData.ID                  = instrument.ID;
                    foundData.ISACTIVE            = instrument.ISACTIVE;
                    foundData.LOG.MODIFYBYUSERID  = sessioninfo.CurrentUserId;
                    foundData.LOG.MODIFYDATE      = DateTime.Now;
                    foundData.CAL_METHOD          = instrument.CAL_METHOD;
                    foundData.COUPON              = instrument.COUPON;
                    foundData.COUPON_FREQ_TYPE_ID = instrument.COUPON_FREQ_TYPE_ID;
                    foundData.FLAG_FIXED          = instrument.FLAG_FIXED;
                    foundData.INS_MKT             = instrument.INS_MKT;
                    foundData.ISSUER              = instrument.ISSUER;
                    foundData.LABEL               = instrument.LABEL;
                    foundData.LOT_SIZE            = instrument.LOT_SIZE;
                    foundData.MATURITY_DATE       = instrument.MATURITY_DATE;
                    foundData.PRODUCT_ID          = instrument.PRODUCT_ID;
                    foundData.CURRENCY_ID1        = instrument.CURRENCY_ID1;
                    foundData.CURRENCY_ID2        = instrument.CURRENCY_ID2;
                    unitOfWork.Commit();
                }
            }

            return(instrument);
        }
Ejemplo n.º 17
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);
            }
        }