public DA_TRN GenerateFXSpotTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strSpotDate, string strCtpy, string strPortfolio , string strCurrencyPair, string strBS, string strContractCcy, string strCounterCcy , string strSpotRate, string strContractAmt, string strCounterAmt, string strRemark, bool settleFlag, string strProductId) { LookupBusiness _lookupBusiness = new LookupBusiness(); DA_TRN trn = new DA_TRN(); DA_TRN lastrn = null; Guid guTemp; if (Guid.TryParse(strProductId, out guTemp)) { lastrn = new DA_TRN(); lastrn = GetByID(guTemp); } trn.ID = Guid.NewGuid(); trn.ENGINE_DATE = sessionInfo.Process.CurrentDate; trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null); trn.START_DATE = trn.TRADE_DATE; trn.MATURITY_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null); trn.CTPY_ID = Guid.Parse(strCtpy); trn.PORTFOLIO_ID = Guid.Parse(strPortfolio); trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair); trn.FIRST.CCY_ID = Guid.Parse(strContractCcy); trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy); trn.FIRST.RATE = Convert.ToDecimal(strSpotRate); trn.FLAG_BUYSELL = strBS; trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmt) : -Convert.ToDecimal(strContractAmt); trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmt) : Convert.ToDecimal(strCounterAmt); trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO; trn.SOURCE = SourceType.INT.ToString(); trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1; trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID; trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P"; trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R"; trn.LOG.INSERTDATE = DateTime.Now; trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId; trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID; trn.FLAG_SETTLE = !settleFlag; trn.REMARK = strRemark; var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable(); var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB"); var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB"); var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable(); if (n1 != null) trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value); else if (n2 != null) trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value); else { var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (firstRate != null && secondRate != null) { if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE)) trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE); else trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE); } else { var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness(); //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn); //trn.KK_CONTRIBUTE = trn.NOTIONAL_THB.Value * trn.KK_PCCF / 100; DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW(); flow1.ID = Guid.NewGuid(); flow1.DA_TRN_ID = trn.ID; flow1.FLAG_FIRST = true; flow1.RATE = trn.FIRST.RATE; flow1.FLOW_DATE = trn.MATURITY_DATE; flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL; if (n1 != null) flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value); else { var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (a != null){ flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE); } else{ var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE; flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID; DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW(); flow2.ID = Guid.NewGuid(); flow2.DA_TRN_ID = trn.ID; flow2.FLAG_FIRST = false; flow2.FLOW_DATE = trn.MATURITY_DATE; flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL; if (n2 != null) flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value); else { var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (a != null) { flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE); } else { var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE; flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID; trn.DA_TRN_FLOW.Add(flow1); trn.DA_TRN_FLOW.Add(flow2); return trn; }
public DA_TRN GenerateFITransactionObject(SessionInfo sessionInfo , string strTradeDate , string strBuySell , string strInstrument , string strCtpy , string strPortfolio , string strSettlementDate , string strYield , string strUnit , string strCleanPrice , string strGrossPrice , string strNotional , string strCCY , string strPceFlag , string strSettleFlag , string strYeildType , string strReportBy , string strPurpose , string strTerm , string strRate , string strTBMARemark , string strRemark , string strProductId) { //Validate business logics here //throw error to UI if fail validation LookupBusiness _lookupBusiness = new LookupBusiness(); DA_TRN trn = new DA_TRN(); DA_TRN lastrn = null; DateTime dteTemp; Decimal decTemp; Guid guTemp; if (Guid.TryParse(strProductId, out guTemp)) { lastrn = new DA_TRN(); lastrn = GetByID(guTemp); } trn.ENGINE_DATE = sessionInfo.Process.CurrentDate; if (strCtpy == "null") throw this.CreateException(new Exception(), "Please input counterparty."); else trn.CTPY_ID = Guid.Parse(strCtpy); if (String.IsNullOrEmpty(strTradeDate)) throw this.CreateException(new Exception(), "Please input trade date."); else if (!DateTime.TryParseExact(strTradeDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp)) throw this.CreateException(new Exception(), "Invalid trade date."); else trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null); if (String.IsNullOrEmpty(strSettlementDate)) throw this.CreateException(new Exception(), "Please input settlement date."); else if (!DateTime.TryParseExact(strSettlementDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp)) throw this.CreateException(new Exception(), "Invalid settlement date."); else { trn.MATURITY_DATE = DateTime.ParseExact(strSettlementDate, "dd/MM/yyyy", null); trn.START_DATE = trn.MATURITY_DATE; } if (strInstrument == "null") throw this.CreateException(new Exception(), "Please input instrument."); else trn.INSTRUMENT_ID = Guid.Parse(strInstrument); if (String.IsNullOrEmpty(strNotional)) throw this.CreateException(new Exception(), "Please input notional amount."); else if (!Decimal.TryParse(strNotional, out decTemp)) throw this.CreateException(new Exception(), "Invalid notional amount."); else if (Convert.ToDecimal(strNotional) <= 0) throw this.CreateException(new Exception(), "Invalid notional amount."); else trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional); if (strPortfolio == "-1") throw this.CreateException(new Exception(), "Please select portfolio."); else trn.PORTFOLIO_ID = Guid.Parse(strPortfolio); if (trn.MATURITY_DATE < trn.TRADE_DATE) { throw this.CreateException(new Exception(), "Settlement date cannot be before trade date."); } if ((strPurpose.Trim() == TBMA_PURPOSE.FIN.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINB.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINP.ToString()) && (strTBMARemark.Trim() == string.Empty || strRate.Trim() == string.Empty || strTerm.Trim() == string.Empty)) { throw this.CreateException(new Exception(), "Please input Term, Rate and Remark."); } if (lastrn != null) { if (strRemark == "") throw this.CreateException(new Exception(), "Please input comment."); else trn.REMARK = strRemark; } trn.ID = Guid.NewGuid(); trn.FLAG_SETTLE = strSettleFlag == "1" ? true : false; trn.FLAG_BUYSELL = strBuySell; trn.FIRST.CCY_ID = Guid.Parse(strCCY); trn.FIRST.RATE = Convert.ToDecimal(strYield); trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID; trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1; trn.SOURCE = SourceType.INT.ToString(); trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID; trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO; var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable(); var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == trn.TRADE_DATE); if (a == null) { var ccys = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccys.LABEL + " spot rate on " + strTradeDate + " trade date."); } trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE); trn.FLAG_PCE = strPceFlag == "1" ? true : false; trn.LOG.INSERTDATE = DateTime.Now; trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId; DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW(); flow1.ID = Guid.NewGuid(); flow1.DA_TRN_ID = trn.ID; flow1.FLAG_FIRST = true; flow1.FLOW_DATE = trn.MATURITY_DATE; flow1.FLOW_AMOUNT = trn.FLAG_BUYSELL == "B" ? -trn.FIRST.NOTIONAL : trn.FIRST.NOTIONAL; flow1.FLOW_AMOUNT_THB = trn.FLAG_BUYSELL == "B" ? -trn.NOTIONAL_THB : trn.NOTIONAL_THB; flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE; flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID; trn.DA_TRN_FLOW.Add(flow1); DA_TMBA_EXTENSION tbma = new DA_TMBA_EXTENSION(); tbma.ID = trn.ID; tbma.PURPOSE = strPurpose; tbma.YIELD_TYPE = strYeildType; tbma.CLEAN_PRICE = Convert.ToDecimal(strCleanPrice); tbma.GROSS_PRICE = Convert.ToDecimal(strGrossPrice); tbma.UNIT = Convert.ToInt32(strUnit); if (strTerm != string.Empty) tbma.TERM = Convert.ToInt32(strTerm); if (strRate != string.Empty) tbma.RATE = Convert.ToDecimal(strRate); if (strTBMARemark != string.Empty) tbma.REMARK = strTBMARemark; tbma.IS_REPORT_CLEAN = strReportBy == "0" ? true : false; if (lastrn != null) { tbma.SEND_DATE = lastrn.DA_TMBA_EXTENSION.SEND_DATE; tbma.SENDER_ID = lastrn.DA_TMBA_EXTENSION.SENDER_ID; } trn.DA_TMBA_EXTENSION = tbma; return trn; }
public DA_TRN GenerateFXSwapTransactionObject2(SessionInfo sessionInfo, string strTradeDate, string strCtpy, string strPortfolio, string strCurrencyPair , string strContractCcy, string strCounterCcy, string strSpotRate , string strBSFar, string strSetDateFar, string strSwapPointFar , string strContractAmtFar, string strCounterAmtFar, string strSpotDate, string strRemark, bool settleFlag, int Version) { LookupBusiness _lookupBusiness = new LookupBusiness(); DA_TRN trn = new DA_TRN(); trn.ID = Guid.NewGuid(); trn.ENGINE_DATE = sessionInfo.Process.CurrentDate; //trn.INT_DEAL_NO = strDealNo; trn.SOURCE = SourceType.INT.ToString(); trn.VERSION = Version; trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString()).ID; trn.CTPY_ID = Guid.Parse(strCtpy); trn.PORTFOLIO_ID = Guid.Parse(strPortfolio); trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair); trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null); trn.SPOT_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null); //If settle after spot date (forward deal) then bucket is count from spot -> settlement date //else (O/N or T/N deal) no need to count bucket so start date will be null if (DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null) > trn.SPOT_DATE) trn.START_DATE = trn.SPOT_DATE; else trn.START_DATE = trn.TRADE_DATE; trn.MATURITY_DATE = DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null); trn.FLAG_BUYSELL = strBSFar; trn.FLAG_NEARFAR = "F"; trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmtFar) : -Convert.ToDecimal(strContractAmtFar); trn.FIRST.CCY_ID = Guid.Parse(strContractCcy); trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P"; trn.FIRST.RATE = Convert.ToDecimal(strSpotRate) + Convert.ToDecimal(strSwapPointFar); trn.FIRST.SWAP_POINT = Convert.ToDecimal(strSwapPointFar); trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmtFar) : Convert.ToDecimal(strCounterAmtFar); trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy); trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R"; trn.LOG.INSERTDATE = DateTime.Now; trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId; trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID; trn.FLAG_SETTLE = !settleFlag; trn.REMARK = strRemark; var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable(); var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB"); var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB"); var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable(); if (n1 != null) trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value); else if (n2 != null) trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value); else { var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (firstRate != null && secondRate != null) { if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE)) trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE); else trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE); } else { var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness(); //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn); //trn.KK_CONTRIBUTE = Math.Abs(trn.NOTIONAL_THB.Value) * trn.KK_PCCF / 100; DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW(); flow1.ID = Guid.NewGuid(); flow1.DA_TRN_ID = trn.ID; flow1.FLAG_FIRST = true; flow1.RATE = trn.FIRST.RATE + trn.FIRST.SWAP_POINT; flow1.FLOW_DATE = trn.MATURITY_DATE; flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL; if (n1 != null) flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value); else { var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (a != null) { flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE); } else { var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE; flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID; DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW(); flow2.ID = Guid.NewGuid(); flow2.DA_TRN_ID = trn.ID; flow2.FLAG_FIRST = false; flow2.FLOW_DATE = trn.MATURITY_DATE; flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL; if (n2 != null) flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value); else { var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (a != null) { flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE); } else { var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID); throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate."); } } flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE; flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID; trn.DA_TRN_FLOW.Add(flow1); trn.DA_TRN_FLOW.Add(flow2); return trn; }
public DA_TRN GenerateSwapTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strInstrument, string strCtpy, string strPortfolio , string strEffDate, string strMatDate, string strNotional1 , string strCCY1 , string strFFL1, string strFFix1, string strRate1, string strFreq1 , string strNotional2, string strCCY2, string strFFL2, string strFFix2, string strRate2, string strFreq2 , int intDaySpan,string strRemark, string strProductId) { LookupBusiness _lookupBusiness = new LookupBusiness(); DA_TRN trn = new DA_TRN(); DA_TRN lastrn = null; Guid guTemp; if (Guid.TryParse(strProductId, out guTemp)) { lastrn = new DA_TRN(); lastrn = GetByID(guTemp); } trn.ID = Guid.NewGuid(); trn.ENGINE_DATE = sessionInfo.Process.CurrentDate; trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null); trn.INSTRUMENT_ID = Guid.Parse(strInstrument); trn.CTPY_ID = Guid.Parse(strCtpy); trn.PORTFOLIO_ID = Guid.Parse(strPortfolio); trn.START_DATE = DateTime.ParseExact(strEffDate, "dd/MM/yyyy", null); trn.MATURITY_DATE = DateTime.ParseExact(strMatDate, "dd/MM/yyyy", null); trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional1); trn.SECOND.NOTIONAL = Convert.ToDecimal(strNotional2); //Fix Currency Type trn.FIRST.CCY_ID = Guid.Parse(strCCY1); trn.SECOND.CCY_ID= Guid.Parse(strCCY2); trn.FIRST.FLAG_PAYREC = "P"; trn.FIRST.FLAG_FIXED = strFFL1 == "1" ? true : false; if (!trn.FIRST.FLAG_FIXED.Value) { trn.FIRST.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix1); } trn.FIRST.RATE = Convert.ToDecimal(strRate1); trn.FIRST.FREQTYPE_ID = Guid.Parse(strFreq1); trn.SECOND.FLAG_PAYREC = "R"; trn.SECOND.FLAG_FIXED = strFFL2 == "1" ? true : false; if (!trn.SECOND.FLAG_FIXED.Value) { trn.SECOND.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix2); } trn.SECOND.RATE = Convert.ToDecimal(strRate2); trn.SECOND.FREQTYPE_ID = Guid.Parse(strFreq2); if (lastrn != null) { if (strRemark == "") throw this.CreateException(new Exception(), "Please input comment."); else trn.REMARK = strRemark; } trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.SWAP.ToString()).ID; trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1; trn.SOURCE = SourceType.INT.ToString(); trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID; trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO; trn.FLAG_SETTLE = true; trn.LOG.INSERTDATE = DateTime.Now; trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId; var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable(); var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB"); var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB"); var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable(); var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate); if (firstRate == null || secondRate == null) { var ccylabel = ccys.Where(p => (p.ID == trn.FIRST.CCY_ID && firstRate == null) || (p.ID == trn.SECOND.CCY_ID && secondRate == null)).Select(p => p.LABEL); var strCCY = string.Join(" and ",ccylabel); throw this.CreateException(new Exception(), "Error : There is no " + strCCY + " spot rate."); } if (n1 != null) trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value); else if (n2 != null) trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value); else { if (Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE)) trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE); else trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE); } GenerateCashFlows(sessionInfo, trn, intDaySpan, firstRate.RATE, secondRate.RATE); return trn; }
/// <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; }