示例#1
0
 public StatisticsHelper(Framework framework, SmartQuant.Strategy strategy)
 {
     this.framework     = framework;
     this.strategy      = strategy;
     this.TrailingPrice = new TrailingPrice(framework, strategy);
     this.HighLowPrice  = new HighLowPrice(framework, strategy);
 }
示例#2
0
        public StrategyHelper(Framework framework, SmartQuant.Strategy strategy)
        {
            this.framework = framework;
            this.strategy  = strategy;

            this.DualPositionContainer = new DualPositionContainer(framework);
            this.OpenCloseHelper       = new OpenCloseHelper(framework, strategy);
            this.PositionHelper        = new PositionHelper(framework);

            this.Strategies = new Dictionary <int, InstrumentStrategyHelper>();

            {
                // 创建多空两套持仓,只是显示用,实际上不以此为依据
                Long = new Portfolio(framework, strategy.Name + "_Long");
                framework.PortfolioManager.Add(Long);
                Long.Parent = strategy.Portfolio;

                Short = new Portfolio(framework, strategy.Name + "_Short");
                framework.PortfolioManager.Add(Short);
                Short.Parent = strategy.Portfolio;
            }

            {
                // 在实际下单时需要使用指定所操作的Portfolio
                OpenCloseHelper.Long  = Long;
                OpenCloseHelper.Short = Short;
            }
        }
        public InstrumentStrategyHelper(Framework framework, SmartQuant.Strategy strategy, Instrument instrument)
        {
            this.framework  = framework;
            this.strategy   = strategy;
            this.instrument = instrument;

            this.PriceHelper = new PriceHelper(framework, instrument.TickSize);
            this.TimeHelper  = new TimeHelper(instrument.Symbol);
        }
示例#4
0
文件: Stop.cs 项目: ForTrade/CSharp
 public Stop(Strategy strategy, Position position, DateTime time)
 {
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.instrument;
     this.qty = position.qty;
     this.side = position.Side;
     this.type = StopType.Time;
     this.creationTime = strategy.framework.Clock.DateTime;
     this.completionTime = time;
     this.stopPrice = this.GetInstrumentPrice();
     if (this.completionTime > this.creationTime)
     {
         strategy.framework.Clock.AddReminder(new Reminder(new ReminderCallback(this.OnClock), this.completionTime, null));
     }
 }
示例#5
0
文件: Stop.cs 项目: ForTrade/CSharp
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
 {
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.instrument;
     this.qty = position.qty;
     this.side = position.Side;
     this.level = level;
     this.type = type;
     this.mode = mode;
     this.currPrice = this.GetInstrumentPrice();
     this.trailPrice = this.currPrice;
     this.stopPrice = this.GetStopPrice();
     this.creationTime = strategy.framework.Clock.DateTime;
     this.completionTime = DateTime.MinValue;
     this.Connect();
 }
示例#6
0
		public void Add(Strategy strategy)
		{
			this.strategies.Add(strategy);
			strategy.portfolio.Parent = this.portfolio;
			foreach (Instrument current in strategy.Instruments)
			{
				List<Strategy> list;
				if (this.strategiesByInstrument[current.Id] == null)
				{
					list = new List<Strategy>();
					this.strategiesByInstrument[current.Id] = list;
				}
				else
				{
					list = this.strategiesByInstrument[current.Id];
				}
				list.Add(strategy);
				if (!base.Instruments.Contains(current))
				{
					base.Instruments.Add(current);
				}
			}
		}
示例#7
0
 public void RemoveStrategy(Strategy strategy)
 {
 }
示例#8
0
 public void AddStrategy(Strategy strategy, bool callOnStrategyStart)
 {
     strategy.id = this.framework.strategyManager.GetNextId();
     strategy.parent = this;
     this.strategies.Add(strategy);
     strategy.status = this.status;
     if (this.status == StrategyStatus.Running)
     {
         this.RegisterStrategy(strategy, strategy.instruments, (int)strategy.id);
         if (callOnStrategyStart)
         {
             strategy.OnStrategyStart_();
         }
     }
 }
示例#9
0
 public void AddStrategy(Strategy strategy)
 {
     this.AddStrategy(strategy, true);
 }
示例#10
0
 internal void UnregisterStrategy(Strategy strategy, InstrumentList instruments, int orderRouteId)
 {
     strategy.portfolio.Parent = this.portfolio;
     foreach (Instrument current in instruments)
     {
         LinkedList<Strategy> linkedList = this.strategiesByInstrument[current.Id];
         if (linkedList != null)
         {
             linkedList.Remove(strategy);
         }
         linkedList.Add(strategy);
         IdArray<int> idArray;
         int num;
         (idArray = this.instrumentCountTable)[num = current.id] = idArray[num] - 1;
         if (this.instrumentCountTable[current.id] == 0)
         {
             this.Instruments.Remove(current);
         }
     }
     Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>();
     foreach (Instrument current2 in instruments)
     {
         InstrumentList instrumentList = null;
         IDataProvider key = this.GetDataProvider(strategy, current2);
         if (!dictionary.TryGetValue(key, out instrumentList))
         {
             instrumentList = new InstrumentList();
             dictionary[key] = instrumentList;
         }
         instrumentList.Add(current2);
     }
     foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in dictionary)
     {
         this.framework.strategyManager.UnregisterMarketDataRequest(current3.Key, current3.Value);
     }
     this.strategyByOrderId[orderRouteId] = null;
     if (this.parent != null)
     {
         this.parent.UnregisterStrategy(this, instruments, orderRouteId);
     }
 }
 public StopEx(SmartQuant.Strategy strategy, SmartQuant.Position position, double level, StopType type, StopMode mode, StopIndicator stopIndicator)
     : base(strategy, position, level, type, mode)
 {
     this.indicator = stopIndicator;
 }
示例#12
0
 public void StartStrategy(Strategy strategy)
 {
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy " + this.framework.strategyManager.Mode);
     this.framework.strategyManager.StartStrategy(strategy);
     while (strategy.Status != StrategyStatus.Stopped)
     {
         Thread.Sleep(10);
     }
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy Done");
 }
示例#13
0
        public InstrumentStrategyHelper GetInstrumentStrategyHelper(Instrument instrument, SmartQuant.Strategy strategy)
        {
            InstrumentStrategyHelper value;

            if (!Strategies.TryGetValue(instrument.Id, out value))
            {
                value = new InstrumentStrategyHelper(framework, strategy, instrument);
                value.OpenCloseHelper = OpenCloseHelper;
                Strategies.Add(instrument.Id, value);
            }
            return(value);
        }
示例#14
0
 public TrailingPrice(Framework framework, SmartQuant.Strategy strategy)
 {
     this.framework = framework;
     this.strategy  = strategy;
 }
示例#15
0
 internal IDataProvider GetDataProvider(Strategy strategy, Instrument instrument)
 {
     IDataProvider dataProvider = null;
     if (instrument.DataProvider != null)
     {
         dataProvider = instrument.dataProvider;
     }
     if (dataProvider == null && strategy.DataProvider != null)
     {
         dataProvider = strategy.DataProvider;
     }
     if (this.framework.Mode == FrameworkMode.Simulation)
     {
         if (dataProvider != null && dataProvider is SellSideStrategy)
         {
             return dataProvider;
         }
         return this.framework.providerManager.dataSimulator;
     }
     else
     {
         if (dataProvider != null)
         {
             return dataProvider;
         }
         return this.framework.DataProvider;
     }
 }
示例#16
0
 public OpenCloseHelper(Framework framework, SmartQuant.Strategy strategy)
 {
     this.framework = framework;
     this.strategy  = strategy;
 }
示例#17
0
 public void StartStrategy(Strategy strategy)
 {
     this.StartStrategy(strategy, this.mode);
 }
示例#18
0
 public void StartStrategy(Strategy strategy, StrategyMode mode)
 {
     this.strategy = strategy;
     if (mode == StrategyMode.Backtest)
     {
         this.framework.Mode = FrameworkMode.Simulation;
     }
     else
     {
         this.framework.Mode = FrameworkMode.Realtime;
     }
     if (this.framework.eventManager.status != EventManagerStatus.Running)
     {
         this.framework.eventManager.Start();
     }
     StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started);
     strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name);
     strategyStatusInfo.Mode = mode.ToString();
     this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null));
     strategy.OnStrategyStart_();
     if (!this.framework.IsExternalDataQueue)
     {
         Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>();
         while (this.requests.Count != 0)
         {
             Dictionary<IDataProvider, InstrumentList> dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.requests);
             this.requests.Clear();
             foreach (KeyValuePair<IDataProvider, InstrumentList> current in new Dictionary<IDataProvider, InstrumentList>(dictionary2))
             {
                 InstrumentList instrumentList = null;
                 if (!dictionary.TryGetValue(current.Key, out instrumentList))
                 {
                     instrumentList = new InstrumentList();
                     dictionary[current.Key] = instrumentList;
                 }
                 InstrumentList instrumentList2 = new InstrumentList();
                 foreach (Instrument current2 in current.Value)
                 {
                     if (!instrumentList.Contains(current2))
                     {
                         instrumentList.Add(current2);
                         instrumentList2.Add(current2);
                     }
                 }
                 if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null)
                 {
                     this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2);
                 }
             }
         }
         this.status = StrategyStatus.Running;
         this.requests = dictionary;
         if (this.requests.Count == 0)
         {
             Console.WriteLine(string.Concat(new object[]
             {
                 DateTime.Now,
                 " StrategyManager::StartStrategy ",
                 strategy.Name,
                 " has no data requests, stopping..."
             }));
             this.StopStrategy();
             return;
         }
         foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in this.requests)
         {
             if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null)
             {
                 this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value);
             }
         }
     }
 }
示例#19
0
 internal void RegisterStrategy(Strategy strategy, InstrumentList instruments, int orderRouteId)
 {
     strategy.portfolio.Parent = this.portfolio;
     foreach (Instrument current in instruments)
     {
         LinkedList<Strategy> linkedList;
         if (this.strategiesByInstrument[current.Id] == null)
         {
             linkedList = new LinkedList<Strategy>();
             this.strategiesByInstrument[current.Id] = linkedList;
         }
         else
         {
             linkedList = this.strategiesByInstrument[current.Id];
         }
         linkedList.Add(strategy);
         IdArray<int> idArray;
         int num;
         (idArray = this.instrumentCountTable)[num = current.id] = idArray[num] + 1;
     }
     Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>();
     foreach (Instrument current2 in instruments)
     {
         InstrumentList instrumentList = null;
         IDataProvider dataProvider = this.GetDataProvider(strategy, current2);
         IExecutionProvider executionProvider = strategy.GetExecutionProvider(current2);
         if (dataProvider.Status == ProviderStatus.Disconnected)
         {
             dataProvider.Connect();
         }
         if (executionProvider.Status == ProviderStatus.Disconnected)
         {
             executionProvider.Connect();
         }
         if (!dictionary.TryGetValue(dataProvider, out instrumentList))
         {
             instrumentList = new InstrumentList();
             dictionary[dataProvider] = instrumentList;
         }
         instrumentList.Add(current2);
     }
     foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in dictionary)
     {
         this.framework.strategyManager.RegisterMarketDataRequest(current3.Key, current3.Value);
     }
     this.strategyByOrderId[orderRouteId] = strategy;
     if (this.parent != null)
     {
         this.parent.RegisterStrategy(this, instruments, orderRouteId);
     }
 }
示例#20
0
 public HighLowPrice(Framework framework, SmartQuant.Strategy strategy)
 {
     this.framework = framework;
     this.strategy  = strategy;
 }
 public StopEx(SmartQuant.Strategy strategy, SmartQuant.Position position, DateTime time)
     : base(strategy, position, time)
 {
 }