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> /// 计算隐含波动率 /// </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); } }