示例#1
0
        public override object Clone()
        {
            var p = new BacktestingProject()
            {
                Name              = Name,
                Memo              = Memo,
                IsUnlimited       = IsUnlimited,
                AnalyseGrade      = AnalyseGrade,
                AnalyseStartTime  = AnalyseStartTime,
                CurrentDataSource = CurrentDataSource.Clone() as IDataSource,
                CurrentTradeGate  = CurrentTradeGate,
                Fine              = Fine,
                Grade             = Grade,
                ProjectStartTime  = ProjectStartTime,
                RiskPolicy        = RiskPolicy.Clone() as IRiskControl,
                Status            = Status,
                TargetPortfolio   = TargetPortfolio.Clone() as IPortfolio,
                TestStrategy      = TestStrategy.Clone() as IStrategy,
                TestCurrentTime   = TestCurrentTime,
                TestEndTime       = TestEndTime,
                TestStartTime     = TestStartTime,
                TestStepDelayMS   = TestStepDelayMS,
            };

            ConditionList.ForEach(v => p.ConditionList.Add(v.Clone() as ICondition));
            InstrumentList.ForEach(v => p.InstrumentList.Add(v.Clone() as IInstrument));

            return(p);
        }
示例#2
0
        public override void PrepareWork()
        {
            TargetPortfolio.PrepareWork();
            MarketDataList.Clear();
            CurrentDataSource.DataList.Clear();
            CurrentValueList.Clear();
            StandardValueList.Clear();
            OrderList.Clear();

            DateTime st = TestStartTime;

            if (TestStartTime > AnalyseStartTime)
            {
                st = AnalyseStartTime;
            }
            CurrentDataSource.CacheStartTime = st;
            CurrentDataSource.CacheEndTime   = TestEndTime;

            TestCurrentTime = TestStartTime;
            analyseTime     = MarketData.GetNextTime(TestCurrentTime, AnalyseGrade);

            _MaxLost = new Money()
            {
                FxCode = Pnl.FxCode, Number = 0
            };
            if (UseFirstMarketDataInit)
            {
                var fdl = new List <IMarketData>();
                InstrumentList.ForEach(v =>
                {
                    var d = CurrentDataSource.GetFirstData(v, TestStartTime, TestEndTime, Grade);
                    if (d != null)
                    {
                        fdl.Add(d);
                    }
                });
                TargetPortfolio.ProcessMarketData(fdl);
                TargetPortfolio.PositionList.ForEach(v =>
                {
                    var d = fdl.FirstOrDefault(m => m.InstrumentTicker == v.InstrumentTicker);
                    if (d != null)
                    {
                        v.Cost = d.Close;
                    }
                });
            }
            if (IsUnlimited)
            {
                TargetPortfolio.IsUnlimited = true;
            }
            standardPortfolio = TargetPortfolio.Clone() as IPortfolio;
            testStartValue    = TargetPortfolio.CurrentValue;
            CurrentDataSource.PrepareWork();
            CurrentTradeGate.PrepareWork();
            foreach (var condition in ConditionList)
            {
                condition.PrepareWork();
                condition.GetInstrumentList = () => { return(InstrumentList); };
                condition.AnalyseDataSource = CurrentDataSource;
            }

            TestStrategy.CurrentPortfolio = TargetPortfolio;
            TestStrategy.PrepareWork();
            RiskPolicy.PrepareWork();
        }