Beispiel #1
0
        /// <summary>
        /// 计算适应度
        /// </summary>
        /// <param name="individual"></param>
        /// <returns></returns>
        private double computeFitness(int serinalno, Properties individual)
        {
            Properties testParam = context.BacktestParam.Clone();

            testParam["serialno"] = serinalno;
            testParam["batchno"]  = serinalno;;
            IStrategyInstance instance = meta.CreateInstance(serinalno.ToString(), individual, "");

            logger.Info("启动回测:...");
            instance.Initilization();
            TotalStat stat = instance.DoTest(context, testParam);

            individual.Put("fitness", stat.TotalProfilt);
            return(stat.TotalProfilt);
        }
Beispiel #2
0
        /// <summary>
        /// 收到的是回测序号和回测参数
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            init();

            //取得参数
            if (args == null || args.Length <= 1 || args[0] == null || args[1] == null || args[0] == "" || args[1] == "")
            {
                logger.Info("启动失败,参数错误");
                return;
            }
            backtestxh = args[0];
            String paramStr = args[1];

            //生成策略参数
            alpha         = new AlphaStrategy4();
            strategyProps = new Properties();
            List <String> paramnames = alpha.GetParameterNames();

            String[] paramValueArray = paramStr.Split(',');
            if (paramnames.Count != paramValueArray.Length)
            {
                logger.Info("启动失败,策略参数无效:" + paramStr);
                return;
            }
            for (int i = 0; i < paramnames.Count; i++)
            {
                strategyProps.Put(paramnames[i], paramValueArray[i]);
            }

            //读取回测参数
            Properties fileprops = Properties.Load(FileUtils.GetDirectory() + "\\alpha.properties", Encoding.UTF8);
            Dictionary <String, Properties> propSet = fileprops.Spilt();

            backtestProps             = propSet["backtest"];
            backtestProps["serialno"] = backtestxh.ToString();

            //创建策略实例
            IStrategyInstance instance = alpha.CreateInstance(backtestxh.ToString(), strategyProps);

            //执行策略实例的回测
            instance.Initilization();
            instance.DoTest(new StrategyContext(), backtestProps);
        }
Beispiel #3
0
        public Task Go()
        {
            Task task = Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < param.Count; i++)
                {
                    //准备执行参数
                    log4net.ILog logger = log4net.LogManager.GetLogger(param[i].backtestxh.ToString());

                    //启动回测程序并等待结束

                    IStrategyInstance instance = meta.CreateInstance(param[i].backtestxh, param[i].instanceParam, instanceVersion);
                    logger.Info("启动回测:...");
                    instance.Initilization();
                    instance.DoTest(context, param[i].backtestProp);

                    String batchno         = param[i].backtestProp.Get <String>("batchno");
                    String resultPath      = param[i].backtestProp.Get <String>("resultpath");
                    resultPath             = FileUtils.GetDirectory(resultPath);
                    String resultFile      = resultPath + param[i].backtestxh + ".result";
                    String batchresultfile = resultPath + batchno + ".result";
                    if (System.IO.File.Exists(resultFile))
                    {
                        String[] content = System.IO.File.ReadAllLines(resultFile);
                        lock (batchResultFileLocker)
                        {
                            System.IO.File.AppendAllLines(batchresultfile, content);
                        }
                        logger.Info("合并回测结果:" + ((content == null || content.Length <= 0) ? "" : content[0]));
                    }
                    else
                    {
                        logger.Warn("没有找到执行结果");
                    }
                }
            });

            return(task);
        }