public void TestStrategyExecute_Multi()
        {
            finishedCount = 0;
            string[]        codes             = new string[] { "rb", "ma", "m", "a", "j", "jd" };
            int             startDate         = 20170101;
            int             endDate           = 20180101;
            ICodePeriodList codePeriodPackage =
                StrategyCenter.Default.BelongDataCenter.CodePeriodFactory.CreateCodePeriodList(codes, startDate, endDate, CodeChooseMethod.Maincontract);

            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_CodePeriodList arguments = new StrategyArguments_CodePeriodList(codePeriodPackage, referedPeriods, forwardPeriod);
            IStrategyExecutor_Multi          executor  = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_Multi_History(arguments);
            IStrategy strategy = StrategyGetter.GetStrategy(typeof(MockStrategy_Event));

            executor.Strategy = strategy;
            executor.OnStrategyDayFinished += Executor_OnStrategyDayFinished;
            executor.OnStrategyFinished    += Executor_OnStrategyFinished;
            executor.Execute();

            StrategyCenter.Default.GetStrategyExecutorPool().ThreadCount      = 2;
            StrategyCenter.Default.GetStrategyExecutorPool().MaxExecutorCount = 3;
            StrategyCenter.Default.GetStrategyExecutorPool().Execute();
            while (finishedCount < 6)
            {
            }
        }
        public IList <IStrategyExecutor_Single> CreateExecutors_History(StrategyArguments_CodePeriodList strategyCodePeriodPackage)
        {
            List <IStrategyExecutor_Single> executors = new List <IStrategyExecutor_Single>();
            List <ICodePeriod> codePeriods            = strategyCodePeriodPackage.CodePeriodPackage.CodePeriods;

            for (int i = 0; i < codePeriods.Count; i++)
            {
                StrategyArguments_CodePeriod argument = new StrategyArguments_CodePeriod(codePeriods[i], strategyCodePeriodPackage.ReferedPeriods, strategyCodePeriodPackage.ForwardPeriod);
                executors.Add(CreateExecutor_History(argument));
            }
            return(executors);
        }
Exemple #3
0
        public void TestExecuteStrategyExecutorPool()
        {
            try
            {
                StrategyExecutorPool pool = (StrategyExecutorPool)StrategyCenter.Default.GetStrategyExecutorPool();
                pool.ThreadCount      = 5;
                pool.MaxExecutorCount = 10;

                pool.OnStrategyStart       += Pool_OnStart;
                pool.OnStrategyDayFinished += Pool_OnDayFinished;
                pool.OnStrategyFinished    += Pool_OnFinished;

                List <string> codes = new List <string>();
                codes.Add("rb");
                codes.Add("m");
                codes.Add("ma");
                codes.Add("i");
                codes.Add("j");
                codes.Add("jd");
                codes.Add("jm");
                codes.Add("p");
                codes.Add("pp");
                StrategyArguments_CodePeriodList strategyCodePeriodPackage = GetStrategyPackage(codes, 20170101, 20170601);

                IList <IStrategyExecutor_Single> executors = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutors_History(strategyCodePeriodPackage);
                for (int i = 0; i < executors.Count; i++)
                {
                    IStrategyExecutor_Single executor = executors[i];
                    executor.Strategy = new MockStrategy_Empty();
                    pool.Queue(executor);
                }

                //pool.Run();
                long startTick = DateTime.Now.Ticks;
                pool.OnPoolFinished += Pool_OnPoolFinished;
                pool.Execute();
                //Thread.Sleep(20000);

                while (!isFinished)
                {
                }
                long endTick = DateTime.Now.Ticks;
                Console.WriteLine(endTick - startTick);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #4
0
        public StrategyExecutor_Multi(IStrategyCenter strategyCenter, StrategyArguments_CodePeriodList arguments)
        {
            this.strategyCenter = strategyCenter;
            this.arguments      = arguments;

            IList <ICodePeriod> codePeriods = this.arguments.CodePeriodPackage.CodePeriods;

            for (int i = 0; i < codePeriods.Count; i++)
            {
                ICodePeriod codePeriod = codePeriods[i];
                StrategyArguments_CodePeriod strategyCodePeriod = new StrategyArguments_CodePeriod(codePeriod, arguments.ReferedPeriods, arguments.ForwardPeriod);
                IStrategyExecutor_Single     executor           = strategyCenter.GetStrategyExecutorFactory().CreateExecutor_History(strategyCodePeriod);
                this.executors.Add(executor);
            }
        }
Exemple #5
0
        private static StrategyArguments_CodePeriodList GetStrategyPackage(List <string> codes, int start, int end)
        {
            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);

            ICodePeriodFactory codePeriodFactory = DataCenter.Default.CodePeriodFactory;
            ICodePeriodList    codePeriodPackage = codePeriodFactory.CreateCodePeriodList(codes, start, end, CodeChooseMethod.Maincontract);
            StrategyArguments_CodePeriodList strategyCodePeriodPackage = new StrategyArguments_CodePeriodList(codePeriodPackage, referedPeriods, forwardPeriod);

            return(strategyCodePeriodPackage);
        }
 public IStrategyExecutor_Multi CreateExecutor_Multi_History(StrategyArguments_CodePeriodList arguments)
 {
     return(new StrategyExecutor_Multi(strategyCenter, arguments));
 }
Exemple #7
0
 public StrategyExecutor_Multi_CodePeriodList(IDataCenter dataCenter, StrategyArguments_CodePeriodList strategyCodePeriodPackage, IStrategyHelper strategyHelper) : this(dataCenter, strategyCodePeriodPackage)
 {
     this.strategyHelper = strategyHelper;
 }
Exemple #8
0
 public StrategyExecutor_Multi_CodePeriodList(IDataCenter dataCenter, StrategyArguments_CodePeriodList strategyCodePeriodPackage)
 {
     this.dataCenter = dataCenter;
     this.strategyCodePeriodPackage = strategyCodePeriodPackage;
 }