예제 #1
0
        public object Clone()
        {
            object    obj  = this.MemberwiseClone();
            ATimeItem item = (ATimeItem)obj;

            item.UpAndDown = (PriceUpAndDown)this.UpAndDown.Clone();
            return(item);
        }
예제 #2
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();
        }