Пример #1
0
        /// <summary>
        /// Create parametter grid from meta.ParameterDefaultValues
        /// </summary>
        /// <param name="meta"></param>
        protected void SetPara(StrategyMeta meta)
        {
            this.ShowMessage("");

            this.myMeta = meta;
            paramGrid.Rows.Clear();
            string[] keys   = meta.ParameterList.Keys;
            object[] values = meta.ParameterList.Values;
            for (int idx = 0; idx < keys.Length; idx++)
            {
                paramGrid.Rows.Add(keys[idx], values[idx]);
            }
            valueColumn.DefaultCellStyle.Format = "N" + meta.ParameterPrecision.ToString();
            paraDescEd.Text = common.system.ToString(meta.ParameterDescriptions);
            hintTextEd.Text = meta.Description + common.Consts.constCRLF + meta.URL;
        }
Пример #2
0
 public baseStrategyForm(StrategyMeta meta)
 {
     InitializeComponent();
     SetPara(meta);
     tabControl.SendToBack();
 }
Пример #3
0
        public void Execute()
        {
            #region 读取策略参数
            //读取参数文件,将参数属性文件分成策略参数和回测参数
            Properties fileprops = Properties.Load(FileUtils.GetDirectory() + "\\alpha.properties", Encoding.UTF8);
            batchno = fileprops.Get <int>("backtest.batchno");
            backteststrategyName = fileprops.Get <String>("backtest.strategy");
            Dictionary <String, Properties> propSet = fileprops.Spilt();
            backtestProps             = propSet["backtest"];
            strategyProps             = propSet[backteststrategyName];
            resultPath                = FileUtils.GetDirectory(backtestProps.Get <String>("resultpath"));
            backtestsetresultfilename = resultPath + batchno + ".result";
            taskCount = backtestProps.Get <int>("taskcount");
            if (taskCount <= 0)
            {
                taskCount = 1;
            }
            #endregion


            #region 准备策略参数
            //分解策略参数:tParams中的key是参数名,value是所有的值组合
            List <String>         tParamNames  = new List <string>();
            List <List <String> > tParamValues = new List <List <string> >();
            List <String>         keys         = strategyProps.Keys;
            foreach (String tKey in keys)
            {
                List <String> tValues = new List <string>();
                String        tvalue  = strategyProps[tKey].ToString();
                if (tvalue.Contains(","))
                {
                    tValues.AddRange(tvalue.Split(','));
                }
                else
                {
                    tValues.Add(tvalue);
                }
                int    tIndex = tKey.IndexOf(".");
                String key    = tKey.Substring(tIndex + 1, tKey.Length - tIndex - 1);
                tParamNames.Add(key);
                tParamValues.Add(tValues);
            }
            //生成策略参数集
            List <String>[]   combinators     = CollectionUtils.Combination <String>(tParamValues.ToArray());
            List <Properties> instancePropSet = new List <Properties>();
            for (int i = 0; i < combinators.Length; i++)
            {
                Properties p = new Properties();
                instancePropSet.Add(p);
                List <String> combinator = combinators[i];
                for (int j = 0; j < combinator.Count; j++)
                {
                    p.Put(tParamNames[j], combinator[j]);
                }
            }
            logger.Info("准备策略参数:共有" + instancePropSet.Count.ToString() + "个参数组合");
            #endregion

            #region 生成任务
            List <Task>     tasks                = new List <Task>();
            List <Executor> executors            = new List <Executor>();
            int             instanceCountPerTask = instancePropSet.Count / taskCount;
            alpha = new StrategyMeta();
            List <ExecuteParam> execParams = new List <ExecuteParam>();
            for (int i = 0; i < instancePropSet.Count; i++)
            {
                int backtestxh = batchno + i + 1;//回测序号
                //结果文件已经有了,跳过
                String resultfilename = resultPath + backtestxh + ".result";
                if (System.IO.File.Exists(resultfilename))
                {
                    continue;
                }


                Properties instanceProp = instancePropSet[i];
                Properties backtestProp = backtestProps.Clone();
                backtestProp["serialno"] = backtestxh.ToString();
                backtestProp["batchno"]  = batchno.ToString();

                execParams.Add(new ExecuteParam(backtestxh.ToString(), GetStrateParameterValues(instanceProp)));
                if (execParams.Count >= instanceCountPerTask)
                {
                    Executor executor = new Executor(execParams, resultPath, batchno.ToString());
                    executors.Add(executor);
                    execParams.Clear();
                }
            }
            if (execParams.Count > 0)
            {
                Executor executor = new Executor(execParams, resultPath, batchno.ToString());
                executors.Add(executor);
                execParams.Clear();
            }
            #endregion

            #region 执行任务
            System.IO.File.WriteAllText(resultPath + batchno + ".result", alpha.GetBatchResultTitle());

            logger.Info("准备执行任务...,(任务数=" + executors.Count.ToString() + ")");
            executors.ForEach(x => tasks.Add(x.Go()));
            Task.WaitAll(tasks.ToArray());

            Console.Read();
            #endregion
        }