示例#1
0
        private void updateFundPrice(DataSet ds, SeriesFundPrice pxs)
        {
            DataRow[] rows = ds.Tables[0].Select("SYMBOL='" + pxs.Code + "'");
            if (rows.Length > 0)
            {
                //基本信息
                pxs.DataSource = this.DataSource;
                pxs.OriginalTimeSeries.Clear();

                foreach (DataRow row in rows)
                {
                    ExchangeTradingPrice px = new ExchangeTradingPrice();
                    px.TradeDate = DataManager.ConvertToDate(row[C_ColName_TradeDate]);
                    px.PreClose  = DataManager.ConvertToDouble(row[C_ColName_PreClose]);
                    px.Close     = DataManager.ConvertToDouble(row[C_ColName_Close]);
                    px.High      = DataManager.ConvertToDouble(row[C_ColName_High]);
                    px.Low       = DataManager.ConvertToDouble(row[C_ColName_Low]);
                    px.Open      = DataManager.ConvertToDouble(row[C_ColName_Open]);
                    px.Volume    = DataManager.ConvertToDouble(row[C_ColName_Volume]);
                    px.Amount    = DataManager.ConvertToDouble(row[C_ColName_Amount]);
                    px.Average   = (px.Volume == 0) ? 0 : px.Amount / px.Volume;

                    //判断停牌
                    if (px.Close == 0)
                    {
                        px.IsTrading = false;
                        px.Close     = px.PreClose;
                        px.Open      = px.PreClose;
                        px.High      = px.PreClose;
                        px.Low       = px.PreClose;
                    }

                    //复权系数
                    double adjustedClose = DataManager.ConvertToDouble(row[C_ColName_AdjustedClose]);
                    px.AdjustCoefficient = (px.Close == 0 || adjustedClose == 0) ? 1 : adjustedClose / px.Close;
                    pxs.OriginalTimeSeries.Add(px);
                }

                //复权并计算涨跌幅
                pxs.Adjust();
            }
            else
            {
                MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_MF3, pxs.Code);
            }
        }
示例#2
0
        public override void Calculate()
        {
            //====================
            //计算涨跌幅: 时间序列全部降序排列
            //====================
            if (this.AdjustedTimeSeries == null || this.AdjustedTimeSeries.Count == 0)
            {
                return;
            }

            double   px0 = 1, px1 = 1;
            DateTime dt0 = DateTime.Today, dt1 = DateTime.Today;

            for (int i = 0; i < this.AdjustedTimeSeries.Count; i++)
            {
                ExchangeTradingPrice item = (ExchangeTradingPrice)this.AdjustedTimeSeries[i];
                if ((i + 1) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay1 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 1]).Close - 1;
                }
                if ((i + 2) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay2 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 2]).Close - 1;
                }
                if ((i + 3) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay3 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 3]).Close - 1;
                }
                if ((i + 4) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay4 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 4]).Close - 1;
                }
                if ((i + 5) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay5 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 5]).Close - 1;
                }
                if ((i + 10) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay10 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 10]).Close - 1;
                }
                if ((i + 20) < this.AdjustedTimeSeries.Count)
                {
                    item.UpAndDown.KLineDay20 = item.Close / ((ExchangeTradingPrice)this.AdjustedTimeSeries[i + 20]).Close - 1;
                }

                //期末值
                if (i == 0)
                {
                    px1 = item.Close;
                    dt1 = item.TradeDate;
                }
                //期初值
                if (item.TradeDate >= base.TimeSeriesStart)
                {
                    px0 = item.Close;
                    dt0 = item.TradeDate;
                }
            }

            //持有期收益率
            base.HoldingPeriodInfo   = px0.ToString("N4") + "[" + dt0.ToString("yyyy-MM-dd") + "]-" + px1.ToString("N4") + "[" + dt1.ToString("yyyy-MM-dd") + "]";
            base.HoldingPeriodReturn = px1 / px0 - 1;
        }