public void ComputeVol(int date, int[] time) { if (date < 20150416) { IHList = null;//2015年4月16之前IH不存在。 } if (date < 20150209) { optionList = null;//2015年2月9日之前50ETF期权不存在。 } OptionInformation myOption = new OptionInformation(date); optionList = myOption.GetOptionCodeByDate(date); optionListInt = myOption.GetOptionNameByDate(date); GetDataDaily myData = new GetDataDaily(date, IHList, optionList); foreach (var time0 in time) { this.time = time0; int index = TradeDays.TimeToIndex(time0); ImpvCurveOfCallMid = new SortedDictionary <double, SortedDictionary <double, double> >(); ImpvCurveOfPutMid = new SortedDictionary <double, SortedDictionary <double, double> >(); ComputeVolDaily(myData, index); string CsvName = "VolatilitySurfaceCallMid" + date.ToString() + time0.ToString() + ".csv"; SaveVolToCsv(CsvName, "call", "mid", ImpvCurveOfCallMid); CsvName = "VolatilitySurfacePutMid" + date.ToString() + time0.ToString() + ".csv"; SaveVolToCsv(CsvName, "put", "mid", ImpvCurveOfPutMid); } }
/// <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); }