void RunVirtual() { //try //{ Dictionary <string, CalcStragGroupClass> rest = null; Program.AllSettings.AllRunningPlanGrps = InitServerClass.InitCalcStrags(ref rest, Program.AllSettings.AllStrags, SCList.ToDictionary(p => p.GUID, p => p), Program.AllSettings.AllAssetUnits, true, true);//注入plans btc.FinishedProcess = new SuccEvent(Finished); ret = btc.VirExchange(Program.AllSettings, ref es, SCList.ToArray()); //} //catch (Exception ce) //{ // MessageBox.Show(ce.Message); //} //MessageBox.Show(es.summary.ToString()); //DataView moneyLines = new DataView(es.MoneyIncreamLine); //this.chart1.Series[0].Points.DataBindXY(moneyLines, "id", moneyLines, "val"); //btn_VirExchange.Text = "模拟交易"; //MessageBox.Show("执行完成!"); this.RunVirExchange = false; }
void RefreshList() { //////if (!ret.succ) //////{ ////// this.Cursor = Cursors.Default; ////// MessageBox.Show(ret.Msg); ////// return; //////} ret = btc.ret; if (ret == null) { return; } this.listView1.Items.Clear(); lock (ret.ChanceList) { for (int i = 0; i < ret.ChanceList.Count; i++) { if (ret.ChanceList[i].HoldTimeCnt > int.Parse(this.txt_MinCols.Text)) { ListViewItem li = new ListViewItem(); li.Text = i.ToString(); li.SubItems.Add(ret.ChanceList[i].ChanceCode); li.SubItems.Add(ret.ChanceList[i].SignExpectNo); li.SubItems.Add(ret.ChanceList[i].EndExpectNo); li.SubItems.Add(ret.ChanceList[i].ChipCount.ToString()); li.SubItems.Add(ret.ChanceList[i].strInputTimes); li.SubItems.Add(ret.ChanceList[i].HoldTimeCnt.ToString()); li.SubItems.Add(ret.ChanceList[i].MatchChips.ToString()); li.SubItems.Add(ret.ChanceList[i].CreateTime.ToString()); li.SubItems.Add(ret.ChanceList[i].UpdateTime.ToString()); this.listView1.Items.Add(li); } } } this.listView2.Items.Clear(); lock (ret.InChipsDic) { int AllChips = ret.InChipsDic.Sum(it => it.Value); int AllWinChips = ret.WinChipsDic.Sum(it => it.Value); foreach (int key in ret.HoldCntDic.Keys) { //AllChips += ret.InChipsDic[key]; ListViewItem li = new ListViewItem(); li.SubItems.Add(key.ToString()); li.SubItems.Add(ret.HoldCntDic[key].ToString()); li.SubItems.Add(ret.HoldWinCntDic[key].ToString()); li.SubItems.Add(ret.InChipsDic[key].ToString()); li.SubItems.Add(ret.WinChipsDic[key].ToString()); int preCnt = 0; int preInChips = 0; foreach (int mkey in ret.HoldCntDic.Keys) { if (key > mkey) { preCnt = preCnt + ret.HoldCntDic[mkey]; preInChips += ret.InChipsDic[mkey]; } } double bs = 100.00 * (float)ret.HoldCntDic[key] / (float)ret.ChanceList.Count; double rbs = 100.00 * (float)ret.HoldWinCntDic[key] / (float)ret.ChanceList.Count; double dr = (float)ret.HoldCntDic[key] / ((float)ret.LoopCnt / 180); double cr = 100.00 * (float)ret.HoldWinCntDic[key] / (ret.ChanceList.Count - preCnt); double mr = 100.00 * (float)ret.WinChipsDic[key] / (AllChips - preInChips); li.SubItems.Add(string.Format("{0:F}/{1:F}", bs, rbs)); //li.SubItems.Add(string.Format("100*{1}/({2}-{3})={0:F}", cr, ret.HoldCntDic[key], ret.ChanceList.Count, preCnt)); li.SubItems.Add(string.Format("{0:F}", cr)); li.SubItems.Add(mr.ToString()); li.SubItems.Add(string.Format("{0:F}", dr)); this.listView2.Items.Add(li); } this.toolStripStatusLabel1.Text = string.Format("第{4}次;合计数量:{0}({2}/{3})/{1}", ret.ChanceList.Count.ToString(), ret.LoopCnt, AllChips, AllWinChips, btc.testIndex); this.toolStripStatusLabel2.Text = "显示数量:" + this.listView1.Items.Count.ToString(); } if (ret.succ) { this.timer_Tip.Enabled = false; } }
private void DoSomething(BackgroundWorker worker, DoWorkEventArgs e) { SettingClass setting = new SettingClass(); setting.GrownMaxVal = int.Parse(this.txt_GrownMaxVal.Text); setting.GrownMinVal = int.Parse(this.txt_GrownMinVal.Text); setting.DispRows = int.Parse(this.txt_MinCols.Text); setting.minColTimes = new int[10]; for (int i = 0; i < 9; i++) { TextBox tb = this.Controls.Find(string.Format("txt_minColTimes{0}", i + 1), true)[0] as TextBox; setting.minColTimes[i] = int.Parse(tb.Text); } #region 老的调用逻辑改为和正式运行一样的通过注入选择的计划列表,运行。除了调试不写入表,其他处理一样。其实在正常处理里面也可以使用调试模式,那会导致停止服务后无法保留交易数据 //////////////////Assembly asmb = typeof(StragClass).Assembly;// Assembly.LoadFrom("EnterpriseServerBase.dll"); //////////////////btc = new BackTestClass(long.Parse(txt_begExpNo.Text), long.Parse(txt_LoopCnt.Text), setting); //////////////////Type sct = asmb.GetType(ddl_StragName.SelectedValue.ToString()); //////////////////StragClass sc = Activator.CreateInstance(sct) as StragClass; //////////////////sc.CommSetting = setting; //////////////////sc.ChipCount = int.Parse(this.txt_ChipCnt.Text); //////////////////sc.FixChipCnt = (this.txt_FixChipCnt.Text.Trim() == "0") ? false : true; //////////////////sc.ReviewExpectCnt = int.Parse(this.txt_reviewExpCnt.Text); //////////////////sc.InputMinTimes = int.Parse(this.txt_minInputTimes.Text); //////////////////sc.InputMaxTimes = int.Parse(this.txt_maxInputTimes.Text); //////////////////sc.ExcludeBS = this.chkb_exclueBS.Checked; //////////////////sc.ExcludeSD = this.chkb_exclueSD.Checked; //////////////////sc.BySer = this.chkb_bySer.Checked; //////////////////sc.OnlyBS = this.chkb_onlyBS.Checked; //////////////////sc.OnlySD = this.chkb_onlySD.Checked; //////////////////sc.GetRev = this.chkb_getRev.Checked; //////////////////if (sc is IProbCheckClass) //////////////////{ ////////////////// (sc as IProbCheckClass).StdvCnt = double.Parse(this.txt_StdvCnt.Text); //////////////////} //////////////////sc.MinWinRate = (double)double.Parse(this.txt_Odds.Text) / double.Parse(this.txt_ChipCnt.Text) / double.Parse(this.txt_minRate.Text); ////////////////////凯利公式 (p*b-q)/q ////////////////////////double p = 1 / sc.MinWinRate; ////////////////////////double b = double.Parse(this.txt_Odds.Text); ////////////////////////double q = 1 - p; ////////////////////////sc.StagSetting = sc.getInitStagSetting(); ////////////////////////sc.StagSetting.BaseType.ChipRate = (p * b - q) / q; ////////////////////////if (MessageBox.Show(sc.StagSetting.BaseType.ChipRate.ToString(), "胜率", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) ; ////////////////////////{ //////////////////////// return; ////////////////////////} #endregion btc = new BackTestClass(long.Parse(txt_begExpNo.Text), long.Parse(txt_LoopCnt.Text), setting); this.listView1.Items.Clear(); this.listView2.Items.Clear(); this.listView3.Items.Clear(); StragRunPlanClass[] plans = this.runPlanPicker1.Plans; if (plans.Length == 0) { return; } SCList = plans.ToList(); SCList.ForEach(p => p.PlanStrag.CommSetting = setting); SCList.ForEach(p => p.PlanStrag.ChipCount = int.Parse(this.txt_ChipCnt.Text)); SCList.ForEach(p => p.Running = true); SCList.ForEach(p => p.AutoRunning = true); SCList.ForEach(p => p.FixAmt = 1); SCList.ForEach(p => p.FixRate = 0.01); sc = SCList[0].PlanStrag; this.Cursor = Cursors.WaitCursor; timer_Tip.Tick += new EventHandler(RefreshList); this.timer_Tip.Interval = int.Parse(txt_Timer_Interval.Text) * 1000; this.timer_Tip.Enabled = true; Thread thrd = null; try { btc.FinishedProcess = new SuccEvent(Finished); btc.teststrag = sc; thrd = new Thread(new ThreadStart(btc.Run)); thrd.Start(); } catch (Exception ce) { ret = new BackTestReturnClass(); ret.ChanceList = new List <ChanceClass>(); ret.Msg = ce.Message; ret.succ = false; MessageBox.Show(ce.Message); } //this.RunVirExchange = true; this.Cursor = Cursors.Default; ////if (!ret.succ) //// MessageBox.Show(ret.Msg); ////RefreshList(null, null); ////while(true) ////{ //// Thread.Sleep(1000); //// RefreshList(null, null); //// if (thrd.ThreadState == ThreadState.Stopped) //// { //// break; //// } ////} ////this.timer_Tip.Enabled = false; ////RefreshList(); }