示例#1
0
        public void TestExecuteStrategy()
        {
            string            code        = "RB1710";
            int               start       = 20170601;
            int               endDate     = 20170603;
            IDataPackage_Code dataPackage = CommonData.GetDataPackage(code, start, endDate);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UseTickData = false;
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute);
            StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(false, KLinePeriod.KLinePeriod_1Minute);

            StrategyArguments_DataPackage arguments = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);
            IStrategyExecutor_Single      runner    = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(arguments);

            DateTime prevtime = DateTime.Now;

            runner.Strategy    = new MockStrategy(null);
            runner.OnFinished += Runner_OnFinished;
            runner.Execute();
            while (!isFinished)
            {
            }
            DateTime time = DateTime.Now;
            TimeSpan span = time.Subtract(prevtime);

            Console.WriteLine(span.Minutes * 60 + span.Seconds);
        }
示例#2
0
        public void TestRunStrategy_Tick()
        {
            //data.reader.IDataReader dataReader = CommonData.GetDataReader();

            string code    = "RB1710";
            int    start   = 20170601;
            int    endDate = 20170603;

            IDataPackage_Code dataPackage = CommonData.GetDataPackage(code, start, endDate);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UseTickData = true;
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute);
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_5Minute);

            StrategyForwardPeriod         forwardPeriod = new StrategyForwardPeriod(true, KLinePeriod.KLinePeriod_1Minute);
            StrategyArguments_DataPackage arguments     = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);
            IStrategyExecutor_Single      runner        = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(arguments);

            DateTime prevtime = DateTime.Now;

            runner.Strategy = new MockStrategy(referedPeriods);
            runner.Run();

            DateTime time = DateTime.Now;
            TimeSpan span = time.Subtract(prevtime);

            Console.WriteLine(span.Minutes * 60 * 1000 + span.Seconds * 1000 + span.Milliseconds);
        }
示例#3
0
        public void TestRunStrategy_Minute()
        {
            string            code        = "RB1710";
            int               startDate   = 20170301;
            int               endDate     = 20170603;
            IDataPackage_Code dataPackage = CommonData.GetDataPackage(code, startDate, endDate);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UseTickData = false;
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute);
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_5Minute);
            StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(false, KLinePeriod.KLinePeriod_1Minute);

            StrategyArguments_DataPackage strategyDataPackage = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);
            //strategyDataPackage.IsSaveResult = true;
            IStrategyExecutor_Single executor = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(strategyDataPackage);

            IStrategy strategy = StrategyGetter.GetStrategy(typeof(MockStrategy_Simple));

            executor.Strategy = strategy;
            executor.Run();

            Console.WriteLine(executor.StrategyResult);
        }
        public StrategyExecutor_CodePeriod_MainContract(IStrategyCenter strategyCenter, StrategyArguments_CodePeriod strategyArguments) : base(strategyCenter, strategyArguments)
        {
            this.strategyArguments = strategyArguments;
            this.PrepareStrategyHelper();

            IList <ICodePeriod> codePeriods = this.strategyArguments.CodePeriod.Contracts;

            this.dataPackages = new List <IDataPackage_Code>();
            for (int i = 0; i < codePeriods.Count; i++)
            {
                ICodePeriod codePeriod = codePeriods[i];
                this.dataPackages.Add(strategyCenter.BelongDataCenter.DataPackageFactory.CreateDataPackage_Code(codePeriod.Code, codePeriod.StartDate, codePeriod.EndDate));
            }
            this.BuildExecutorInfo();
            for (int i = 0; i < dataPackages.Count; i++)
            {
                IDataPackage_Code dataPackage            = dataPackages[i];
                StrategyHelper    executorStrategyHelper = new StrategyHelper();
                executorStrategyHelper.QueryResultManager = this.strategyHelper.QueryResultManager;
                executorStrategyHelper.Drawer             = null;//TODO
                executorStrategyHelper.Trader             = this.strategyHelper.Trader;

                StrategyArguments_DataPackage strategyArgument = new StrategyArguments_DataPackage(dataPackage, strategyArguments.ReferedPeriods, strategyArguments.ForwardPeriod, executorStrategyHelper);
                StrategyExecutor_DataPackage  executor         = new StrategyExecutor_DataPackage(strategyCenter, strategyArgument, this.strategyExecutorInfo);
                executor.OnBarFinished += Executor_OnBarFinished;
                executor.OnDayFinished += Executor_OnDayFinished;
                this.executors.Add(executor);
            }
        }
示例#5
0
        public static IStrategyExecutor_Single CreateExecutor_DataPackage(string code, int start, int end)
        {
            IStrategyExecutorFactory executorFactory = StrategyCenter.Default.GetStrategyExecutorFactory();
            StrategyReferedPeriods   referedPeriods  = GetReferedPeriods();
            StrategyForwardPeriod    forwardPeriod   = new StrategyForwardPeriod(true, KLinePeriod.KLinePeriod_1Minute);

            IDataPackage_Code             dataPackage        = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end);
            StrategyArguments_DataPackage strategyCodePeriod = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);
            IStrategyExecutor_Single      executor           = executorFactory.CreateExecutor_History(strategyCodePeriod);

            return(executor);
        }
 public StrategyExecutor_DataPackage(IStrategyCenter strategyCenter, StrategyArguments_DataPackage strategyArguments, StrategyExecutorInfo strategyExecutorInfo) : base(strategyCenter, strategyArguments)
 {
     this.dataPackage = strategyArguments.DataPackage;
     this.codePeriod  = new CodePeriod(dataPackage.Code, dataPackage.StartDate, dataPackage.EndDate);
     if (strategyExecutorInfo == null)
     {
         this.InitStrategyExecutorInfo();
     }
     else
     {
         this.strategyExecutorInfo = strategyExecutorInfo;
     }
 }
示例#7
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());
        }
示例#8
0
        private void InitByCodePeriod(IStrategyCenter strategyCenter, StrategyArguments_CodePeriod strategyArguments)
        {
            ICodePeriod codePeriod = strategyArguments.CodePeriod;

            if (codePeriod.IsFromContracts)
            {
                this.strategyExecutor = new StrategyExecutor_CodePeriod_MainContract(strategyCenter, strategyArguments);
            }
            else
            {
                IDataPackage_Code             dataPackage         = strategyCenter.BelongDataCenter.DataPackageFactory.CreateDataPackage_Code(codePeriod.Code, codePeriod.StartDate, codePeriod.EndDate);
                StrategyArguments_DataPackage strategyDataPackage = new StrategyArguments_DataPackage(dataPackage, strategyArguments.ReferedPeriods, strategyArguments.ForwardPeriod);
                this.strategyExecutor = strategyCenter.GetStrategyExecutorFactory().CreateExecutor_History(strategyDataPackage);
            }

            this.strategyExecutor.OnStart       += StrategyExecutor_OnStart;;
            this.strategyExecutor.OnBarFinished += StrategyExecutor_OnBarFinished;
            this.strategyExecutor.OnDayFinished += StrategyExecutor_OnDayFinished;
            this.strategyExecutor.OnCanceled    += StrategyExecutor_OnCanceled;
            this.strategyExecutor.OnFinished    += StrategyExecutor_OnFinished;
        }
        private void ExecuteStrategy_Event(string code, int startDate, int endDate)
        {
            IDataPackage_Code dataPackage = CommonData.GetDataPackage(code, startDate, endDate);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UseTickData = false;
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute);
            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_5Minute);
            StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(false, KLinePeriod.KLinePeriod_1Minute);

            StrategyArguments_DataPackage strategyCodePeriod = new StrategyArguments_DataPackage(dataPackage, referedPeriods, forwardPeriod);
            IStrategyExecutor_Single      executor           = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(strategyCodePeriod);

            executor.OnBarFinished += Executor_OnBarFinished;
            executor.OnDayFinished += Executor_OnDayFinished;
            executor.OnFinished    += Executor_OnFinished;

            IStrategy strategy = StrategyGetter.GetStrategy(typeof(MockStrategy_Empty));

            executor.Strategy = strategy;
            executor.Run();
        }
示例#10
0
 public IStrategyExecutor_Single CreateExecutor_History(StrategyArguments_DataPackage strategyArguments)
 {
     return(new StrategyExecutor_DataPackage(strategyCenter, strategyArguments));
 }
示例#11
0
 public StrategyExecutor_DataPackage(IStrategyCenter strategyCenter, StrategyArguments_DataPackage strategyArguments) : this(strategyCenter, strategyArguments, null)
 {
 }