public void LoadData(DataTable dtGZB, PortfolioDataAdapterType type, DateTime start, DateTime end, string benchmarkcode) { //加载数据 try { //纠正时间 if (end < start) { DateTime tmp = end; end = start; start = tmp; } if (end > DateTime.Today.AddDays(-1)) { end = DateTime.Today.AddDays(-1); } //读取估值表 IPortfolioDataAdapter adapter = PortfolioDataAdaptorFactory.GetAdapter(type); this.PortfGroup = adapter.BuildPortfolios(dtGZB, start, end); this.StartDate = this.PortfGroup.ExchangeTradingDays[0]; this.EndDate = this.PortfGroup.ExchangeTradingDays[this.PortfGroup.ExchangeTradingDays.Count - 1]; //计算收益率和持仓 if (PortfGroup.IsDataComplete() && PortfGroup.Portfolios.Count > 1) { this.Calculate(); } else { throw new Exception(Message.C_Msg_PD3); } //无需比较基准 if (benchmarkcode == null || benchmarkcode.Length == 0) { return; } //建立比较基准并计算收益率 this.Benchmark = new Index(benchmarkcode); this.Benchmark.SetDatePeriod(start, end); this.Benchmark.LoadData(DataInfoType.IndexComponents); this.Benchmark.LoadData(DataInfoType.HistoryTradePrice); this.Benchmark.ComponentsCalculate(); } catch (Exception ex) { throw ex; } }
public virtual void BuildPortfolio(DataTable dtGZB, PortfolioDataAdapterType type, DateTime tradeday) { try { IPortfolioDataAdapter adapter = PortfolioDataAdaptorFactory.GetAdapter(type); PortfolioGroup group = adapter.BuildPortfolios(dtGZB, tradeday, tradeday); this.SecurityPortfolio = group.Portfolios[0]; //仅需要最新一期的持仓数据 } catch (Exception ex) { throw ex; } }