Esempio n. 1
0
        public void TestStrategyResult_DataPackage()
        {
            //ICodePeriodFactory factory = DataCenter.Default.CodePeriodFactory;
            //ICodePeriod codePeriod = factory.CreateCodePeriod("rb1801", 20170501, 20170801);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_15Minute);
            referedPeriods.UseTickData = true;
            StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(true, KLinePeriod.KLinePeriod_15Minute);
            //StrategyArguments_CodePeriod strategyCodePeriod = new StrategyArguments_CodePeriod(codePeriod, referedPeriods, forwardPeriod);
            IDataPackage_Code             dataPackage       = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code("rb1801", 20170501, 20170801);
            StrategyArguments_DataPackage strategyArguments = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);

            //自动保存结果
            strategyArguments.IsSaveResult = true;
            IStrategyExecutor_Single executor = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(strategyArguments);
            MockStrategy_Results     strategy = new MockStrategy_Results();

            strategy.Name     = "策略结果保存";
            executor.Strategy = strategy;
            executor.Run();

            //IStrategyTrader trader = executor.StrategyHelper.Trader;

            int             day        = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
            IStrategyResult result     = executor.StrategyResult;
            string          resultName = executor.StrategyResult.Name;

            IStrategyResultStore store     = StrategyCenter.Default.StrategyResultStore;
            IList <int>          savedDays = store.GetAllSavedDays();

            for (int i = 0; i < savedDays.Count; i++)
            {
                Console.Write(savedDays[i] + ",");
            }
            Console.WriteLine();

            IStrategyResult result2 = store.LoadStrategyResult(day, resultName);

            Console.WriteLine(result2);
            Assert.AreEqual(result.ToString(), result2.ToString());

            Assert.AreEqual(1, result2.StrategyResult_Codes.Count);
            Assert.AreEqual(1, result2.StrategyQueryResultManager.GetQueryResults().Count);
            Console.WriteLine(result2.StrategyResult_Codes[0]);
            Assert.AreEqual(result.StrategyResult_Codes[0].ToString(), result2.StrategyResult_Codes[0].ToString());
        }