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; } }
protected void GridViewCBondPositionDetail_PageIndexChanging(object sender, GridViewPageEventArgs e) { ((GridView)sender).PageIndex = e.NewPageIndex; ((GridView)sender).DataSource = _htmloutput.GetConvertableBondPositionTable(); ((GridView)sender).DataBind(); }