/// <summary>
        /// 根据股票数据或者期货数据整理得到的数组
        /// </summary>
        /// <param name="data">DataTable格式的股票或者期货数组</param>
        /// <returns>List格式的数据</returns>
        public stockFormat[] GetStockArray(DataTable data)
        {
            stockFormat[] stockArray = new stockFormat[28802];
            int           lastTime   = 0;

            foreach (DataRow row in data.Rows)
            {
                stockFormat stock = new stockFormat();
                stock.ask  = new stockPrice[5];
                stock.bid  = new stockPrice[5];
                stock.code = (int)row["Code"];
                stock.date = (int)row["Date"];
                //剔除非交易时间的交易数据。
                int now = (int)row["Time"] + (int)row["Tick"] * 500;
                if (now < 93000000 || (now > 113000000 && now < 130000000) || (now > 150000000) || (int)row["Tick"] >= 2)
                {
                    continue;
                }
                if (now <= lastTime)
                {
                    continue;
                }
                stock.time      = now;
                lastTime        = now;
                stock.lastPrice = (double)row["LastPrice"];
                for (int i = 1; i <= 5; i++)
                {
                    stock.ask[i - 1] = new stockPrice((double)row["Ask" + i.ToString()], (double)row["Askv" + i.ToString()]);
                    stock.bid[i - 1] = new stockPrice((double)row["Bid" + i.ToString()], (double)row["Bidv" + i.ToString()]);
                }
                stock.preClose = (double)row["PreClose"];
                stockArray[TradeDays.TimeToIndex(now)] = stock;
            }
            return(stockArray);
        }
Exemple #2
0
        /// <summary>
        /// 构造函数。获取所有的期权合约代码的信息。
        /// </summary>
        /// <param name="dataBase">数据库名称</param>
        /// <param name="tableName">期权合约代码</param>
        /// <param name="connectionString">连接字符串</param>
        public OptionCodeInformation(string dataBase, string tableName, string connectionString)
        {
            DataApplication myDataBase = new DataApplication(dataBase, connectionString);

            contractData = myDataBase.GetDataTable(tableName);
            CodeList     = myDataBase.GetOptionInfoList(contractData);
            TradeDays myTradeDays = new TradeDays(20150209);
        }
Exemple #3
0
        /// <summary>
        /// 根据期权合约代码和今日日期,给出期权的到期天数。
        /// </summary>
        /// <param name="optionCode">期权合约代码</param>
        /// <param name="date">今日日期</param>
        /// <returns>合约到期天数</returns>
        public int GetOptionDuration(int optionCode, int date)
        {
            optionInfo contract = GetContractInfo(optionCode);
            int        duration = -1;

            if (contract.optionCode > 0)
            {
                duration = TradeDays.GetTimeSpan(date, contract.endDate);
            }
            return(duration);
        }
Exemple #4
0
 /// <summary>
 /// 获得期权盘口价格变动的函数。
 /// </summary>
 /// <returns>盘口价格的变动</returns>
 public optionPositionChange[] GetPositionChange()
 {
     optionPositionChange[] changeArray = new optionPositionChange[28802];
     for (int i = 1; i < optionList.Count; i++)
     {
         optionFormat lastPosition = optionList[i - 1];
         optionFormat thisPosition = optionList[i];
         changeArray[TradeDays.TimeToIndex(thisPosition.time)] = getChange(lastPosition, thisPosition);
     }
     return(changeArray);
 }
Exemple #5
0
        /// <summary>
        /// 根据当日日期和strike的区间给出合约列表。
        /// </summary>
        /// <param name="minStrike">最低行权价</param>
        /// <param name="maxStrike">最高行权价</param>
        /// <param name="date">今日日期</param>
        /// <returns>期权合约代码的列表</returns>
        public List <int> GetCodeListByStrike(double minStrike, double maxStrike, int date)
        {
            List <int> codeList      = new List <int>();
            int        frontDuration = GetFrontDuration(date);

            foreach (var item in CodeList)
            {
                optionInfo contract = item.Value;
                if (contract.startDate <= date && contract.endDate >= date && TradeDays.GetTimeSpan(date, contract.endDate) == frontDuration && contract.strike >= minStrike && contract.strike <= maxStrike)
                {
                    codeList.Add(contract.optionCode);
                }
            }
            return(codeList);
        }
Exemple #6
0
 /// <summary>
 /// 构造函数。存储基本的信息。
 /// </summary>
 /// <param name="initialCapital">初始资金</param>
 /// <param name="startDate">开始时间</param>
 /// <param name="endDate">结束时间</param>
 /// <param name="recordStr">记录字符</param>
 public RBDaily(double initialCapital, int startDate, int endDate, string recordStr)
 {
     if (endDate < startDate)
     {
         endDate = startDate;
     }
     this.startDate  = startDate;
     this.endDate    = endDate;
     myTradeDays     = new TradeDays(startDate, endDate);
     recordTableName = recordStr + DateTime.Now.ToString("yyyyMMddhhmm");
     recordCSV       = recordStr + DateTime.Now.ToString("yyyyMMddhhmm") + ".csv";
     mainContract    = GetMainContract("RB", "SHF", startDate, endDate);
     //DocumentApplication.RecordCsv(recordCSV, "日期", "总资金", "可用资金", "期权保证金", "期货保证金", "期权现值", "总金额Delta", "期权金额Delta", "期货金额Delta", "日内开仓量", "当日持仓量");
     //判断主力合约的函数
 }
Exemple #7
0
        /// <summary>
        /// 给出当日近月合约到期天数。
        /// </summary>
        /// <param name="date">今日日期</param>
        /// <returns>近月合约到期天数</returns>
        public int GetFrontDuration(int date)
        {
            int frontDuration = 999;

            foreach (var item in CodeList)
            {
                optionInfo contract = item.Value;
                if (contract.startDate <= date && contract.endDate >= date)
                {
                    int duration = TradeDays.GetTimeSpan(date, contract.endDate);
                    if (duration < frontDuration)
                    {
                        frontDuration = duration;
                    }
                }
            }
            return(frontDuration);
        }
        /// <summary>
        /// 读取50etf前收盘数据的函数
        /// </summary>
        /// <param name="tableName">50etf表</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        public SortedDictionary <int, double> GetETFPreClosePrice(string tableName, int startDate = 0, int endDate = 0)
        {
            DataTable myDataTable = new DataTable();
            SortedDictionary <int, double> etfClose = new SortedDictionary <int, double>();
            string commandString;

            if (startDate == 0)
            {
                commandString = "select distinct [PreClose],[date] from " + tableName + " order by [Date]";
            }
            else
            {
                if (endDate == 0)
                {
                    endDate = startDate;
                }
                endDate       = TradeDays.GetNextTradeDay(endDate);
                commandString = "select distinct [PreClose],[date] from " + tableName + "  where [Date]>=" + startDate.ToString() + " and [Date]<=" + endDate.ToString() + " order by [Date]";
            }
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    using (SqlCommand command = conn.CreateCommand())
                    {
                        command.CommandText = commandString;
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                        {
                            adapter.Fill(myDataTable);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            foreach (DataRow row in myDataTable.Rows)
            {
                etfClose.Add((int)row["Date"], (double)row["PreClose"]);
            }
            return(etfClose);
        }