コード例 #1
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();
        }