protected override List <OptionMinute> readFromWind(string code, DateTime date) { WindAPI w = Platforms.GetWindAPI(); DateTime date1 = date.Date, date2 = date.Date.AddDays(1); WindData wd = w.wsi(code, "open,high,low,close,volume,amt,oi", date1, date2, "periodstart=09:30:00;periodend=15:00:00;Fill=Previous"); int len = wd.timeList.Length; int fieldLen = wd.fieldList.Length; var items = new List <OptionMinute>(len); if (wd.data is double[]) { double[] dataList = (double[])wd.data; DateTime[] timeList = wd.timeList; for (int k = 0; k < len; k++) { items.Add(new OptionMinute { time = timeList[k], open = (double)dataList[k * fieldLen + 0], high = (double)dataList[k * fieldLen + 1], low = (double)dataList[k * fieldLen + 2], close = (double)dataList[k * fieldLen + 3], volume = (double)dataList[k * fieldLen + 4], amount = (double)dataList[k * fieldLen + 5], openInterest = (double)dataList[k * fieldLen + 6] }); } } return(items); }
public static void test1() { WindAPI w = new WindAPI(); w.start(); WindData wd = w.wsi("510050.SH", "open,high,low,close", "2016-07-26 09:00:00", "2016-07-26 14:56:12", ""); }
private List <FuturesMinute> readByParameters(string code, DateTime date, string paramters) { WindAPI w = Platforms.GetWindAPI(); DateTime date2 = new DateTime(date.Year, date.Month, date.Day, 15, 0, 0); DateTime date1 = DateUtils.PreviousTradeDay(date).AddHours(17); //获取日盘数据 WindData wd = w.wsi(code, "open,high,low,close,volume,amt,oi", date1, date2, paramters); int len = wd.timeList.Length; int fieldLen = wd.fieldList.Length; var items = new List <FuturesMinute>(len); if (wd.data is double[]) { double[] dataList = (double[])wd.data; DateTime[] timeList = wd.timeList; for (int k = 0; k < len; k++) { items.Add(new FuturesMinute { tradeday = date, time = timeList[k], open = (double)dataList[k * fieldLen + 0], high = (double)dataList[k * fieldLen + 1], low = (double)dataList[k * fieldLen + 2], close = (double)dataList[k * fieldLen + 3], volume = (double)dataList[k * fieldLen + 4], amount = (double)dataList[k * fieldLen + 5], openInterest = (double)dataList[k * fieldLen + 6] }); } } //【原版】如果该时间段第1个时间点的close为NAN,则放弃该时间段的所有数据 //if (items.Count>0 && double.IsNaN(items[0].close)==true) //{ // return new List<FuturesMinute>(); //} //判断该时间段前25条数据是否含有真正的数据(至少一条数据) List <FuturesMinute> tempItem = items.GetRange(0, 25); bool haveData = items.Any(x => double.IsNaN(x.close) != true); //【新版1】如果该时间段前5个时间点的close为NAN,则放弃该时间段的所有数据 //if (items.Count > 0 && double.IsNaN(items[0].close) && double.IsNaN(items[1].close) && // double.IsNaN(items[2].close) && double.IsNaN(items[3].close) && double.IsNaN(items[4].close)) //{ // return new List<FuturesMinute>(); //} //【新版2】如果该时间段前20个时间点的close为NAN,则放弃该时间段的所有数据 if (items.Count > 0 && haveData == false) { return(new List <FuturesMinute>()); } return(items); }
private void button2_Click(object sender, EventArgs e) { string windCode = textBox4.Text; string svolume = textBox3.Text; if (!int.TryParse(svolume, out volume)) { volume = 100; } WindData wd = w.wsi(windCode, "open", DateTime.Today.AddHours(9.5), DateTime.Now, "BarSize=1"); if (wd.errorCode != 0) { richTextBox1.Text += "\r\n"; richTextBox1.Text += w.getErrorMsg(wd.errorCode); return; } open = (float)((double[])wd.data)[0]; Kmin = open; Kmax = 0; w.cancelRequest(rid); updateKLines(windCode); label4.Text = "当前价"; label7.Text = "K线最高价"; label7.ForeColor = Color.Red; label8.Text = "K线最低价"; label8.ForeColor = Color.Green; label13.Text = "开盘价"; label13.ForeColor = Color.SkyBlue; label14.Text = Convert.ToString(open); label14.ForeColor = Color.SkyBlue; //label11.Text = "5分钟K线图"; //label12.Text = "15分钟K线图"; //label11.ForeColor = myPens[0].Color; //label12.ForeColor = myPens[1].Color; label5.Text = windCode + " 最近15分钟价格走势图"; //for (int i = 1; i < allLabels.Count; i++) //{ // Controls.Add((Label)allLabels[i]); // ((Label)allLabels[i]).BringToFront(); //} }
public void Execute() { //从万得提取数据 WindAPI w = new WindAPI(); w.start(); WindData wd = w.wsi("510050.SH", "open,high,low,close,volume" , "2016-07-01 09:00:00", "2016-07-22 15:00:00", "Fill=Previous"); w.stop(); //初始化各类变量 DateTime[] DataDate = wd.timeList; String.Format("yyyy/MM/dd hh:mm:ss", DataDate); //日期、开盘价、最高价、最低价、收盘价、成交量 int FieldLength = wd.GetFieldLength(); int DataLength = wd.GetDataLength(); int DateLength = DataLength / FieldLength; int sign = 0;//下标计数 double[] RawData = (double[])wd.data; double[,] MarketData = new double[DateLength, 5]; /* * double[] OP = new double[DateLength]; * double[] HP = new double[DateLength]; * double[] LP = new double[DateLength]; * double[] CP = new double[DateLength]; */ for (int i = 0; i < RawData.Length; i = i + FieldLength) { for (int j = 0; j < FieldLength; j++) { MarketData[sign, j] = RawData[i + j]; } sign++; } // System.Console.WriteLine("{0},{1},{2},{3}", sign, MarketData.GetLength(0), MarketData.GetLength(1), DateLength); /* * for (int now = 0; now <= sign; now++) * { * if (now != 0 && now % 60 == 0)//60min做一次停顿 * Console.ReadKey(); * System.Console.WriteLine("Time:{0} -- O:{1} H:{2} L:{3} C:{4} Volum:{5}\n" * , DataDate[now], MarketData[now,0], MarketData[now,1] * , MarketData[now,2], MarketData[now,3], MarketData[now,4]); * } * Console.ReadKey(); */ GenSignal myGS = new GenSignal(); myGS.getSignal(MarketData); }
public static DataNode[] QueryDataK(string code, DateTime day) { WindData result; lock (_threadLock) { var start = day.Date.AddHours(9.5); var end = day.Date.AddHours(15); result = _api.wsi(code, "close,volume", start, end, "BarSize=1"); } return(DataHelper.ParseData(result, "wsi")); }
public static unsafe Bar[] DumpBarByWind(string code, string startDate, string endDate, BarType barType) { var ret = new List <Bar>(); if (barType == BarType.Day || barType == BarType.Week) { WindData wd = wind.wsd(code, "open,high,low,close,volume,settle,oi", startDate, endDate, ""); if (wd.data == null) { return(ret.ToArray()); } object[,] data = wd.getDataByFunc("wsd", false) as object[, ]; var w = wd.fieldList.Length; var l = (int)(data.Length / w); for (var i = 0; i < l; i++) { var bar = new Bar(); bar.TradingDay = int.Parse(wd.timeList[i].ToString("yyyyMMdd")); bar.D = wd.timeList[i]; bar.Settle = data[i, 5].GetDouble(); bar.O = data[i, 0].GetDouble(); bar.H = data[i, 1].GetDouble(); bar.L = data[i, 2].GetDouble(); bar.C = data[i, 3].GetDouble(); bar.V = data[i, 4].GetDouble(); bar.I = data[i, 6].GetDouble(); bar.WindCode = code; bar.BarType = barType; ret.Add(bar); } } else { var wd = wind.wsi(code, "open,high,low,close,volume,oi", startDate, endDate, $"BarSize={(int)barType}"); if (wd.data == null) { return(ret.ToArray()); } object[,] data = wd.getDataByFunc("wsi", false) as object[, ]; if (data == null) { Console.WriteLine($"{code} not find wsi {startDate} ~ {endDate}"); return(ret.ToArray()); } var w = wd.fieldList.Length; var l = (int)(data.Length / w); for (var i = 0; i < l; i++) { var bar = new Bar(); bar.TradingDay = int.Parse(wd.timeList[i].ToString("yyyyMMdd")); bar.D = wd.timeList[i]; bar.O = data[i, 0].GetDouble(); bar.H = data[i, 1].GetDouble(); bar.L = data[i, 2].GetDouble(); bar.C = data[i, 3].GetDouble(); bar.V = data[i, 4].GetDouble(); bar.I = data[i, 5].GetDouble(); bar.WindCode = code; bar.BarType = barType; ret.Add(bar); } } return(ret.ToArray()); }
public void DoIt() { WindAPI w = new WindAPI(); w.start(); //取昨天的最高、最低、收盘 double dLastHigh = 0; double dLastLow = 0; double dLastClose = 0; WindData wd = w.wss("600999.SH", "high,low,close", "tradeDate=20141202;priceAdj=U;cycle=D"); //WindData wd = w.wss("601000.SH", "high,low,close", "tradeDate=20141202;priceAdj=U;cycle=D"); //WindData wd = w.wss("M1309.DCE", "high,low,close", "tradeDate=20130411;priceAdj=U;cycle=D"); double[,] lastPriceData = (double[, ])wd.getDataByFunc("wss", true); if (null == lastPriceData) { return; } dLastHigh = lastPriceData[0, 0]; dLastLow = lastPriceData[0, 1]; dLastClose = lastPriceData[0, 2]; //计算出6个价位 double dSsetup = dLastHigh + 0.35 * (dLastClose - dLastLow); //观察卖出价 double dSenter = (1.07 / 2) * (dLastHigh + dLastLow) - 0.07 * dLastLow; //反转卖出价 double dBenter = (1.07 / 2) * (dLastHigh + dLastLow) - 0.07 * dLastHigh; //反转买入价 double dBsetup = dLastLow - 0.35 * (dLastHigh - dLastClose); //观察买入价 double dBbreak = dSsetup + 0.25 * (dSenter - dBsetup); //突破买入价 double dSbreak = dBsetup - 0.205 * (dSenter - dBsetup); //突破卖出价 //某天的交易数据 WindData wdWSI = w.wsi("600999.SH", "high,low,close", "2014-12-03 09:30:00", "2014-12-03 15:00:00", ""); //WindData wdWSI = w.wsi("601000.SH", "high,low,close", "2014-12-03 09:30:00", "2014-12-03 15:00:00", ""); //WindData wdWSI = w.wsi("M1309.DCE", "high,low,close", "2013-04-12 09:30:00", "2013-04-12 15:00:00", ""); double[,] curPriceData = (double[, ])wdWSI.getDataByFunc("wsi", true); if (null == curPriceData) { return; } int nTimeCount = curPriceData.GetLength(0); if (nTimeCount < 0) { return; } int nPriceDim = curPriceData.GetLength(1); if (nPriceDim < 3) { return; } //策略初值,1表示做多,-1表示做空,0表示无操作 List <int> curHoldList = new List <int>(nTimeCount); for (int i = 0; i < nTimeCount; i++) { curHoldList.Add(0); } double dCurHigh = curPriceData[0, 0]; double dCurLow = curPriceData[0, 1]; double dCurPrice = curPriceData[0, 2]; for (int i = 0; i < nTimeCount; i++) { dCurHigh = (curPriceData[i, 0] > dCurHigh) ? curPriceData[i, 0] : dCurHigh; dCurLow = (curPriceData[i, 1] > dCurLow) ? curPriceData[i, 1] : dCurLow; dCurPrice = curPriceData[i, 2]; //当前持仓 int nCurHold = curHoldList.Sum(); bool bCon1 = (dCurPrice > dBbreak) && (0 == nCurHold); //空仓做多条件 bool bCon2 = (dCurPrice < dSbreak) && (0 == nCurHold); //空仓做空条件 bool bCon3 = (nCurHold > 0) && (dCurHigh > dSsetup) && (dCurPrice < dSenter); //多单反转卖出条件:holding>0 and 今高>观察卖出价 and c<反转卖出价; bool bCon4 = (nCurHold < 0) && (dCurLow < dBsetup) && (dCurPrice > dBenter); //空单反转买入条件:=holding<0 and 今低<观察买入价 and c>反转买入价; //交易 if (bCon3) //多单反转 { curHoldList[i] = -1; //平多 //sell } else if (bCon2) //空单做空 { curHoldList[i] = -1; //sell } else if (bCon4) //空单反转 { curHoldList[i] = 1; //buy } else if (bCon1) //空仓做多 { curHoldList[i] = 1; //buy } else { curHoldList[i] = 0; } } int nCurHole = curHoldList.Sum(); //尾盘轧平 if (1 == nCurHole && 1 == curHoldList.Last()) { curHoldList[nTimeCount - 1] = 0; } else if (1 == nCurHole) { curHoldList[nTimeCount - 1] = -1; } else if (-1 == nCurHole && -1 == curHoldList.Last()) { curHoldList[nTimeCount - 1] = 0; } else if (-1 == nCurHole) { curHoldList[nTimeCount - 1] = 1; } //统计收益 double dProfit = 0; for (int i = 0; i < nTimeCount; i++) { dProfit += curPriceData[i, 2] * curHoldList[i]; } Console.WriteLine("策略收益:" + dProfit); w.stop(); }