private void SearchData() { //记录买入时间 DateTime buytime = DateTime.Now; int progress = 0; int totalnum = StockApp.allstock.Count * pnl_buysell.GetSelectedCombGroup().Length; int rulenum = 0; int lastdate = StockDapan.GetLastDate(); foreach (combineRule combinerule in pnl_buysell.GetSelectedCombGroup()) { Buy buyitem = combinerule.buy; Sell sellitem = combinerule.sell; rulenum++; progress = rulenum * StockApp.allstock.Count; int buyvalue = chk_ml.Checked ? Rule.STATUS_BUY_ML : Rule.STATUS_BUY; StockOpeItem[] opeitems = StockAnalysisSQL.GetAnalysis2List(buyvalue, fromdate, todate, buyitem.ToString(), sellitem.ToString(), -0.99, //SCORE false, //NO DEFAULT apply false); // no restrict max sell date foreach (StockOpeItem item in opeitems) { //sellprice > 0, 说明已卖出 if (chk_hidesold.Checked && item.selldate < Math.Min(lastdate, todate)) { continue; } list.Add(item.ToRowInfo()); } } }
public void SyncList() { this.dg_overview.Rows.Clear(); StockOpeItem[] items = null; foreach (Buy buyitem in calcpanel.GetAllBuy()) { foreach (Sell sellitem in calcpanel.GetAllSell()) { foreach (int rulevalue in Rule.rulebuy_type) { items = StockAnalysisSQL.GetAnalysis2List(rulevalue, startdate, enddate, buyitem.ToString(), sellitem.ToString(), (double)this.cmb_scorefilter.Value / 100 ); AddList(items, rulevalue, buyitem.ToString(), sellitem.ToString()); } } } }
private void dg_overview_DoubleClick(object sender, EventArgs e) { dg_detail.Rows.Clear(); DataGridViewRow row = this.dg_overview.Rows[this.dg_overview.SelectedCells[0].RowIndex]; int type = Convert.ToInt16(row.Cells[0].Value); string buyrule = (string)row.Cells[1].Value; string sellrule = (string)row.Cells[2].Value; StockOpeItem[] items = null; items = StockAnalysisSQL.GetAnalysis2List(type, startdate, enddate, buyrule, sellrule, (double)this.cmb_scorefilter.Value / 100); int index = 0; foreach (StockOpeItem s in items) { index++; dg_detail.Rows.Add(s.ToRowInfo()); } ShowDetail(true); }
//正式分析 private void Analyse() { System.Collections.ArrayList list = new System.Collections.ArrayList(); int itemnum = 0; list.Clear(); foreach (Buy buyitem in pnl_buysell.GetAllBuy()) { foreach (Sell sellitem in pnl_buysell.GetAllSell()) { foreach (int buyrule in Rule.rulebuy_type) { //计算的时候可以看到并没有考虑止损, 但实际显示结果时都有考虑 StockOpeItem[] rule_items = StockAnalysisSQL.CalculateSave2Analysis2(startdate, enddate, buyitem.ToString(), sellitem.ToString(), buyrule); //计算当前分析进度 foreach (StockOpeItem rule_item in rule_items) { if (rule_item.grade < buyitem.minumum_grade) { continue; } list.Add(rule_item); } } itemnum++; prog.SetProgress(itemnum * 100 * StockApp.allstock.Count / analyse_total); UtilLog.AddInfo(TAG, buyitem.ToString() + "-" + sellitem.ToString() + " analysis finished "); } }// for each buy StockAnalysisSQL.SaveToDB_Analysis2(list); UtilLog.AddInfo(TAG, startdate + " till " + enddate + " buy analyse finished."); }
private void Simulate(int new_startdate, int new_enddate) { this.dg_overview.Rows.Clear(); //仓位股票数量 holdstocknum = (int)txt_num.Value; foreach (int buy_type in Rule.rulebuy_type) { for (int i = 0; i < pnl_buysell2.GetSelectedCombGroup().Length; i++) { sm = new SimulateManager(new_startdate, new_enddate, holdstocknum); combineRule combinerule = pnl_buysell2.GetSelectedCombGroup()[i]; //得到所有符合买卖原则的数据 StockOpeItem[] items = StockAnalysisSQL.GetAnalysis2List(buy_type, new_startdate, new_enddate, combinerule.buy.ToString(), combinerule.sell.ToString(), -0.99, true, //apply default Sell true); foreach (StockOpeItem item in items) { sm.AddOpeItem(item); } sm.Simulate(new_startdate, new_enddate); sm.SaveToDB(buy_type, combinerule.buy.ToString(), combinerule.sell.ToString()); } } }