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);
            }
        }
Example #2
0
        public void TestStrategyResult_CodePeriod_MainContract()
        {
            string      code       = "RB";
            int         startDate  = 20170101;
            int         endDate    = 20180101;
            ICodePeriod codePeriod = DataCenter.Default.CodePeriodFactory.CreateCodePeriod_MainContract(code, startDate, endDate);

            StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods();

            referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_15Minute);
            referedPeriods.UseTickData = true;
            StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(true, KLinePeriod.KLinePeriod_15Minute);

            StrategyArguments_CodePeriod arguments = new StrategyArguments_CodePeriod(codePeriod, referedPeriods, forwardPeriod);

            arguments.IsSaveResult = true;
            IStrategyExecutor_Single executor = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(arguments);

            //IStrategy strategy = StrategyGetter.GetStrategy(typeof(MockStrategy_Simple));
            MockStrategy_Results strategy = new MockStrategy_Results();

            strategy.Name     = "策略结果保存";
            executor.Strategy = strategy;
            executor.Run();
        }
Example #3
0
        public void TestStrategyExecutorEvent_CodePeriod1()
        {
            string      code       = "RB";
            int         startDate  = 20170101;
            int         endDate    = 20180101;
            ICodePeriod codePeriod = DataCenter.Default.CodePeriodFactory.CreateCodePeriod_MainContract(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);
            StrategyArguments_CodePeriod strategyCodePeriod = new StrategyArguments_CodePeriod(codePeriod, 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();
        }
Example #4
0
 public StrategyResult_CodePeriod(ICodePeriod codePeriod, StrategyForwardPeriod forwardPeriod, StrategyReferedPeriods referedPeriods, IStrategyDrawer strategyDrawer, IStrategyTrader strategyTrader)
 {
     this.codePeriod     = codePeriod;
     this.forwardPeriod  = forwardPeriod;
     this.referedPeriods = referedPeriods;
     this.strategyDrawer = strategyDrawer;
     this.strategyTrader = strategyTrader;
 }
Example #5
0
 /// <summary>
 /// 得到指定代码周期的运行结果
 /// </summary>
 /// <param name="codePeriod"></param>
 /// <returns></returns>
 public IStrategyResult_CodePeriod GetStrategyResult_Code(ICodePeriod codePeriod)
 {
     if (dic_CodePeriod_StrategyResult_CodePeriods.ContainsKey(codePeriod))
     {
         return(dic_CodePeriod_StrategyResult_CodePeriods[codePeriod]);
     }
     return(null);
 }
        private void BuildExecutorInfo()
        {
            ICodePeriod codePeriod = strategyArguments.CodePeriod;
            int         totalDays  = 0;

            for (int i = 0; i < dataPackages.Count; i++)
            {
                totalDays += dataPackages[i].GetTradingDays().Count;
            }
            this.strategyExecutorInfo = new StrategyExecutorInfo(codePeriod, totalDays);
        }
 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;
     }
 }
Example #8
0
        private ICodePeriod GetCodePackage_MainContract(string variety, int start, int end)
        {
            List <MainContractInfo> contractInfos = dataReader.MainContractReader.GetMainContractInfos(variety, start, end);
            List <ICodePeriod>      mainContracts = new List <ICodePeriod>();

            for (int i = 0; i < contractInfos.Count; i++)
            {
                MainContractInfo mainContractInfo = contractInfos[i];
                ICodePeriod      codePeriod       = CreateCodePeriod(mainContractInfo.Code, mainContractInfo.Start, mainContractInfo.End);
                mainContracts.Add(codePeriod);
            }
            return(CreateCodePeriod_MainContract(variety, start, end, mainContracts));
        }
Example #9
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Code + "," + StartDate + "," + EndDate);
            if (isFromContract)
            {
                for (int i = 0; i < Contracts.Count; i++)
                {
                    ICodePeriod codePeriod = Contracts[i];
                    sb.Append("\r\n").Append(codePeriod);
                }
            }
            return(sb.ToString());
        }
Example #10
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);
            }
        }
Example #11
0
        public override int GetHashCode()
        {
            int hash = Code.GetHashCode();

            hash = hash * 10 + startDate;
            hash = hash * 10 + endDate;
            if (isFromContract)
            {
                for (int i = 0; i < Contracts.Count; i++)
                {
                    ICodePeriod codePeriod = Contracts[i];
                    hash = hash * 10 + codePeriod.GetHashCode();
                }
            }
            return(hash);
        }
Example #12
0
        private void LoadMain(XmlElement xmlElem)
        {
            XmlElement elemCodePeriod = (XmlElement)xmlElem.GetElementsByTagName("codeperiod")[0];

            codePeriod = new CodePeriod();
            codePeriod.Load(elemCodePeriod);

            XmlElement elemForwardPeriod = (XmlElement)xmlElem.GetElementsByTagName("forwardperiod")[0];

            forwardPeriod = new StrategyForwardPeriod();
            forwardPeriod.Load(elemForwardPeriod);

            XmlElement elemReferedPeriods = (XmlElement)xmlElem.GetElementsByTagName("referedperiods")[0];

            referedPeriods = new StrategyReferedPeriods();
            referedPeriods.Load(elemReferedPeriods);
        }
Example #13
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;
        }
 public StrategyArguments_CodePeriod(ICodePeriod codePeriod, StrategyReferedPeriods referedPeriods, StrategyForwardPeriod forwardPeriod, StrategyTraderSetting traderSetting) : this(codePeriod, referedPeriods, forwardPeriod)
 {
     this.TraderSetting = traderSetting;
 }
 public StrategyArguments_CodePeriod(ICodePeriod codePeriod, StrategyReferedPeriods referedPeriods, StrategyForwardPeriod forwardPeriod)
 {
     this.codePeriod     = codePeriod;
     this.ReferedPeriods = referedPeriods;
     this.ForwardPeriod  = forwardPeriod;
 }
Example #16
0
 /// <summary>
 /// 创建一个历史数据回测执行器
 /// </summary>
 /// <param name="codePeriod"></param>
 /// <returns></returns>
 public IStrategyExecutor CreateExecutor_History(ICodePeriod codePeriod)
 {
     return(null);
 }
Example #17
0
 public StrategyExecutorInfo(ICodePeriod codePeriod, int totalDayCount)
 {
     this.codePeriod    = codePeriod;
     this.totalDayCount = totalDayCount;
 }
Example #18
0
 public StrategyExecutorInfo_CodePeriod(IStrategyExecutor executor, ICodePeriod codePeriod)
 {
     this.executor   = executor;
     this.codePeriod = codePeriod;
 }
Example #19
0
 public StrategyResult_CodePeriod(ICodePeriod codePeriod, StrategyForwardPeriod forwardPeriod, StrategyReferedPeriods referedPeriods)
 {
     this.codePeriod     = codePeriod;
     this.forwardPeriod  = forwardPeriod;
     this.referedPeriods = referedPeriods;
 }