private ConvertibleBondDailyInfo getBondDailyInfo(ConvertibleBondInfo info, DateTime date) { ConvertibleBondDailyInfo data = new ConvertibleBondDailyInfo(); var tempDataTable = windReader.GetDailyDataTable(info.code, "clause_conversion2_swapshareprice,underlyingcode,clause_conversion_2_swapsharestartdate,clause_conversion_2_swapshareenddate", info.startDate, date); List <ConvertibleBondDailyInfo> bondDaily = new List <ConvertibleBondDailyInfo>(); foreach (DataRow dt in tempDataTable.Rows) { ConvertibleBondDailyInfo bondDailyInfoNow = new ConvertibleBondDailyInfo(); bondDailyInfoNow.code = info.code; bondDailyInfoNow.name = info.name; bondDailyInfoNow.startDate = info.startDate; bondDailyInfoNow.endDate = info.endDate; bondDailyInfoNow.stockCode = info.stockCode; bondDailyInfoNow.conversionPrice = Convert.ToDouble(dt["clause_conversion2_swapshareprice"]); //bondDailyInfoNow.forceConvertDate = Convert.ToDateTime(dt["clause_conversion_2_forceconvertdate"]); bondDailyInfoNow.conversionStartDate = Convert.ToDateTime(dt["clause_conversion_2_swapsharestartdate"]); bondDailyInfoNow.conversionEndDate = Convert.ToDateTime(dt["clause_conversion_2_swapshareenddate"]); bondDailyInfoNow.date = Convert.ToDateTime(dt["datetime"]); bondDaily.Add(bondDailyInfoNow); } for (int i = bondDaily.Count() - 1; i >= 0; i--) { if (bondDaily[i].conversionPrice != 0) { data = bondDaily[i]; break; } } return(data); }
private double getEstimateOptionPrice(DateTime today, ConvertibleBondDailyInfo bondInfo, double volatility, double stockPrice) { double option = 0; int days = DateTimeExtension.DateUtils.GetSpanOfTradeDays(today, bondInfo.endDate); double strike = bondInfo.conversionPrice; double duration = (double)days / 252.0; option = ImpliedVolatilityExtension.ComputeOptionPrice(strike, duration, 0.04, 0, "认购", volatility, stockPrice); return(option); }
private ConvertibleBondDailyInfo getBondDailyInfo(DateTime date, string code) { ConvertibleBondDailyInfo info = new ConvertibleBondDailyInfo(); if (bondDailyInfo.ContainsKey(code) == false) { return(info); } var data = bondDailyInfo[code]; foreach (var item in data) { info = item; if (item.date.Date == date.Date) { break; } } return(info); }
private void dataPrepare(DateTime startDate, DateTime endDate) { //获取交易日信息 this.tradedays = dateRepo.GetStockTransactionDate(startDate, endDate); List <DateTime> ceilDate = new List <DateTime>(); string bondCode; string underlyingCode; //获取可转债信息 this.bondInfo = GetConvertibleBondInfos(endDate); //获取日线数据 try { foreach (var info in bondInfo) { underlyingCode = info.stockCode; DateTime startTime = startDate; DateTime endTime = endDate; if (startTime < info.startDate) { startTime = info.startDate; } if (endTime > info.endDate) { endTime = info.endDate; } if (dailyData.ContainsKey(underlyingCode) == false) { var underlyingData = stockDailyRepo.GetStockTransactionWithRedis(underlyingCode, startTime.AddDays(-10), endTime); dailyData.Add(underlyingCode, underlyingData); endTime = DateTimeExtension.DateUtils.PreviousTradeDay(info.endDate, 7); if (endTime > endDate.Date) { endTime = endDate.Date; } if (startDate > endTime) { startDate = endTime; } var bondData = stockDailyRepo.GetStockTransactionWithRedis(info.code, info.startDate, endTime); dailyData.Add(info.code, bondData); if (info.startDate > endTime) { continue; } var tempDataTable = windReader.GetDailyDataTable(info.code, "clause_conversion2_swapshareprice,underlyingcode,clause_conversion_2_swapsharestartdate,clause_conversion_2_swapshareenddate", info.startDate, endTime); List <ConvertibleBondDailyInfo> bondDaily = new List <ConvertibleBondDailyInfo>(); foreach (DataRow dt in tempDataTable.Rows) { ConvertibleBondDailyInfo bondDailyInfoNow = new ConvertibleBondDailyInfo(); bondDailyInfoNow.code = info.code; bondDailyInfoNow.name = info.name; bondDailyInfoNow.startDate = info.startDate; bondDailyInfoNow.endDate = info.endDate; bondDailyInfoNow.stockCode = info.stockCode; bondDailyInfoNow.conversionPrice = Convert.ToDouble(dt["clause_conversion2_swapshareprice"]); //bondDailyInfoNow.forceConvertDate = Convert.ToDateTime(dt["clause_conversion_2_forceconvertdate"]); bondDailyInfoNow.conversionStartDate = Convert.ToDateTime(dt["clause_conversion_2_swapsharestartdate"]); bondDailyInfoNow.conversionEndDate = Convert.ToDateTime(dt["clause_conversion_2_swapshareenddate"]); bondDailyInfoNow.date = Convert.ToDateTime(dt["datetime"]); bondDaily.Add(bondDailyInfoNow); } bondDailyInfo.Add(info.code, bondDaily); } } } catch (Exception e) { Console.WriteLine(e.Message); } int num = 0; foreach (var item in dailyData) { var data = item.Value; var code = item.Key; num = num + 1; Console.WriteLine(num); for (int i = 1; i < data.Count(); i++) { if (data[i] == null || data[i].DateTime.Date < startDate) { continue; } DateTime day = data[i].DateTime.Date; //获取其对应的可转债 bondCode = getConvetibleCodeByStockCode(code, day, bondInfo); //判断是否涨停 var dataToday = data[i]; var dataYesterday = data[i - 1]; double price = Math.Round(dataYesterday.Close * dataYesterday.AdjFactor / dataToday.AdjFactor * 1.1, 2); //获取日内数据 try { if (data[i].High >= 0.99 * price && bondCode != "") { //获取分钟数据 //var data1 = stockMinutelyRepo.GetStockTransactionWithRedis(bondCode, day, day); //var data2 = stockMinutelyRepo.GetStockTransactionWithRedis(code, day, day); //if (minuteData.ContainsKey(data[i].DateTime) == true) //{ // minuteData[data[i].DateTime].Add(bondCode, data1); // minuteData[data[i].DateTime].Add(code, data2); //} //else //{ // Dictionary<string, List<StockTransaction>> dataNow = new Dictionary<string, List<StockTransaction>>(); // dataNow.Add(bondCode, data1); // dataNow.Add(code, data2); // minuteData.Add(day, dataNow); //} //获取tick数据 DateTime startTime = day.Date + new TimeSpan(9, 30, 0); DateTime endTime = day.Date + new TimeSpan(15, 0, 0); var data3 = tickRepo.GetStockTransaction(bondCode, startTime, endTime); var data4 = tickRepo.GetStockTransaction(code, startTime, endTime); if (tickData.ContainsKey(day.Date) == true) { tickData[day.Date].Add(bondCode, data3); tickData[day.Date].Add(code, data4); } else { Dictionary <string, List <StockTickTransaction> > dataNow = new Dictionary <string, List <StockTickTransaction> >(); dataNow.Add(bondCode, data3); dataNow.Add(code, data4); tickData.Add(day.Date, dataNow); } } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("code:{0} date:{1} No data!", bondCode, day); } } } }