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

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

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

            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

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

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

            DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

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

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

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

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

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

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

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

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

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

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

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

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

            trn.DA_TMBA_EXTENSION = tbma;
            return trn;
        }
Example #3
0
        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;
        }
Example #4
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);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Import Cash flows to DA_TRN.DA_TRN_CASHFLOW
        /// </summary>
        private static List<DA_TRN_CASHFLOW> GenerateCashflowObject(SessionInfo sessioninfo, List<CASHFLOWModel> opicscashflows, List<DA_TRN_CASHFLOW> importedcashflows, List<DA_TRN> trns)
        {
            List<DA_TRN_CASHFLOW> cashflows = new List<DA_TRN_CASHFLOW>();
            DA_TRN_CASHFLOW newcashflow;
            DA_TRN trn = null;
            DA_TRN_CASHFLOW importedflow = null;

            foreach (CASHFLOWModel opicscashflow  in opicscashflows)
            {
                //Check whether deal is imported
                trn = trns.FirstOrDefault(p => p.EXT_DEAL_NO == opicscashflow.EXT_DEAL_NO);

                if (trn != null)
                {
                    //Check duplicate
                    importedflow = importedcashflows.FirstOrDefault(p => p.DA_TRN_ID == trn.ID
                                                                    && p.FLAG_FIRST.Equals(opicscashflow.LEG == 1 ? true : false)
                                                                    && p.SEQ == opicscashflow.SEQ);

                    if (importedflow == null)
                    {
                        newcashflow = new DA_TRN_CASHFLOW();

                        newcashflow.ID = Guid.NewGuid();
                        newcashflow.DA_TRN_ID = trn.ID;
                        newcashflow.FLAG_FIRST = opicscashflow.LEG == 1 ? true : false;
                        newcashflow.SEQ = opicscashflow.SEQ;
                        newcashflow.RATE = opicscashflow.RATE;
                        newcashflow.FLOW_DATE = opicscashflow.FLOW_DATE;
                        newcashflow.FLOW_AMOUNT = opicscashflow.FLOW_AMOUNT;
                        newcashflow.FLOW_AMOUNT_THB = opicscashflow.FLOW_AMOUNT_THB;

                        newcashflow.LOG.INSERTDATE = DateTime.Now;
                        newcashflow.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;

                        cashflows.Add(newcashflow);
                    }
                }
            }

            return cashflows;
        }