예제 #1
0
        private void parsePositionDetail(GZBItem gzbItem)
        {
            #region 定制字母数字转换表
            if (_htCodeDict == null)
            {
                _htCodeDict = new Hashtable();
                _htCodeDict.Add("A", "10");
                _htCodeDict.Add("B", "11");
                _htCodeDict.Add("C", "12");
                _htCodeDict.Add("D", "13");
                _htCodeDict.Add("E", "14");
                _htCodeDict.Add("F", "15");
                _htCodeDict.Add("G", "16");
                _htCodeDict.Add("H", "17");
                _htCodeDict.Add("I", "18");
                _htCodeDict.Add("J", "19");
                _htCodeDict.Add("K", "20");
                _htCodeDict.Add("L", "21");
                _htCodeDict.Add("M", "22");
                _htCodeDict.Add("N", "23");
                _htCodeDict.Add("O", "24");
                _htCodeDict.Add("P", "25");
                _htCodeDict.Add("Q", "26");
                _htCodeDict.Add("R", "27");
                _htCodeDict.Add("S", "28");
                _htCodeDict.Add("T", "29");
                _htCodeDict.Add("U", "30");
                _htCodeDict.Add("V", "31");
                _htCodeDict.Add("W", "32");
                _htCodeDict.Add("X", "33");
                _htCodeDict.Add("Y", "34");
                _htCodeDict.Add("Z", "35");
            }
            #endregion

            //==============================
            //输入项目代码必须14位及以上
            //==============================
            try
            {
                //1102 01 01    600060
                //股票 沪  成本  代码
                string itemCode           = gzbItem.ItemCode;
                string itemCostOrInterest = itemCode.Substring(6, 2);
                string assetCode8         = itemCode.Substring(0, 8);
                string assetCode4         = itemCode.Substring(0, 4);
                string tradeCode          = gzbItem.ItemCode.Substring(8); //交易所6位,银行间7-9位
                string windCode           = tradeCode;

                if (itemCostOrInterest != "01")   //成本01  利息10
                {
                    return;
                }

                #region 查询资产类别
                AssetCategory assetCategory = AssetCategory.Other;
                switch (assetCode4)
                {
                case DBConsts.C_GZB_KMBM_CashDeposit:
                    assetCategory = AssetCategory.CashDeposit;
                    break;

                case DBConsts.C_GZB_KMBM_RevRepo:
                    assetCategory = AssetCategory.Repo;
                    break;

                case DBConsts.C_GZB_KMBM_Stock:
                    assetCategory = AssetCategory.Equity;
                    break;

                case DBConsts.C_GZB_KMBM_Bond:
                    assetCategory = AssetCategory.Bond;
                    break;

                case DBConsts.C_GZB_KMBM_Fund:
                    assetCategory = AssetCategory.Fund;
                    break;

                case DBConsts.C_GZB_KMBM_Warrant:
                    assetCategory = AssetCategory.Warrant;
                    break;

                default:
                    assetCategory = AssetCategory.Other;
                    break;
                }
                #endregion

                #region 查询资产后缀
                switch (assetCode8)
                {
                case DBConsts.C_GZB_KMBM_Stock_SH:
                case DBConsts.C_GZB_KMBM_IPO_SH:
                case DBConsts.C_GZB_KMBM_SEO_SH:
                case DBConsts.C_GZB_KMBM_Bond_SH_CB:
                case DBConsts.C_GZB_KMBM_Bond_SH_UZ:
                case DBConsts.C_GZB_KMBM_Bond_SH_Corp:
                case DBConsts.C_GZB_KMBM_Bond_SH_Govn:
                case DBConsts.C_GZB_KMBM_Repo_SH_PL:
                case DBConsts.C_GZB_KMBM_Repo_SH_BO:
                case DBConsts.C_GZB_KMBM_Fund_SH:
                    windCode += ".SH";
                    break;

                case DBConsts.C_GZB_KMBM_Stock_SZ:
                case DBConsts.C_GZB_KMBM_Stock_CY:
                case DBConsts.C_GZB_KMBM_SEO_SZ:
                case DBConsts.C_GZB_KMBM_IPO_SZ:
                case DBConsts.C_GZB_KMBM_Bond_SZ_CB:
                case DBConsts.C_GZB_KMBM_Bond_SZ_Corp:
                case DBConsts.C_GZB_KMBM_Bond_SZ_Govn:
                case DBConsts.C_GZB_KMBM_Repo_SZ_PL:
                case DBConsts.C_GZB_KMBM_Repo_SZ_BO:
                case DBConsts.C_GZB_KMBM_Fund_SZ:
                case DBConsts.C_GZB_KMBM_Bond_SZ_STFB:
                    windCode += ".SZ";
                    break;

                case DBConsts.C_GZB_KMBM_Bond_IB_Govn:
                case DBConsts.C_GZB_KMBM_Bond_IB_FinB:
                case DBConsts.C_GZB_KMBM_Bond_IB_Bill:
                case DBConsts.C_GZB_KMBM_Bond_IB_POFB:
                case DBConsts.C_GZB_KMBM_Repo_IB_PL:
                case DBConsts.C_GZB_KMBM_Repo_IB_BO:
                    windCode += ".IB";
                    break;

                case DBConsts.C_GZB_KMBM_Bond_IB_Corp:
                    windCode  = tradeCode;
                    windCode  = windCode.Replace("A", "10");
                    windCode  = windCode.Replace("B", "11");
                    windCode  = windCode.Replace("C", "12");
                    windCode  = windCode.Replace("D", "13");
                    windCode  = windCode.Replace("E", "14");
                    windCode += ".IB";
                    break;

                case DBConsts.C_GZB_KMBM_Bond_IB_STFB:
                    //对于04 11 64 004这种债券,代码结构为券种(两位)+发行年份(两位)+发行机构(两位)+发行期数(三位)可以采用以下方式:
                    //  券种两位转换为一位04则为4,年份两位转换为一位11则为B,发行主体不变,期数转换为两位004则为04。
                    //  041164004则为4B6404
                    string bondCode   = "0" + tradeCode.Substring(0, 1);
                    string yearCode   = tradeCode.Substring(1, 1);
                    string issuerCode = tradeCode.Substring(2, 2);
                    string termCode1  = tradeCode.Substring(4, 1);
                    string termCode2  = tradeCode.Substring(5, 1);

                    if (_htCodeDict.Contains(yearCode))
                    {
                        yearCode = _htCodeDict[yearCode].ToString();
                    }

                    if (_htCodeDict.Contains(termCode1))
                    {
                        termCode1 = _htCodeDict[termCode1].ToString();
                    }
                    else
                    {
                        termCode1 = "0" + termCode1;
                    }

                    windCode = bondCode + yearCode + issuerCode + termCode1 + termCode2 + ".IB";
                    break;

                case DBConsts.C_GZB_KMBM_Fund_OF:
                case DBConsts.C_GZB_KMBM_Fund_OF_M:
                    windCode += ".OF";
                    break;

                //case DBConsts.C_GZB_KMBM_SEO_SZ:
                //case DBConsts.C_GZB_KMBM_SEO_SH:
                //    //增发项目:忽略之;股份收到后会自动记入股票项目
                //    return;
                default:
                    throw new Exception("未知的金融资产:" + gzbItem.ItemCode + "|" + gzbItem.ItemName);
                }
                #endregion

                AssetPosition p = new AssetPosition();
                p.ReportDate         = this.ReportDate;
                p.Code               = tradeCode;
                p.WindCode           = windCode;
                p.Name               = gzbItem.ItemName;
                p.Price.TradeDate    = gzbItem.ItemDate;
                p.Price.Close        = gzbItem.CurrentPrice;
                p.HoldingQuantity    = gzbItem.HoldingQuantity;
                p.HoldingCost        = gzbItem.HoldingCost;
                p.HoldingMarketValue = gzbItem.HoldingMarketValue;
                p.Pctof_Nav          = gzbItem.HoldingMVPctofNAV;
                p.Category           = assetCategory;

                switch (assetCategory)
                {
                case AssetCategory.Equity:
                    p.Pctof_Portfolio = p.HoldingMarketValue / this.EquityPositionAmt;
                    this.EquityPositionList.Add(p);
                    break;

                case AssetCategory.Bond:
                    p.Pctof_Portfolio = p.HoldingMarketValue / this.BondPositionAmt;

                    //区分转债与纯债
                    switch (assetCode8)
                    {
                    case DBConsts.C_GZB_KMBM_Bond_SH_CB:
                    case DBConsts.C_GZB_KMBM_Bond_SZ_CB:
                        p.Category = AssetCategory.ConvertableBond;
                        break;

                    default:
                        break;
                    }

                    this.BondPositionList.Add(p);
                    break;

                case AssetCategory.Repo:
                case AssetCategory.Fund:
                case AssetCategory.Warrant:
                    p.Pctof_Portfolio = p.HoldingMarketValue / (this.RevRepoPositionAmt + this.FundPositionAmt + this.WarrantPositionAmt);
                    this.OtherPositionList.Add(p);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(DBConsts.C_ErrMsg_ErrorPositionDetail + ex.Message, ex);
            }
        }
예제 #2
0
        //private List<string> _EquityCodeList = new List<string>();
        //private List<string> _BondCodeList = new List<string>();

        public List <GZBItem> BuildGZBList(DataTable dtGZB)
        {
            //==================================================================================================
            //字段名
            //FDate, FKmbm, FKmmc, FHqjg, FZqsl, FZqcb, FZqsz, Gz_zz, FSz_Jz_bl, FCb_Jz_bl
            //==================================================================================================

            try
            {
                _GZBList.Clear();

                if (dtGZB != null && dtGZB.Rows.Count > 0)
                {
                    foreach (DataRow oRow in dtGZB.Rows)
                    {
                        GZBItem gzb = new GZBItem();
                        string  pct = "";

                        foreach (DataColumn oCol in dtGZB.Columns)
                        {
                            if (oRow[oCol.ColumnName] == DBNull.Value)
                            {
                                continue;
                            }

                            string colNameAdjusted = oCol.ColumnName.ToUpper();
                            switch (colNameAdjusted)
                            {
                            case DBConsts.C_GZB_ColName_FDate:
                                gzb.ItemDate = Convert.ToDateTime(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FKmbm:
                                gzb.ItemCode = oRow[oCol.ColumnName].ToString();
                                //this.parseCode(gzb.ItemCode);
                                break;

                            case DBConsts.C_GZB_ColName_FKmmc:
                                gzb.ItemName = oRow[oCol.ColumnName].ToString();
                                break;

                            case DBConsts.C_GZB_ColName_FZqsl:
                                gzb.HoldingQuantity = Convert.ToDouble(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FZqcb:
                                gzb.HoldingCost = Convert.ToDouble(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FZqsz:
                                gzb.HoldingMarketValue = Convert.ToDouble(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FGz_zz:
                                gzb.HoldingValueAdded = Convert.ToDouble(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FHqjg:
                                gzb.CurrentPrice = Convert.ToDouble(oRow[oCol.ColumnName]);
                                break;

                            case DBConsts.C_GZB_ColName_FCb_Jz_bl:
                                //比例:原值="15.23%",新值="0.1523"
                                if (oRow[oCol.ColumnName] != DBNull.Value)
                                {
                                    pct = oRow[oCol.ColumnName].ToString();
                                    pct = pct.Substring(0, pct.Length - 1);
                                    gzb.HoldingCostPctofNAV = Convert.ToDouble(pct) / 100;
                                }
                                break;

                            case DBConsts.C_GZB_ColName_FSz_Jz_bl:
                                //比例:原值="15.23%",新值="0.1523"
                                if (oRow[oCol.ColumnName] != DBNull.Value)
                                {
                                    pct = oRow[oCol.ColumnName].ToString();
                                    pct = pct.Substring(0, pct.Length - 1);
                                    gzb.HoldingMVPctofNAV = Convert.ToDouble(pct) / 100;
                                }
                                break;

                            default:
                                break;
                            }
                        }

                        _GZBList.Add(gzb);
                    }
                }

                return(_GZBList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }