Example #1
0
        public virtual void Adjust()
        {
            //========================================
            //1)按交易日补齐数据并作复权调整
            //========================================
            #region  交易日补齐数据并作复权调整
            if (this.TradingDates.Count == 0)
            {
                DataManager.GetDataLoader().LoadTradingDate(this);
            }

            if (TradingDates == null || TradingDates.Count == 0 || this.OriginalTimeSeries == null || this.OriginalTimeSeries.Count == 0)
            {
                MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_GE2, "");
                return;
            }

            if (this.AdjustedTimeSeries == null)
            {
                this.AdjustedTimeSeries = new List <ATimeItem>();
            }
            else
            {
                this.AdjustedTimeSeries.Clear();
            }

            //找到缺失的交易日并补齐数据
            int iOriginalCnt = 0;
            for (int iTradeDayCount = 0; iTradeDayCount < this.TradingDates.Count;)
            {
                DateTime tradeday = this.TradingDates[iTradeDayCount];

                if (iOriginalCnt < this.OriginalTimeSeries.Count)
                {
                    ATimeItem item = this.OriginalTimeSeries[iOriginalCnt];

                    //判断是否是样本外数据
                    if (item.TradeDate < this.TimeSeriesStart)
                    {
                        item.IsOutsideSamplePeriod = true;
                    }
                    else
                    {
                        InsideSampleLength++;
                    }

                    if (tradeday >= item.TradeDate)
                    {
                        //交易日不在净值数据中则加入前一交易日的数据
                        ATimeItem newItem = (ATimeItem)item.Clone();
                        newItem.TradeDate = tradeday;

                        if (tradeday == item.TradeDate)
                        {
                            newItem.IsTrading = true;
                        }
                        else
                        {
                            newItem.IsTrading = false;
                        }

                        //复权调整
                        newItem.Adjust();

                        this.AdjustedTimeSeries.Add(newItem);

                        if (tradeday == item.TradeDate)
                        {
                            iOriginalCnt++;
                        }

                        //计数器加1
                        iTradeDayCount++;
                    }
                    else
                    {
                        iOriginalCnt++;
                    }
                }
                else
                {
                    //OriginalTimeSeries更早交易日的数据
                    break;
                }
            }
            #endregion

            //========================================
            //2)计算涨跌幅数据
            //========================================
            this.Calculate();
        }
Example #2
0
        public override void LoadMutualFundInfo(MutualFund f)
        {
            try
            {
                //读取数据库
                this.LoadMutualFundInfo();

                //更新数据
                DataRow[] rows = _FundInfo.Tables[0].Select("SYMBOL='" + f.Code + "'");
                if (rows.Length >= 1)
                {
                    f.DataSource          = this.DataSource;
                    f.Category.DataSource = this.DataSource;

                    DataRow row = rows[0];
                    f.Name         = row[C_ColName_Name].ToString();
                    f.ListedDate   = DataManager.ConvertToDate(row[C_ColName_ListedDate]);
                    f.DelistedDate = DataManager.ConvertToDate(row[C_ColName_DelistedDate]);
                    f.Category.SetupCategory(row[C_ColName_GSFundType].ToString(), 3);

                    if (row[C_ColName_ParentCode] == DBNull.Value)
                    {
                        //非分级基金
                        f.IsStructured = false;
                        f.Category.StructureCategory = FundStructureCategory.Parent;
                    }
                    else
                    {
                        //分级基金
                        f.IsStructured   = true;
                        f.ParentFundCode = row[C_ColName_ParentCode].ToString();

                        if (row[C_ColName_ParentCode].ToString() == row[C_ColName_Code].ToString())
                        {
                            f.Category.StructureCategory = FundStructureCategory.Parent;

                            //查找子基金
                            string  sql = @"Select SYMBOL From CURFSCODE WHERE Symbol_Comp = '" + f.Code + "' AND Symbol <> Symbol_Comp";
                            DataSet ds  = base.DBInstance.ExecuteSQL(sql);

                            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                            {
                                MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_MF8, f.Code);
                            }
                            else
                            {
                                if (f.SubFundCodes == null)
                                {
                                    f.SubFundCodes = new List <string>();
                                }

                                foreach (DataRow rowsub in ds.Tables[0].Rows)
                                {
                                    string code = rowsub[C_ColName_Code].ToString();
                                    f.SubFundCodes.Add(code);
                                }
                            }
                        }
                        else
                        {
                            f.Category.StructureCategory = FundStructureCategory.Child;
                        }
                    }
                }
                else
                {
                    MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_MF5, f.Code);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }