Пример #1
0
 public List <IMarketData> GetMarketDataList()
 {
     if (CurrentDataSource == null)
     {
         return(null);
     }
     if (AnalyseType != DistributeAnalyseType.Instrument)
     {
         InstrumentList.Clear();
         SectorList.ForEach(s =>
         {
             InstrumentList.AddRange(Instrument.GetInstrumentBySector(s, AnalyseType));
         });
     }
     return(CurrentDataSource.GetDataList(InstrumentList, StartTime, EndTime, Grade));
 }
Пример #2
0
 public void LoadCurrentInstrumentMarketData(DateTime start, DateTime end)
 {
     if (CurrentInstrument == null)
     {
         return;
     }
     else
     {
         MarketDataList.Clear();
         var ml = CurrentDataSource.GetDataList(new List <IInstrument>()
         {
             CurrentInstrument
         }, start, end, Grade);
         ml.ForEach(v => MarketDataList.Add(v));
     }
 }
Пример #3
0
        public List <Tuple <double, double, double> > Get3DCurve(IInstrument inst)
        {
            var ml = CurrentDataSource.GetDataList(inst, StartTime, EndTime, Grade);

            return(Get3DCurve(GetDistributeDataList(ml)));
        }
Пример #4
0
        public List <Tuple <double, double> > GetDimentionAnalyse(IInstrument inst, bool isAbsolute = false, int n = 20)
        {
            var ml = CurrentDataSource.GetDataList(inst, StartTime, EndTime, Grade);

            return(GetDimentionAnalyse(GetDistributeDataList(ml), isAbsolute, n));
        }
Пример #5
0
        void TestStep(DateTime start, DateTime end)
        {
            TestStrategy.CurrentTime = end;
            AddInfo("test step, start:" + start.ToString() + ",end:" + end.ToString());
            var dl = CurrentDataSource.GetDataList(InstrumentList, start, end, Grade);

            AddInfo("got market data ,count is:" + dl.Count.ToString());
            if (dl == null || dl.Count == 0)
            {
                return;
            }
            TestStrategy.CurrentTime = dl.Max(d => d.Time);
            dl.ForEach(v =>
            {
                var inst = InstrumentList.FirstOrDefault(i => i.Ticker == v.InstrumentTicker);
                if (inst != null)
                {
                    AddInfo("update " + inst.Name + " price, value is:" + v.Close.ToString() + "(" + v.Time.ToString() + ")");
                    inst.CurrentPrice = v.Close;
                }
            });
            MarketDataList.AddRange(dl);
            AddInfo("portfolio process market data!");
            TargetPortfolio.ProcessMarketData(dl);
            AddInfo("standard portfolio process market data!");
            standardPortfolio.ProcessMarketData(dl);
            AddInfo("strategy process market data!");
            TestStrategy.ProcessMarketData(dl);

            if (analyseTime <= end)
            {
                AddInfo("prepare analyse, analyse time is:" + analyseTime.ToString());
                AnalyseStep();
                analyseTime = MarketData.GetNextTime(end, AnalyseGrade);
                var cl = new List <ISignal>();
                foreach (var condition in ConditionList)
                {
                    var rl = condition.GetResult();
                    if (rl != null && rl.Count > 0)
                    {
                        cl.AddRange(rl);
                    }
                }
                if (cl.Count > 0)
                {
                    AddInfo("got signal, count is " + cl.Count.ToString());
                    TestStrategy.ProcessSignal(cl);
                }
            }
            AddInfo("strategy process portfolio");
            TestStrategy.ProcessPortfolio();
            var ol = TestStrategy.GetOrderList();

            if (ol.Count > 0)
            {
                AddInfo("strategy generate order, count is :" + ol.Count.ToString());
                List <IOrder> col = new List <IOrder>();
                foreach (var o in ol)
                {
                    if (o != null && RiskPolicy.PredictOrder(o, TargetPortfolio))
                    {
                        col.Add(o);
                    }
                }
                OrderList.AddRange(col);
                AddInfo("trade gate process order");
                CurrentTradeGate.ProcessorOrder(col);
                AddInfo("portfolio info before process order is" + GetPortfolioMemo(TargetPortfolio));
                TargetPortfolio.ProcessOrderList(col);
                AddInfo("portfolio info after process order is" + GetPortfolioMemo(TargetPortfolio));
            }

            if (!IsUnlimited)//adjust risk
            {
                AddInfo("adjust risk");
                ol = RiskPolicy.AdjustRisk(TargetPortfolio);
                if (ol.Count > 0)
                {
                    AddInfo("risk order generate, count is:" + ol.Count.ToString());
                    OrderList.AddRange(ol);
                    List <IOrder> col = ol.Where(v => v != null).ToList();
                    CurrentTradeGate.ProcessorOrder(col);
                    TargetPortfolio.ProcessOrderList(col);
                }
            }
            CurrentValueList.Add(new TimeValueObject()
            {
                Time = dl.Max(v => v.Time), Value = CurrentValue, Memo = GetPortfolioMemo(TargetPortfolio)
            });
            StandardValueList.Add(new TimeValueObject()
            {
                Time = dl.Max(v => v.Time), Value = StandardValue, Memo = GetPortfolioMemo(standardPortfolio)
            });
            if (_MaxLost.Number > Pnl.Number)
            {
                _MaxLost.Number = Pnl.Number;
            }
            if (TestStepDelayMS > 0)
            {
                Thread.Sleep(TestStepDelayMS);
            }
        }