Example #1
0
        private void btn_clearNet_Click(object sender, EventArgs e)
        {
            Dictionary <string, AssetUnitClass> units = this.ddl_assetunits.Tag as Dictionary <string, AssetUnitClass>;

            if (this.ddl_assetunits.SelectedIndex < 0)
            {
                return;
            }
            AssetUnitClass auc = units[this.ddl_assetunits.SelectedValue.ToString()];

            if (auc == null)
            {
                return;
            }
            if (MessageBox.Show("是否真的需要恢复资产单元到初始金额?如果点是,资产单元将恢复到设定的初始值,对于复利策略对应的资产单元,将恢复到100%状态,在连续亏损时请慎重点击该按钮,建议当资产单元达到10%以下才使用!", "确认恢复资产单元", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }
            try
            {
                auc.Resume();
            }
            catch (Exception ce)
            {
                MessageBox.Show(ce.Message);
            }
        }
Example #2
0
 void RefrshStragAndPlan()
 {
     try
     {
         if (UseSetting == null)
         {
             return;
         }
         DataTable dt_strag = StragClass.ToTable <StragClass>(UseSetting.AllStrags.Values.ToList <StragClass>());
         if (dt_strag != null)
         {
             SetDataGridDataTable(dg_StragList, dt_strag);
         }
         DataTable dt_plans = StragRunPlanClass.ToTable <StragRunPlanClass>(UseSetting.AllRunPlannings.Values.ToList <StragRunPlanClass>());
         if (dt_plans != null)
         {
             SetDataGridDataTable(dg_stragStatus, dt_plans);
         }
         DataTable dt_grps = CalcStragGroupClass.ToTable <CalcStragGroupClass>(UseSetting.AllRunningPlanGrps.Values.ToList <CalcStragGroupClass>());
         if (dt_grps != null)
         {
             SetDataGridDataTable(dg_PlanGrps, dt_grps);
         }
         DataTable dt_assetunit = AssetUnitClass.ToTable <AssetUnitClass>(UseSetting.AllAssetUnits.Values.ToList <AssetUnitClass>());
         if (dt_assetunit != null)
         {
             SetDataGridDataTable(dg_AssetUnits, dt_assetunit);
         }
         refresh_AssetChart();
     }
     catch (Exception e)
     {
     }
 }
Example #3
0
        private void dg_AssetUnits_DoubleClick(object sender, EventArgs e)
        {
            if (this.dg_AssetUnits.CurrentRow.Index < 0)
            {
                return;
            }
            if (UseSetting == null)
            {
                return;
            }

            AssetUnitClass auc = null;

            try
            {
                DataTable dt = this.dg_AssetUnits.Tag as DataTable;
                string    id = dt.Rows[dg_AssetUnits.CurrentRow.Index]["UnitId"].ToString();
                auc = UseSetting.AllAssetUnits[id];
                if (auc == null)
                {
                    return;
                }
            }
            catch
            {
                return;
            }
            //dg_AssetUnits as
            DataView moneyLines = new DataView(auc.SummaryLine());

            this.chart_ForGuide.Series[0].Points.DataBindXY(moneyLines, "id", moneyLines, "val");
        }
Example #4
0
        void RefrshStragAndPlan(bool ForceRefresh = false)
        {
            try
            {
                if (UseSetting == null)
                {
                    return;
                }
                DataTable dt_strag = BaseStragClass <TimeSerialData> .ToTable <BaseStragClass <TimeSerialData> >(UseSetting.AllStrags.Values.ToList <BaseStragClass <TimeSerialData> >());

                if (dt_strag != null)
                {
                    SetDataGridDataTable(dg_StragList, dt_strag);
                }
                DataTable dt_plans = StragRunPlanClass <TimeSerialData> .ToTable <StragRunPlanClass <TimeSerialData> >(UseSetting.AllRunPlannings.Values.ToList <StragRunPlanClass <TimeSerialData> >());

                if (dt_plans != null)
                {
                    SetDataGridDataTable(dg_stragStatus, dt_plans);
                }
                DataTable dt_grps = CalcStragGroupClass <TimeSerialData> .ToTable <CalcStragGroupClass <TimeSerialData> >(UseSetting.AllRunningPlanGrps.Values.ToList <CalcStragGroupClass <TimeSerialData> >());

                if (dt_grps != null)
                {
                    SetDataGridDataTable(dg_PlanGrps, dt_grps);
                }
                DataTable dt_assetunit = AssetUnitClass.ToTable <AssetUnitClass>(UseSetting.AllAssetUnits.Values.ToList <AssetUnitClass>());
                if (dt_assetunit != null)
                {
                    SetDataGridDataTable(dg_AssetUnits, dt_assetunit);
                }
                DataTable dt_exchange = null;
                foreach (AssetUnitClass auc in UseSetting.AllAssetUnits.Values)
                {
                    ExchangeService ed = auc.getCurrExchangeServer();
                    if (ed == null)
                    {
                        //MessageBox.Show(string.Format("{0}资产单元交易服务为空!", auc.UnitName));

                        continue;
                    }
                    DataTable assetdt = ed.ExchangeDetail;
                    if (assetdt == null)
                    {
                        //MessageBox.Show(string.Format("{0}资产单元交易记录为空!", auc.UnitName));

                        continue;
                    }
                    //MessageBox.Show(string.Format("{0}有新交易记录{1}条!列数:{2}", auc.UnitName, assetdt.Rows.Count,assetdt.Columns.Count));

                    if (assetdt != null)
                    {
                        if (dt_exchange == null)
                        {
                            dt_exchange = assetdt.Clone();
                        }
                        for (int i = 0; i < assetdt.Rows.Count; i++)
                        {
                            dt_exchange.Rows.Add(assetdt.Rows[i].ItemArray);
                        }
                    }
                }
                //MessageBox.Show(dt_exchange.Rows.Count.ToString());
                if (dt_exchange != null)
                {
                    SetDataGridDataTable(dg_ExchangeList, dt_exchange, "createtime desc");
                }
                if (UseSetting.AllAssetUnits != null)
                {
                    lock (UseSetting.AllAssetUnits)
                    {
                        refresh_AssetChart();
                    }
                }
            }
            catch (Exception e)
            {
                string msg = string.Format("{0}:{1}", e.Message, e.StackTrace);
                if (ForceRefresh)
                {
                    MessageBox.Show(msg);
                }
            }
        }
Example #5
0
        /// <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;
            //////}
        }