private void updateMarketDataByGZB(string fundcode, string authcode) { if (authcode != DataService.GetInstance().GetAuthorizationCode()) { LabelStatus.Text = "无效的授权码"; LabelStatus.Visible = true; return; } DateTime lastTradeDay = DateTime.Today.AddDays(-1); //倒序排列交易日,获得最后一个交易日 DataTable dtTradingDays = DataService.GetInstance().GetTradingDaysList(DateTime.Today.AddDays(-10), DateTime.Today.AddDays(-1)); dtTradingDays.DefaultView.Sort = "trade_days desc"; dtTradingDays = dtTradingDays.DefaultView.ToTable(); if (dtTradingDays != null && dtTradingDays.Rows.Count > 0) { string str = dtTradingDays.Rows[0]["trade_days"].ToString(); lastTradeDay = new DateTime( Convert.ToInt16(str.Substring(0, 4)), Convert.ToInt16(str.Substring(4, 2)), Convert.ToInt16(str.Substring(6, 2)) ); } //读取最后交易日持仓数据 IFundDataAdapter IFDA = FundDataAdaptorFactory.GetAdaptor(FundDataAdaptorFactory.AdapterType.YSS); DataTable dtGZB = DataService.GetInstance().GetGZB(lastTradeDay, lastTradeDay, fundcode, null); Portfolio p = new Portfolio(fundcode, "", Portfolio.PortfolioType.MutualFund, Portfolio.PortfolioCategoryI.EquityFund, Portfolio.PortfolioCategoryII.OpenEnd); p.UpdatePositionByGZB(IFDA.BuildGZBList(dtGZB)); List <AssetPosition> equityList = p.EquityPositionList; List <string> equityCodeList = new List <string>(); if (equityList == null || equityList.Count == 0) { return; } //根据持仓数据修改显示项目 string filter = "s_info_windcode in ("; for (int i = 0; i < equityList.Count; i++) { filter += "'" + equityList[i].WindCode + "',"; equityCodeList.Add(equityList[i].WindCode.Trim().ToUpper()); } filter = filter.Substring(0, filter.Length - 1) + ")"; _BlockTrade.DefaultView.RowFilter = filter; _MarginTrade.DefaultView.RowFilter = filter; _StrangeTrade.DefaultView.RowFilter = filter; _RestrictStock.DefaultView.RowFilter = filter; _IPOSEO.DefaultView.RowFilter = filter; _MarketNews = DataService.GetInstance().GetMarketNews(equityCodeList); }
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; } }