public List <EquityIndustry> GetIndustryList(DataTable dtIndustryInfo) { //================================================================================================== //Wind字段名 //s_info_indexcode, industriescode, industriesname //================================================================================================== try { List <EquityIndustry> industryList = new List <EquityIndustry>(); if (dtIndustryInfo != null && dtIndustryInfo.Rows.Count > 0) { foreach (DataRow oRow in dtIndustryInfo.Rows) { EquityIndustry industry = new EquityIndustry(); foreach (DataColumn oCol in dtIndustryInfo.Columns) { switch (oCol.ColumnName.ToLower()) { case DBConsts.C_Mkt_ColumnName_SWIndustryIndexCode: industry.SWIndustryIndex = oRow[oCol].ToString(); break; case DBConsts.C_Mkt_ColumnName_IndustryName: industry.SWIndustryName = oRow[oCol].ToString(); break; default: break; } } industryList.Add(industry); } } return(industryList); } catch (Exception ex) { throw ex; } }
public int CompareTo(object obj) { try { //Order by pctof_equity Desc EquityIndustry ind = (EquityIndustry)obj; if (this.PortfolioWeight > ind.PortfolioWeight) { return(-1); } else { return(1); } } catch (Exception ex) { throw ex; } }
public void UpdateEquityByMarket(List <AssetPosition> equityList, List <EquityPrice> priceList, List <AssetPosition> capitalList) { #region Loop Position for (int i = 0; i < EquityPositionList.Count; i++) { string windcode = EquityPositionList[i].WindCode; //========================== //Industry //========================== #region Update Industry if (equityList != null && equityList.Count > 0) { int idxEquity = equityList.FindIndex(delegate(AssetPosition e) { return(e.WindCode == windcode); }); if (idxEquity >= 0) { EquityPositionList[i].Name = equityList[idxEquity].Name; EquityPositionList[i].SWIndustryName = equityList[idxEquity].SWIndustryName; EquityPositionList[i].SWIndustryIndex = equityList[idxEquity].SWIndustryIndex; //update industry list int idxIndustry = EquityIndustryList.FindIndex(delegate(EquityIndustry ind) { return(ind.SWIndustryIndex == EquityPositionList[i].SWIndustryIndex); }); if (idxIndustry >= 0) { EquityIndustryList[idxIndustry].PortfolioWeight += EquityPositionList[i].Pctof_Portfolio; EquityIndustryList[idxIndustry].HoldingMarketValue += EquityPositionList[i].HoldingMarketValue; } else { EquityIndustry industry = new EquityIndustry(); industry.SWIndustryName = EquityPositionList[i].SWIndustryName; industry.SWIndustryIndex = EquityPositionList[i].SWIndustryIndex; industry.PortfolioWeight = EquityPositionList[i].Pctof_Portfolio; industry.HoldingMarketValue = EquityPositionList[i].HoldingMarketValue; EquityIndustryList.Add(industry); } } } #endregion //========================== //Prices //========================== #region Update Prices if (priceList != null && priceList.Count > 0) { int idxPrice = priceList.FindIndex(delegate(EquityPrice p) { return(p.WindCode == windcode && p.TradeDate == this.ReportDate); }); if (idxPrice >= 0) { EquityPositionList[i].TradingVolume = priceList[idxPrice].Volume; EquityPositionList[i].Price.AdjustedClose = priceList[idxPrice].AdjustedClose; EquityPositionList[i].Price.Close = priceList[idxPrice].Close; EquityPositionList[i].Price.AdjustedAverage = priceList[idxPrice].AdjustedAverage; EquityPositionList[i].Price.Average = priceList[idxPrice].Average; if (EquityPositionList[i].TradingVolume > 0) { EquityPositionList[i].LiquidityCycle = EquityPositionList[i].HoldingQuantity / EquityPositionList[i].TradingVolume; } //调整特殊值 if (EquityPositionList[i].Price.Close == 0) { EquityPositionList[i].Price.Close = priceList[idxPrice].PreClose; } if (EquityPositionList[i].Price.Average == 0) { EquityPositionList[i].Price.Average = EquityPositionList[i].Price.Close; } if (EquityPositionList[i].Price.AdjustedAverage == 0) { EquityPositionList[i].Price.AdjustedAverage = EquityPositionList[i].Price.AdjustedClose; } } } #endregion //========================== //Capital //========================== if (capitalList != null && capitalList.Count > 0) { int idxCapital = capitalList.FindIndex(delegate(AssetPosition p) { return(p.Code == windcode); }); if (idxCapital >= 0) { EquityPositionList[i].FreefloatCapital = capitalList[idxCapital].FreefloatCapital; } } } #endregion }
public void BuildBenchmarkComponents(List <AssetPosition> indexComponentWeightList, List <EquityPrice> equityPriceList) { _BenchmarkPositionList = indexComponentWeightList; //计算各成分股回报 foreach (AssetPosition p in _BenchmarkPositionList) { try { //计算个股回报 double pxStart = 0, pxEnd = 0; //选择日期范围并降序排列(为了消除非交易日无数据的影响) List <EquityPrice> selectedPriceList = equityPriceList.FindAll(delegate(EquityPrice e) { return(e.WindCode == p.Code && e.TradeDate >= this.ReportStartDate && e.TradeDate <= this.ReportEndDate); }); selectedPriceList.Sort(); if (selectedPriceList.Count == 0) { pxStart = 0; } else { pxStart = selectedPriceList[selectedPriceList.Count - 1].AdjustedClose; //期初复权价 //不用担心停牌,停牌会有前期价格 pxEnd = selectedPriceList[0].AdjustedClose; //期末复权价 } if (pxStart == 0) { p.TotalReturnPct = 0; } else { p.TotalReturnPct = (pxEnd / pxStart - 1); } //计算行业权重及行业平均回报 int industryIndex = _BenchmarkIndustryList.FindIndex(delegate(EquityIndustry ind) { return(ind.SWIndustryIndex == p.SWIndustryIndex); }); if (industryIndex < 0) { EquityIndustry newInd = new EquityIndustry(); newInd.SWIndustryName = p.SWIndustryName; newInd.SWIndustryIndex = p.SWIndustryIndex; newInd.PortfolioWeight = p.Pctof_Portfolio; _BenchmarkIndustryList.Add(newInd); } else { _BenchmarkIndustryList[industryIndex].PortfolioWeight += p.Pctof_Portfolio; } } catch (Exception ex) { throw ex; } } //计算行业回报 foreach (AssetPosition p in _BenchmarkPositionList) { int industryIndex = _BenchmarkIndustryList.FindIndex(delegate(EquityIndustry ind) { return(ind.SWIndustryIndex == p.SWIndustryIndex); }); if (industryIndex >= 0) { _BenchmarkIndustryList[industryIndex].ReturnPct += p.Pctof_Portfolio / _BenchmarkIndustryList[industryIndex].PortfolioWeight * p.TotalReturnPct; } } }