Пример #1
0
 public Executor(StrategyContext context, IStrategyMeta meta, String instanceVersion, List <ExecuteParam> param)
 {
     this.context         = context;
     this.meta            = meta;
     this.instanceVersion = instanceVersion;
     this.param           = new List <ExecuteParam>(param);
 }
Пример #2
0
        /// <summary>
        /// 执行回测
        /// </summary>
        /// <param name="props"></param>
        /// <returns></returns>
        public virtual TotalStat DoTest(StrategyContext context, Properties testParam)
        {
            //取得回测参数
            this.backtestParam = new BacktestParameter(testParam);
            log = log4net.LogManager.GetLogger(this.backtestParam.Serialno);

            log.Info("");
            log.Info("回测策略实例:" + this.ToString());
            log.Info("回测数据路径=" + backtestParam.Datapath);
            log.Info("准备回测:回测编号=" + backtestParam.Serialno + ",初始资金=" + backtestParam.Initfunds.ToString("F2") + ",日期=" + backtestParam.BeginDate.ToString("yyyyMMdd") + "-" + backtestParam.EndDate.ToString("yyyyMMdd"));

            List <String> codes = new List <string>();

            System.IO.File.ReadAllLines(FileUtils.GetDirectory() + backtestParam.Codefilename)
            .ToList().ForEach(x => codes.Add(x.Split(',')[1]));
            log.Info("加载代码" + codes.Count.ToString());

            this.buyer = context.GetBuyer(props.Get <String>("buyer"));
            if (buyer == null)
            {
                throw new Exception("回测启动失败:找不到买入算法实现:" + props.Get <String>("buyer"));
            }
            this.seller = context.GetSeller(props.Get <String>("seller"));
            if (seller == null)
            {
                throw new Exception("回测启动失败:找不到卖出算法实现:" + props.Get <String>("seller"));
            }
            log.Info("买入算法=" + buyer.Caption + ",卖出算法=" + seller.Caption);

            List <TradeRecords> bouts     = doTestByCodes(codes);
            TotalStat           totalStat = doTestByDate(bouts);

            if (totalStat != null)
            {
                totalStat.Summary(log);
                recordBacktest(totalStat);
            }
            return(totalStat);
        }
Пример #3
0
 public abstract List <TradeInfo> DoBuy(Properties strategyParams, DateTime d, StrategyContext context);
Пример #4
0
 /// <summary>
 /// 卖出
 /// </summary>
 /// <param name="holdRecord"></param>
 /// <param name="d"></param>
 /// <param name="strategyParams"></param>
 /// <returns></returns>
 public abstract TradeInfo DoSell(HoldRecord holdRecord, DateTime d, Properties strategyParams, StrategyContext context);