Exemple #1
0
        private void buildBenchmarkIndex()
        {
            if (_BenchmarkDefList.Count == 0)
            {
                throw new Exception(DBConsts.C_ErrMsg_NoBenchmark);
            }

            if (_BenchmarkDefList.Count == 1)
            {
                _BenchmarkIndexList = _BenchmarkDefList[0].BenchmarkPriceList;
            }

            int  dayDiff = 0;
            bool flg     = false;

            while (BenchmarkStartDate.AddDays(dayDiff) <= BenchmarkEndDate)
            {
                flg = false;
                DateTime currDate = BenchmarkStartDate.AddDays(dayDiff);

                EquityPrice indexPrice = new EquityPrice();
                indexPrice.TradeDate = currDate;

                foreach (BenchmarkDef bmi in _BenchmarkDefList)
                {
                    if (bmi.ConstRate > 0)
                    { //常数: 基期=1
                        indexPrice.Close += (1 + bmi.ConstRate / 365 * dayDiff) * bmi.Weight;
                    }
                    else
                    {//指数
                        int idx = bmi.BenchmarkPriceList.FindIndex(delegate(EquityPrice e) { return(e.TradeDate == currDate); });
                        if (idx >= 0)
                        {
                            indexPrice.Close += bmi.BenchmarkPriceList[idx].Close * bmi.Weight;
                            flg = true;
                        }
                    }
                }

                if (flg)    //去除非交易作日
                {
                    _BenchmarkIndexList.Add(indexPrice);
                }

                dayDiff++;
            }
        }
Exemple #2
0
 public int CompareTo(object obj)
 {
     try
     {
         //Order by TradeDate Desc
         EquityPrice p = (EquityPrice)obj;
         if (this.TradeDate > p.TradeDate)
         {
             return(-1);
         }
         else
         {
             return(1);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
        public List <EquityPrice> GetPriceList(DataTable dtPriceInfo)
        {
            //==================================================================================================
            //Wind字段名
            //s_info_windcode, trade_dt, s_dq_close, s_dq_adjclose, s_dq_adjfactor, s_dq_volume(手), s_dq_amount(千元)
            //股票专有
            //s_dq_avgprice
            //==================================================================================================
            try
            {
                List <EquityPrice> priceList = new List <EquityPrice>();

                if (dtPriceInfo != null && dtPriceInfo.Rows.Count > 0)
                {
                    foreach (DataRow oRow in dtPriceInfo.Rows)
                    {
                        EquityPrice px = new EquityPrice();

                        foreach (DataColumn oCol in dtPriceInfo.Columns)
                        {
                            switch (oCol.ColumnName.ToLower())
                            {
                            case DBConsts.C_Mkt_ColumnName_WindCode:
                                px.WindCode = oRow[oCol].ToString();
                                break;

                            case DBConsts.C_Mkt_ColumnName_Trade_Date:
                                string strDate = oRow[oCol].ToString();
                                px.TradeDate = new DateTime(
                                    Convert.ToInt16(strDate.Substring(0, 4))
                                    , Convert.ToInt16(strDate.Substring(4, 2))
                                    , Convert.ToInt16(strDate.Substring(6, 2))
                                    );
                                break;

                            case DBConsts.C_Mkt_ColumnName_PreClose:
                                px.PreClose = Convert.ToDouble(oRow[oCol]);
                                break;

                            case DBConsts.C_Mkt_ColumnName_Close:
                                px.Close = Convert.ToDouble(oRow[oCol]);
                                break;

                            case DBConsts.C_Mkt_ColumnName_Volume:
                                px.Volume = Convert.ToDouble(oRow[oCol]) * 100;     //手->股
                                break;

                            case DBConsts.C_Mkt_ColumnName_Amount:
                                px.Amount = Convert.ToDouble(oRow[oCol]) * 1000;     //千元->元
                                break;

                            case DBConsts.C_Mkt_ColumnName_AdjClose:
                                if (oRow[oCol] != DBNull.Value)
                                {
                                    px.AdjustedClose = Convert.ToDouble(oRow[oCol]);
                                }
                                break;

                            case DBConsts.C_Mkt_ColumnName_AdjFactor:
                                if (oRow[oCol] != DBNull.Value)
                                {
                                    px.AdjustedFactor = Convert.ToDouble(oRow[oCol]);
                                }
                                break;

                            case DBConsts.C_Mkt_ColumnName_AvgPrice:
                                if (oRow[oCol] != DBNull.Value)
                                {
                                    px.Average = Convert.ToDouble(oRow[oCol]);
                                }
                                break;

                            default:
                                break;
                            }
                        }

                        px.AdjustedAverage  = px.Average * px.AdjustedFactor;
                        px.AdjustedPreClose = px.Close * px.AdjustedFactor;
                        priceList.Add(px);
                    }
                }

                return(priceList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }