Exemple #1
0
    private void buildPerformanceReport(DateTime reportStart, DateTime reportEnd, string fundCode)
    {
        try
        {
            IFundDataAdapter   IFDA = FundDataAdaptorFactory.GetAdaptor(FundDataAdaptorFactory.AdapterType.YSS);
            IMarketDataAdapter IMDA = MarketDataAdaptorFactory.GetAdaptor(MarketDataAdaptorFactory.AdapterType.Wind);

            //基金类型数据
            DataTable dtFund   = DataService.GetInstance().GetPortfolioList();
            DataRow   oFundRow = null;
            if (dtFund != null)
            {
                for (int i = 0; i < dtFund.Rows.Count; i++)
                {
                    string fcode = dtFund.Rows[i]["Code"].ToString();
                    if (fcode == fundCode)
                    {
                        oFundRow = dtFund.Rows[i];
                        break;
                    }
                }
            }

            if (oFundRow == null)
            {
                LabelStatus.Text = "未知的代码!";
                return;
            }

            string fundName      = oFundRow["Name"].ToString();
            string isHedgeFund   = oFundRow["IsHedgeFund"].ToString();
            string assetType     = oFundRow["AssetType"].ToString();
            string operationType = oFundRow["opType"].ToString();

            Portfolio.PortfolioType       pType       = Portfolio.PortfolioType.MutualFund;
            Portfolio.PortfolioCategoryI  pCategoryI  = Portfolio.PortfolioCategoryI.EquityFund;
            Portfolio.PortfolioCategoryII pCategoryII = Portfolio.PortfolioCategoryII.OpenEnd;

            switch (assetType)
            {
            case "E":       //Equity
                pCategoryI = Portfolio.PortfolioCategoryI.EquityFund;
                break;

            case "B":       //Bond
                pCategoryI = Portfolio.PortfolioCategoryI.BondFund;
                break;

            case "M":       //Monetary
                pCategoryI = Portfolio.PortfolioCategoryI.MonetaryFund;
                break;

            default:
                break;
            }

            switch (operationType)
            {
            case "O":       //Open End
                pCategoryII = Portfolio.PortfolioCategoryII.OpenEnd;
                break;

            case "C":       //Close End
                pCategoryII = Portfolio.PortfolioCategoryII.CloseEnd;
                break;

            default:
                break;
            }

            if (isHedgeFund == "1")
            {
                pType = Portfolio.PortfolioType.HedgeFunds;
            }
            else
            {
                pType = Portfolio.PortfolioType.MutualFund;
            }


            //market data
            DataTable dtGZB          = DataService.GetInstance().GetGZB(reportStart, reportEnd, fundCode, null);
            DataTable dtTradingDays  = DataService.GetInstance().GetTradingDaysList(reportStart, reportEnd);
            DataTable dtPriceInfo    = DataService.GetInstance().GetStockPrices(reportStart, reportEnd);          //1Month:   2400 * 22 = 52800 Rows
            DataTable dtEquityInfo   = DataService.GetInstance().GetAShareStockList(null);                        //Total:    2400 Rows
            DataTable dtCapitalInfo  = DataService.GetInstance().GetFreeFloatCapital(reportEnd, null);            //Total:    2400 Rows
            DataTable dtIndustryInfo = DataService.GetInstance().GetSWIndustryList();                             //Total:      23 Rows

            //==============================
            //Benchmark
            //==============================
            DataTable          dtBenchmarkList = DataService.GetInstance().GetPortfolioBenchmarkList(fundCode);
            string             defaultBMCode   = "000300.SH";
            BenchmarkPortfolio bmf             = new BenchmarkPortfolio(reportStart, reportEnd, reportStart, reportEnd);
            if (dtBenchmarkList.Rows.Count > 0)
            {
                foreach (DataRow oRow in dtBenchmarkList.Rows)
                {
                    string benchmarkcode   = "";
                    string benchmarkname   = "";
                    double benchmarkweight = 0;
                    double constrate       = 0;

                    if (oRow["BENCHMARKCODE"] != DBNull.Value)
                    {
                        benchmarkcode = oRow["BENCHMARKCODE"].ToString();
                    }
                    if (oRow["BENCHMARKNAME"] != DBNull.Value)
                    {
                        benchmarkname = oRow["BENCHMARKNAME"].ToString();
                    }
                    if (oRow["BENCHMARKWEIGHT"] != DBNull.Value)
                    {
                        benchmarkweight = Convert.ToDouble(oRow["BENCHMARKWEIGHT"]);
                    }
                    if (oRow["CONSTRATE"] != DBNull.Value)
                    {
                        constrate = Convert.ToDouble(oRow["CONSTRATE"]);
                    }

                    if (benchmarkcode.Length > 0)
                    {
                        //e.g. 沪深300指数
                        DataTable dtBenchmarkIndex = DataService.GetInstance().GetIndexPrices(reportStart, reportEnd, benchmarkcode);
                        bmf.AddBenchmarkIndex(new BenchmarkDef(benchmarkcode, benchmarkname, benchmarkweight, 0, IMDA.GetPriceList(dtBenchmarkIndex)));
                        defaultBMCode = benchmarkcode;
                    }
                    else
                    {
                        //e.g. 银行存款
                        bmf.AddBenchmarkIndex(new BenchmarkDef(null, benchmarkname, benchmarkweight, constrate, null));
                    }
                }
            }

            DataTable dtBMWeight = DataService.GetInstance().GetIndexWeights(defaultBMCode, reportEnd);
            bmf.BuildBenchmarkComponents(IMDA.GetPositionList(dtBMWeight), IMDA.GetPriceList(dtPriceInfo));

            //==============================
            //Performance Evaluator
            //==============================
            PerformanceEvaluator pe = new PerformanceEvaluator(reportStart, reportEnd, fundCode, fundName, pType, pCategoryI, pCategoryII);
            pe.BuildPortfolios(IFDA.BuildGZBList(dtGZB), IMDA.GetPositionList(dtEquityInfo), IMDA.GetPriceList(dtPriceInfo), IMDA.GetPositionList(dtCapitalInfo));

            //更新债券到期日等
            string bondcodelist = "";
            pe.GetBondPositions(out bondcodelist);
            if (bondcodelist.Length > 0)
            {
                DataTable dtBondInfo = DataService.GetInstance().GetChinaBondList(bondcodelist);
                pe.UpdateBondPositions(IMDA.GetPositionList(dtBondInfo));
            }

            //评估
            pe.Evaluate(bmf, IMDA.GetIndustryList(dtIndustryInfo));

            //==============================
            //Output
            //==============================
            _htmloutput = new HTMLOutput(pe);

            //基本信息
            spFundInfo.InnerHtml = _htmloutput.GetFundInfo();

            //流动性风险: 股票/债券
            GridViewEquityPositionDetail.DataSource = _htmloutput.GetEquityPositionTable();
            GridViewEquityPositionDetail.DataBind();
            GridViewBondPositionDetail.DataSource = _htmloutput.GetPureBondPositionTable();
            GridViewBondPositionDetail.DataBind();
            GridViewCBondPositionDetail.DataSource = _htmloutput.GetConvertableBondPositionTable();
            GridViewCBondPositionDetail.DataBind();
            GridViewCashPositionDetail.DataSource = _htmloutput.GetCashPositionTable();
            GridViewCashPositionDetail.DataBind();
            GridViewOtherPositionDetail.DataSource = _htmloutput.GetOtherPositionTable();
            GridViewOtherPositionDetail.DataBind();

            //绩效归因
            GridViewIndustry.DataSource = _htmloutput.GetIndustryTable();
            GridViewIndustry.DataBind();
        }
        catch (Exception ex)
        {
            LabelStatus.Visible = true;
            LabelStatus.Text    = ex.Message;
        }
    }
Exemple #2
0
    private void buildPositionReport(DateTime reportStart, DateTime reportEnd, string fundCode)
    {
        try
        {
            //基金类型数据
            DataTable dtFund   = DataService.GetInstance().GetPortfolioList();
            DataRow   oFundRow = null;
            if (dtFund != null)
            {
                for (int i = 0; i < dtFund.Rows.Count; i++)
                {
                    string fcode = dtFund.Rows[i]["Code"].ToString();
                    if (fcode == fundCode)
                    {
                        oFundRow = dtFund.Rows[i];
                        break;
                    }
                }
            }

            if (oFundRow == null)
            {
                LabelStatus.Text = "未知的代码!";
                return;
            }

            string      fundName      = oFundRow["Name"].ToString();
            string      benchmarkname = oFundRow["Benchmark"].ToString();
            string      benchmarkcode = oFundRow["BenchmarkCode"].ToString();
            DataTable   dtGZB         = DataService.GetInstance().GetGZB(reportStart, reportEnd, fundCode, null);
            Performance p             = new Performance();
            p.LoadData(dtGZB, Security.Portfolio.PortfolioDataAdapterType.YSS, reportStart, reportEnd, benchmarkcode);
            p.Attribute();

            //基本信息
            string html = this.getFundInfo(p, fundCode, fundName, benchmarkname);
            spFundInfo.InnerHtml = html;

            //归因分析
            GridViewIndustry.DataSource = p.GetAttributionTable();
            GridViewIndustry.DataBind();

            //持仓分析
            GridViewEquityPositionDetail.DataSource = p.GetPositionTable(SecurityType.Equity);
            GridViewEquityPositionDetail.DataBind();
            GridViewEquityPositionDetail.Caption = "股票持仓(" + p.PortfGroup.GetLatestPortfolio().EquityHoldings.Position.MarketValuePct.ToString("P2") + ")";

            GridViewBondPositionDetail.DataSource = p.GetPositionTable(SecurityType.Bond);
            GridViewBondPositionDetail.DataBind();
            GridViewBondPositionDetail.Caption = "债券持仓(" + p.PortfGroup.GetLatestPortfolio().BondHoldings.Position.MarketValuePct.ToString("P2") + ")";

            GridViewFundPositionDetail.DataSource = p.GetPositionTable(SecurityType.Fund);
            GridViewFundPositionDetail.DataBind();
            GridViewFundPositionDetail.Caption = "基金持仓(" + p.PortfGroup.GetLatestPortfolio().FundHoldings.Position.MarketValuePct.ToString("P2") + ")";

            GridViewRevRepoPositionDetail.DataSource = p.GetPositionTable(SecurityType.RevRepo);
            GridViewRevRepoPositionDetail.DataBind();
            GridViewRevRepoPositionDetail.Caption = "逆回购持仓(" + p.PortfGroup.GetLatestPortfolio().RevRepoHoldings.Position.MarketValuePct.ToString("P2") + ")";

            GridViewTheRepoPositionDetail.DataSource = p.GetPositionTable(SecurityType.TheRepo);
            GridViewTheRepoPositionDetail.DataBind();
            GridViewTheRepoPositionDetail.Caption = "正回购持仓(" + p.PortfGroup.GetLatestPortfolio().TheRepoHoldings.Position.MarketValuePct.ToString("P2") + ")";

            GridViewCashPositionDetail.DataSource = p.GetPositionTable(SecurityType.Deposit);
            GridViewCashPositionDetail.DataBind();
            GridViewCashPositionDetail.Caption = "现金持仓(" + p.PortfGroup.GetLatestPortfolio().CashHoldings.Position.MarketValuePct.ToString("P2") + ")";

            //交易记录
            GridViewTransactionDetail.DataSource = p.GetTransactionTable();
            GridViewTransactionDetail.DataBind();

            //消息
            GridViewMessages.DataSource = MessageManager.GetInstance().GetMessageTable();
            GridViewMessages.DataBind();
        }
        catch (Exception ex)
        {
            LabelStatus.Visible = true;
            LabelStatus.Text    = ex.Message;
        }
    }