/// <summary> /// 滚动测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_roundTest_Click(object sender, EventArgs e) { if (this.runPlanPicker1.Plans.Length == 0) { return; } this.Cursor = Cursors.WaitCursor; 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); } btc = new BackTestClass(long.Parse(txt_begExpNo.Text), long.Parse(txt_LoopCnt.Text), setting); Assembly asmb = typeof(StragClass).Assembly; //////Type sct = asmb.GetType(ddl_StragName.SelectedValue.ToString()); //////StragClass sc = Activator.CreateInstance(sct) as StragClass; StragClass sc = this.runPlanPicker1.Plans[0].PlanStrag; 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; this.runPlanPicker1.Plans[0].PlanStrag = sc; RoundBackTestReturnClass rbtr = null; try { int cycLong = int.Parse(txt_RoundCycLong.Text); int stepLong = int.Parse(txt_RoundStepLong.Text); rbtr = btc.RunRound(sc, cycLong, stepLong); } catch (Exception ce) { rbtr = new RoundBackTestReturnClass(); rbtr.Msg = ce.Message; rbtr.succ = false; } if (!rbtr.succ) { this.Cursor = Cursors.Default; MessageBox.Show(rbtr.Msg); return; } listView3.Items.Clear(); List <float> wins = rbtr.RoundWinRate; for (int i = 0; i < rbtr.RoundData.Count; i++) { ListViewItem lvi = new ListViewItem(); lvi.Text = (i + 1).ToString(); lvi.SubItems.Add(rbtr.RoundData[i].LoopCnt.ToString()); lvi.SubItems.Add(rbtr.RoundData[i].ChanceList.Count.ToString()); lvi.SubItems.Add(rbtr.RoundData[i].HoldCntDic[1].ToString()); lvi.SubItems.Add(wins[i].ToString()); listView3.Items.Add(lvi); } this.tabPage3.Show(); this.Cursor = Cursors.Default; MessageBox.Show(rbtr.Msg); }
/// <summary> /// 模拟回归 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_VirExchange_Click(object sender, EventArgs e) { StragRunPlanClass[] plans = this.runPlanPicker1.Plans; if (plans == null || plans.Length == 0) { return; } SCList = plans.ToList(); if (!RunVirExchange) { if (MessageBox.Show("确定开始模拟成交?", "确认", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } if (RunVirExchange) { if (MessageBox.Show("确定停止模拟成交?", "确认", MessageBoxButtons.YesNo) == DialogResult.No) { return; } try { if (th.ThreadState == ThreadState.Running) { th.Abort(); } } catch { } th = null; this.timer_Tip.Enabled = false; RunVirExchange = false; return; } this.RunVirExchange = true; //this.btn_VirExchange.Text = "停止"; //this.Cursor = Cursors.WaitCursor; //es = new ExchangeService(int.Parse(this.txt_InitCash.Text),double.Parse(this.txt_Odds.Text)); SettingClass setting = new SettingClass(); setting.SetGlobalSetting(this.globalSetting); 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]; setting.UseLocalWaveData = this.checkBox_UseBuffRsult.Checked; AssetUnitClass auc = new AssetUnitClass(); if (Program.AllSettings.AllAssetUnits.Count > 0)//如果存在资产管理单元,所有计划均绑定到第一个上进行测试 { auc = Program.AllSettings.AllAssetUnits.Values.First(); } es = auc.ExchangeServer; if (es != null) { es.Reset(); } //设置所有默认值 SCList.ForEach(p => p.PlanStrag.CommSetting = setting); SCList.ForEach(p => p.AssetUnitInfo = auc); SCList.ForEach(p => p.Running = true); //if (SCList.Count == 1) //{ // //SCList[0].PlanStrag = sc; SCList.ForEach(p => p.IncreamType = this.checkBox_CreamModel.Checked ? InterestType.CompoundInterest : InterestType.SimpleInterest); SCList.ForEach(p => p.AutoRunning = true); ////SCList.ForEach(p=>p.FixAmt = 1); ////SCList.ForEach(p=>p.FixRate = 0.01); SCList.ForEach(p => p.AllowMaxHoldTimeCnt = int.Parse(txt_AllowMaxHoldTimeCnt.Text)); if (SCList.Count == 1) { SCList.ForEach(p => p.PlanStrag.ChipCount = int.Parse(this.txt_ChipCnt.Text)); } //} #region 用新的计算进行回测 ////////////////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); ////////////////} ////////////////setting.MaxHoldingCnt = int.Parse(this.txt_MaxHoldChanceCnt.Text); ////////////////setting.Odds = double.Parse(this.txt_Odds.Text); ////////////////setting.InitCash = int.Parse(this.txt_InitCash.Text); ////////////////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()); ////////////////if (!checkBox_MixAll.Checked) ////////////////{ //////////////// ////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); //////////////// if (sc.StagSetting.IsLongTermCalc) //////////////// { //////////////// sc.ReviewExpectCnt = sc.ReviewExpectCnt + sc.InputMinTimes; //////////////// } //////////////// 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.AllowMaxHoldTimeCnt = int.Parse(this.txt_AllowMaxHoldTimeCnt.Text); //////////////// sc.MinWinRate = double.Parse(this.txt_minRate.Text); //////////////// ////double p = double.Parse(this.txt_ChipCnt.Text) / setting.Odds; //////////////// ////double Normal_p = double.Parse(this.txt_ChipCnt.Text) / 10; //////////////// ////double b = double.Parse(this.txt_Odds.Text); //////////////// ////double q = 1 - p; //////////////// sc.StagSetting = sc.getInitStagSetting(); //////////////// ////sc.StagSetting.BaseType.ChipRate = (p * b - q) / b; //////////////// //sc.StagSetting.BaseType.IncrementType = this.checkBox_CreamModel.Checked ? InterestType.CompoundInterest : InterestType.SimpleInterest; //////////////// if (setting.UseLocalWaveData && sc is ProbWaveSelectStragClass)//是长期概率分布类 //////////////// { //////////////// DataTable dt = new PK10ProbWaveDataInterface().GetProWaveResult(long.Parse(txt_begExpNo.Text)); //////////////// (sc as ProbWaveSelectStragClass).LocalWaveData = new GuideResult(dt); //////////////// } //////////////// StragRunPlanClass sr = new StragRunPlanClass(); //////////////// sr.PlanStrag = sc; //////////////// sr.IncreamType = this.checkBox_CreamModel.Checked ? InterestType.CompoundInterest : InterestType.SimpleInterest; //////////////// sr.AutoRunning = true; //////////////// sr.FixAmt = 1; //////////////// sr.FixRate = 0.01; //////////////// SCList.Add(sr); ////////////////} ////////////////else ////////////////{ //////////////// for (int i = 2; i < 9; i++) //////////////// { //////////////// for (int j = 0; j < 2; j++) //////////////// { //////////////// StragClass sobj = Activator.CreateInstance(sct) as StragClass; //////////////// sobj.CommSetting = setting; //////////////// sobj.ChipCount = i; //////////////// sobj.FixChipCnt = (this.txt_FixChipCnt.Text.Trim() == "0") ? false : true; //////////////// sobj.ReviewExpectCnt = sobj.CommSetting.minColTimes[i - 1] + 1; //////////////// sobj.BySer = j==1; //////////////// sobj.MinWinRate = double.Parse(this.txt_minRate.Text); //////////////// //sobj.AllowMaxHoldTimeCnt = 100; //////////////// sobj.StagSetting = sobj.getInitStagSetting(); //////////////// //sobj.StagSetting.BaseType.IncrementType = this.checkBox_CreamModel.Checked ? InterestType.CompoundInterest : InterestType.SimpleInterest; //////////////// StragRunPlanClass sr = new StragRunPlanClass(); //////////////// sr.PlanStrag = sobj; //////////////// sr.IncreamType = this.checkBox_CreamModel.Checked ? InterestType.CompoundInterest : InterestType.SimpleInterest; //////////////// sr.AutoRunning = true; //////////////// sr.FixAmt = 1; //////////////// sr.FixRate = 0.01; //////////////// SCList.Add(sr); //////////////// } //////////////// } ////////////////} //////////////////sc.MinWinRate = double.Parse(this.txt_Odds.Text) *double.Parse(this.txt_minRate.Text); //////////////////凯利公式 (p*b-q)/b //////////////////凯利公式 (p*b-q)/b //////////////////////DialogResult rs = MessageBox.Show(sc.StagSetting.BaseType.ChipRate.ToString(), "胜率", MessageBoxButtons.OKCancel) ; //////////////////////if (rs == DialogResult.Cancel) //////////////////////{ ////////////////////// return; //////////////////////} #endregion //this.Cursor = Cursors.WaitCursor; this.chart1.Series.Clear(); //this.chart1.DataSource = null; this.timer_Tip.Interval = int.Parse(txt_Timer_Interval.Text) * 1000; timer_Tip.Tick += new EventHandler(timer_Tip_Tick); //this.timer_Tip.Enabled = true; this.timer_Tip.Enabled = true; //this.timer_Tip_Tick(null, null); //////try //////{ if (btc == null) { btc = btc = new BackTestClass(long.Parse(txt_begExpNo.Text), long.Parse(txt_LoopCnt.Text), setting); } th = new Thread(RunVirtual); th.Start(); return; //////} //////catch (Exception ce) //////{ ////// ret = new BackTestReturnClass(); ////// ret.ChanceList = new List<ChanceClass>(); ////// ret.Msg = ce.Message; ////// ret.succ = 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(); }