예제 #1
0
 /// <summary>
 /// 将datatable转化为数组格式
 /// </summary>
 /// <param name="str">交易代码</param>
 /// <param name="dt">数据</param>
 /// <returns>数组形式数据</returns>
 public levelOne[] DataTable2Array(string str, DataTable dt)
 {
     levelOne[] dtArr = new levelOne[28802];
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         levelOne data0 = new levelOne();
         data0.code = str;
         int time  = Convert.ToInt32(dt.Rows[i]["ttime"]);
         int index = TradeDays.TimeToIndex(time);
         if (index < 0 || index > 28801)
         {
             continue;
         }
         data0.time   = time;
         data0.last   = Convert.ToDouble(dt.Rows[i]["cp"]);
         data0.ask    = Convert.ToDouble(dt.Rows[i]["S1"]);
         data0.askv   = Convert.ToDouble(dt.Rows[i]["SV1"]);
         data0.bid    = Convert.ToDouble(dt.Rows[i]["B1"]);
         data0.bidv   = Convert.ToDouble(dt.Rows[i]["BV1"]);
         dtArr[index] = data0;
     }
     for (int i = 1; i < 28802; i++)
     {
         if (dtArr[i].last == 0)
         {
             dtArr[i] = new levelOne(dtArr[i - 1].code, dtArr[i - 1].time, dtArr[i - 1].last, dtArr[i - 1].ask, dtArr[i - 1].askv, dtArr[i - 1].bid, dtArr[i - 1].bidv);
         }
     }
     return(dtArr);
 }
예제 #2
0
 /// <summary>
 /// 计算隐含波动率及其他希腊值的类。
 /// </summary>
 /// <param name="option">期权类型</param>
 /// <param name="optionData">期权数据</param>
 /// <param name="etfData">etf数据</param>
 /// <param name="duration">到期时间</param>
 public Impv(optionFormat option, levelOne optionData, levelOne etfData, double duration)
 {
     this.option     = option;
     this.optionData = optionData;
     this.etfData    = etfData;
     this.duration   = duration;
 }
예제 #3
0
        /// <summary>
        /// 计算隐含波动率
        /// </summary>
        /// <param name="myData">数据</param>
        /// <param name="index">时间下标</param>
        public void ComputeVolDaily(GetDataDaily myData, int index)
        {
            levelOne etfData = myData.dataDaily["510050.SH"][index];

            foreach (int code in optionListInt)
            {
                string       codeStr    = code.ToString() + ".SH";
                optionFormat option     = OptionInformation.myOptionList[code];
                levelOne     optionData = myData.dataDaily[codeStr][index];
                double       duration   = TradeDays.GetTimeSpan(date, option.endDate);
                Impv         vol        = new Impv(option, optionData, etfData, duration);
                double       sigma      = vol.computeVol();
                GetCurve(option.strike, option.optionType, duration, sigma);
            }
        }