示例#1
0
        public static ABSDealResult GetNancyDealResult(ABSDeal absDeal, NancyStaticAnalysisResult nancyResult)
        {
            var result = new ABSDealResult();

            result.OriginAcf = nancyResult.AssetCashflowDt;
            result.OriginCf  = nancyResult.CashflowDt;
            result.Acf       = result.OriginAcf.Copy();
            result.Cf        = result.OriginCf.Copy();
            result.AcfResult = new AcfResult(result.OriginAcf, absDeal.Assets);

            RunSpecialRules(result.Cf, absDeal.Info.IsCsdcDeal);

            SplitCategoryByNote(result.Cf);

            result.Cf  = CleanAndTranslateCashflowTable(result.Cf);
            result.Acf = CleanAndTranslateAssetCashflowTable(result.Acf);

            AddAssetIdToRepeatedCNName(result.Acf, absDeal);

            var dictDates = GetDeterminationDatesByPaymentDates(absDeal);

            ConvertAcfColumnDateName(result.Acf, dictDates);

            return(result);
        }
示例#2
0
        private decimal GetFee(string feeName)
        {
            //var dsVariables = NancyUtils.GetOverridableVariables(m_project.ProjectId);

            var logicModel = new ProjectLogicModel(m_userName, m_project.ProjectId);
            var dataset    = logicModel.DealSchedule.GetByPaymentDay(m_paymentDay).Dataset;
            NancyStaticAnalysisResult results = NancyUtils.GetStaticAnalyticsResult(m_project.ProjectId,
                                                                                    null, dataset.Instance.AsOfDate, dataset.AssetOverrideSetting);

            var cfTable = results.CashflowDt;

            int columnIndex = -1;

            for (int i = 0; i < cfTable.Columns.Count; ++i)
            {
                DateTime columnDate;
                if (DateTime.TryParse(cfTable.Columns[i].ColumnName, out columnDate) &&
                    m_paymentDay == columnDate)
                {
                    columnIndex = i;
                    break;
                }
            }

            CommUtils.Assert(columnIndex >= 0, "找不到对应支付日[" + m_paymentDay.ToString() + "]的数据");

            for (int i = 0; i < cfTable.Rows.Count; ++i)
            {
                var row = cfTable.Rows[i];
                if (row.ItemArray[1].Equals(feeName))
                {
                    return(decimal.Parse(row.ItemArray[columnIndex].ToString()));
                }
            }

            throw new ApplicationException("Can't find [" + feeName + "].");
        }
示例#3
0
        /// <summary>
        /// 对nancy返回的结果执行特殊的规则处理:
        /// 1、证券利随本清
        /// 2、证券和产品偿付频率错配
        /// 3、合并留存金额
        /// 4、自动处理中证登手续费
        /// </summary>
        /// <param name="result"></param>
        /// <param name="isCsdcDeal"></param>
        private static void RunSpecialRules(NancyStaticAnalysisResult result, bool isCsdcDeal)
        {
            var table = result.CashflowDt;
            //处理“证券利随本清”
            var rowIndex = table.IndexOfRow(x => x.ItemArray[1].Equals("证券利随本清"));

            if (rowIndex >= 0)
            {
                var key = ".Receiver Distribution";
                var rowIndexReceiver = -1;
                while ((rowIndexReceiver = table.IndexOfRow(x => x.ItemArray[1].ToString().Contains(key))) >= 0)
                {
                    var description = table.Rows[rowIndexReceiver].ItemArray[1].ToString();
                    var noteName    = description.Substring(0, description.Length - key.Length);
                    var rowIndexInterestReceived     = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Interest Received");
                    var rowIndexBeginningInterestDue = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Beginning Interest Due");
                    if (rowIndexInterestReceived < 0 || rowIndexBeginningInterestDue < 0)
                    {
                        break;
                    }

                    //把Receiver Distribution和Interest Received的值加起来
                    for (int i = 2; i < table.Columns.Count; ++i)
                    {
                        var totalInterest = double.Parse(table.Rows[rowIndexInterestReceived][i].ToString())
                                            + double.Parse(table.Rows[rowIndexReceiver][i].ToString());

                        table.Rows[rowIndexReceiver][i] = totalInterest.ToString("n2");
                    }

                    table.CopyRow(rowIndexReceiver, rowIndexInterestReceived, 2);
                    table.CopyRow(rowIndexReceiver, rowIndexBeginningInterestDue, 2);
                    table.Rows.RemoveAt(rowIndexReceiver);
                }
            }

            //备份第一种处理“证券利随本清”的方法
            //rowIndex = table.IndexOfRow(x => x.ItemArray[1].Equals("Alpha证券利随本清Alpha"));
            //if (rowIndex >= 0)
            //{
            //    table.Rows.RemoveAt(rowIndex);

            //    //收到的逾期利息
            //    var key = ".Deferred Interest Received";
            //    var rowIndexDeferredInterestReceived = -1;
            //    while ((rowIndexDeferredInterestReceived = table.IndexOfRow(x => x.ItemArray[1].ToString().Contains(key))) >= 0)
            //    {
            //        var description = table.Rows[rowIndexDeferredInterestReceived].ItemArray[1].ToString();
            //        var noteName = description.Substring(0, description.Length - key.Length);

            //        //收到的利息
            //        var rowIndexInterestReceived = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Interest Received");
            //        //预计收到的利息
            //        var rowIndexBeginningInterestDue = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Beginning Interest Due");
            //        //未偿利息(逾期利息)
            //        var rowIndexInteststDeferred = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Interest Deferred");
            //        if (rowIndexInterestReceived < 0 || rowIndexBeginningInterestDue < 0 || rowIndexInterestReceived < 0)
            //        {
            //            break;
            //        }

            //        for (int i = 2; i < table.Columns.Count; ++i)
            //        {
            //            var interestReceived = double.Parse(table.Rows[rowIndexInterestReceived][i].ToString())
            //                + double.Parse(table.Rows[rowIndexDeferredInterestReceived][i].ToString());

            //            //收到的利息=收到的利息+收到的逾期利息
            //            table.Rows[rowIndexInterestReceived][i] = interestReceived.ToString("n2");
            //            //预计收到的利息=收到的利息+收到的逾期利息
            //            table.Rows[rowIndexBeginningInterestDue][i] = table.Rows[rowIndexInterestReceived][i];
            //        }

            //        //清空未偿利息(逾期利息)
            //        table.Rows.RemoveAt(rowIndexInteststDeferred);
            //        //清空收到的逾期利息
            //        table.Rows.RemoveAt(rowIndexDeferredInterestReceived);
            //    }
            //}

            var dsTable = new DsTable(result.CashflowDt);

            //处理“证券和产品偿付频率错配”
            MergeReceiverDistributionWithInterestReceived(dsTable);

            //合并留存金额
            MergeReserveRows(dsTable);

            dsTable.OverrideTo(result.CashflowDt);

            //是否自动处理中证手续费
            if (isCsdcDeal)
            {
                var csdcRows = new List <Tuple <int, DataRow> >();

                var key = ".Interest Received";
                for (var i = 0; i < table.Rows.Count; ++i)
                {
                    var row = table.Rows[i];
                    if (row.ItemArray[1].ToString().EndsWith(key, StringComparison.CurrentCultureIgnoreCase))
                    {
                        var description = row.ItemArray[1].ToString();
                        var noteName    = description.Substring(0, description.Length - key.Length);

                        var principalReceivedIndex = table.IndexOfRow(x => x.ItemArray[1].ToString() == noteName + ".Principal Received");

                        var csdcRow = table.NewRow();
                        csdcRow[0] = "Notes";
                        csdcRow[1] = noteName + ".CsdcFee";

                        for (int j = 2; j < table.Columns.Count; ++j)
                        {
                            //中证登手续费 = (本金 + 利息) * 万分之0.5
                            var totalReceived = double.Parse(table.Rows[principalReceivedIndex][j].ToString())
                                                + double.Parse(row[j].ToString());

                            csdcRow[j] = (totalReceived * 0.00005).ToString("n2");
                        }

                        csdcRows.Add(Tuple.Create(i, csdcRow));
                    }
                }

                csdcRows = csdcRows.OrderByDescending(x => x.Item1).ToList();

                foreach (var csdcRow in csdcRows)
                {
                    table.Rows.InsertAt(csdcRow.Item2, csdcRow.Item1);
                }
            }
        }