public override void Run() { Strategy metaStrategy = new Strategy(framework, "MetaStrategy"); Instrument instrument1 = InstrumentManager.Instruments["CSCO"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; MyStrategy strategy = new MyStrategy(framework, "BuySell"); strategy.Instruments.Add(instrument1); strategy.Instruments.Add(instrument2); VWAP_SellSide sellSideStrategy = new VWAP_SellSide(framework, "VWAP SellSide"); strategy.ExecutionProvider = sellSideStrategy; strategy.DataProvider = sellSideStrategy; DataSimulator.DateTime1 = new DateTime(2013, 12, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); BarFactory.Add(instrument1, BarType.Time, 60); BarFactory.Add(instrument2, BarType.Time, 60); metaStrategy.AddStrategy(strategy); metaStrategy.AddStrategy(sellSideStrategy); this.strategy = metaStrategy; StartStrategy(); }
protected override void OnSubscribe(InstrumentList instruments) { // Get size of bar. barSize = (long)Global[barSizeCode]; // Get roll info. rollInfo = (List <RollInfo>)Global[rollInfoCode]; // Get root instrument. rootInstrument = instruments.GetByIndex(0); // Get current futures contract. currentFuturesContract = rootInstrument.Legs[legIndex].Instrument; // Add current futures contract to bar factory. BarFactory.Add(currentFuturesContract, BarType.Time, barSize); // Add current futures contract to strategy. AddInstrument(currentFuturesContract); // Add reminder to maturity date and roll time. AddReminder(rollInfo[legIndex].Maturity.Date + TimeOfRoll); AddGroups(); }
protected override void OnSubscribe(Instrument instrument) { // Get size of bar. barSize = (long)Global[barSizeCode]; // Get spread instrument. spread = instrument; // Add legs instruments to bar factory. foreach (Leg leg in spread.Legs) { BarFactory.Add(leg.Instrument, BarType.Time, barSize); } // Remove instruments from strategy. Instruments.Clear(); // Add legs instruments to strategy. foreach (Leg leg in spread.Legs) { AddInstrument(leg.Instrument); } processors = new System.Collections.Generic.LinkedList <OrderProcessor>(); groups = new Dictionary <Instrument, Group[]>(); AddGroups(); }
protected override void OnReminder(DateTime dateTime, object data) { legIndex++; Position position = Portfolio.GetPosition(currentFuturesContract); double rollAmount = 0; if (position != null) { rollAmount = position.Amount; } if (legIndex > rollInfo.Count - 1) { return; } Instrument prevFuturesContract = currentFuturesContract; // Get new current futures contract. currentFuturesContract = rootInstrument.Legs[legIndex].Instrument; // Add current futures contract to bar factory. BarFactory.Add(currentFuturesContract, BarType.Time, barSize); // Add current futures contract to strategy. AddInstrument(currentFuturesContract); // Add reminder to maturity date and roll time. AddReminder(rollInfo[legIndex].Maturity.AddDays(-1).Date + TimeOfRoll); AddGroups(); // Roll from previous contract to current contract if needed. if (rollAmount > 0) { Order order1 = SellOrder(prevFuturesContract, Math.Abs(rollAmount), "Roll"); Order order2 = BuyOrder(currentFuturesContract, Math.Abs(rollAmount), "Roll"); rollOrders.Add(order1); rollOrders.Add(order2); Send(order1); Send(order2); } else if (rollAmount < 0) { Order order1 = BuyOrder(prevFuturesContract, Math.Abs(rollAmount), "Roll"); Order order2 = SellOrder(currentFuturesContract, Math.Abs(rollAmount), "Roll"); rollOrders.Add(order1); rollOrders.Add(order2); Send(order1); Send(order2); } }
public void SetupDI() { var builder = new ContainerBuilder(); builder.RegisterType <BarDependency>().As <IBarDependency>(); container = builder.Build(); // Tell the factory to resolve all IBarDependencies through our IContainer. BarFactory.SetFactory(() => container.Resolve <IBarDependency>()); }
public override void Run() { var instrument = InstrumentManager.Instruments [symbol]; strategy = new MyStrategy(framework, "SMACrossoverTPSL"); strategy.AddInstrument(instrument); DataSimulator.DateTime1 = new DateTime(2015, 01, 01); DataSimulator.DateTime2 = new DateTime(2015, 12, 31); BarFactory.Add(instrument, BarType.Time, barSize); StartStrategy(); }
public override void Run() { Instrument spreadInsturment = InstrumentManager.Get("NGF 01-15 vs NGG 02-15"); // Add spread instrument if needed. if (spreadInsturment == null) { spreadInsturment = new Instrument(InstrumentType.Synthetic, "NGF 01-15 vs NGG 02-15"); InstrumentManager.Add(spreadInsturment); } spreadInsturment.Legs.Clear(); // Add legs for spread instrument if needed. if (spreadInsturment.Legs.Count == 0) { spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("NGF17after"), 1)); spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("NGG17after"), 1)); } // Main strategy. strategy = new Strategy(framework, "SpreadTrading"); // Create BuySide strategy and add trading instrument. MyStrategy buySide = new MyStrategy(framework, "BuySide"); buySide.Instruments.Add(spreadInsturment); // Create SellSide strategy. SpreadSellSide sellSide = new SpreadSellSide(framework, "SellSide"); sellSide.Global[SpreadSellSide.barSizeCode] = barSize; // Set SellSide as data and execution provider for BuySide strategy. buySide.DataProvider = sellSide; buySide.ExecutionProvider = sellSide; // Add strategies to main. strategy.AddStrategy(buySide); strategy.AddStrategy(sellSide); // Set DataSimulator's dates. DataSimulator.DateTime1 = new DateTime(2014, 11, 23); // 1 day before real start DataSimulator.DateTime2 = new DateTime(2014, 11, 29); // 1 day after real end BarFactory.Clear(); // Run. StartStrategy(); }
public override void Run() { Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; //Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; //Instrument instrument3 = InstrumentManager.Instruments["CSCO_2001"]; //Instrument instrument4 = InstrumentManager.Instruments["IF1409"]; //Instrument instrument5 = InstrumentManager.Instruments["IF999"]; // Create SMA Crossover strategy strategy = new SMACrossoverLoadOnStart_Strategy(framework, "SMACrossover"); //strategy = new DynamicBreakOut2(framework, "DynamicBreakOut2"); //strategy = new DualThrust_RangeBreak_Strategy(framework, "DualThrust_RangeBreak_Strategy"); // Add instruments strategy.AddInstrument(instrument1); //strategy.AddInstrument(instrument2); //strategy.AddInstrument(instrument3); //strategy.AddInstrument(instrument4); //strategy.AddInstrument(instrument5); PbTickDataImport ptdi = new PbTickDataImport(); ptdi.ReadFile(instrument1.Id, @"D:\1.data"); DataSimulator.Series.Add(ptdi.Trades); DataSimulator.SubscribeAll = false; ExecutionSimulator.FillOnBar = true; // Set simulation interval //DataSimulator.DateTime1 = new DateTime(2015, 04, 16); //DataSimulator.DateTime1 = new DateTime(2001, 01, 01); //DataSimulator.DateTime1 = new DateTime(2014, 06, 01); DataSimulator.DateTime1 = new DateTime(2013, 12, 16, 9, 30, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 20, 16, 00, 0); //DataSimulator.DateTime2 = new DateTime(2013, 12, 31); //DataSimulator.DateTime2 = new DateTime(2001, 12, 31); //DataSimulator.DateTime2 = new DateTime(2016, 11, 02); // Add 1 minute bars BarFactory.Add(instrument1, BarType.Time, barSize60); BarFactory.Add(instrument1, BarType.Time, barSize86400); //BarFactory.Add(instrument2, BarType.Time, barSize); //BarFactory.Add(instrument3, BarType.Time, barSize); //BarFactory.Add(instrument4, BarType.Time, barSize60); //BarFactory.Add(instrument4, BarType.Time, barSize86400); //BarFactory.Add(instrument5, SmartQuant.BarType.Time, barSize60); //BarFactory.Add(instrument5, SmartQuant.BarType.Time, barSize86400); // Run the strategy StartStrategy(); }
public override void Run() { Instrument spreadInsturment = InstrumentManager.Get("AAPL vs MSFT"); // Add spread instrument if needed. if (spreadInsturment == null) { spreadInsturment = new Instrument(InstrumentType.Stock, "AAPL vs MSFT"); InstrumentManager.Add(spreadInsturment); } spreadInsturment.Legs.Clear(); // Add legs for spread instrument if needed. if (spreadInsturment.Legs.Count == 0) { spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("AAPL"), 1)); spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("MSFT"), -12)); } // Main strategy. strategy = new Strategy(framework, "SpreadTrading"); // Create BuySide strategy and add trading instrument. MyStrategy buySide = new MyStrategy(framework, "BuySide"); buySide.Instruments.Add(spreadInsturment); // Create SellSide strategy. SpreadSellSide sellSide = new SpreadSellSide(framework, "SellSide"); sellSide.Global[SpreadSellSide.barSizeCode] = barSize; // Set SellSide as data and execution provider for BuySide strategy. buySide.DataProvider = sellSide; buySide.ExecutionProvider = sellSide; // Add strategies to main. strategy.AddStrategy(buySide); strategy.AddStrategy(sellSide); // Set DataSimulator's dates. DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); // Add 1 minute bars (60 seconds) for spread instrument. BarFactory.Add(spreadInsturment, BarType.Time, barSize); // Run. StartStrategy(); }
public QBProvider() { timerConnect.Elapsed += new System.Timers.ElapsedEventHandler(timerConnect_Elapsed); timerAccount.Elapsed += new System.Timers.ElapsedEventHandler(timerAccount_Elapsed); timerPonstion.Elapsed += new System.Timers.ElapsedEventHandler(timerPonstion_Elapsed); InitCallbacks(); InitSettings(); BarFactory = new BarFactory(); status = ProviderStatus.Unknown; ProviderManager.Add(this); }
public override void Run() { // Get synthetic trading instrument. Instrument instrument1 = InstrumentManager.Instruments["NQ"]; // Init roll info - leg index, symbol and maturity date. List <RollInfo> rollInfo = new List <RollInfo>() { new RollInfo(0, "NQZ3", new DateTime(2013, 12, 20)), new RollInfo(1, "NQH4", new DateTime(2014, 03, 21)), }; // Add legs. for (var i = 0; i < rollInfo.Count; i++) { instrument1.Legs.Add(new Leg(InstrumentManager.Instruments[rollInfo[i].Symbol])); } // Main strategy. strategy = new Strategy(framework, "Roll"); // Create BuySide strategy and add trading instrument. MyStrategy buySide = new MyStrategy(framework, "BuySide"); buySide.Instruments.Add(instrument1); // Create SellSide strategy. RollSellSide sellSide = new RollSellSide(framework, "SellSide"); sellSide.Global[RollSellSide.barSizeCode] = barSize; sellSide.Global[RollSellSide.rollInfoCode] = rollInfo; // Set SellSide as data and execution provider for BuySide strategy. buySide.DataProvider = sellSide; buySide.ExecutionProvider = sellSide; // Add strategies to main. strategy.AddStrategy(buySide); strategy.AddStrategy(sellSide); // Set DataSimulator's dates. DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); // Add 4 hours bars (14400 seconds) for ins1. BarFactory.Add(instrument1, BarType.Time, barSize); // Run. StartStrategy(); }
public IQFeedProvider() { iqf = new IQFeed(); //iqf.IQ32DLLPath = "H:\\Program Files\\trading\\DTN\\DTN.IQ\\"; iqf.Messages += new MessageEventHandler(EmitMessage); iqfl2 = new IQFeedLevelII(); BarFactory = new BarFactory(); htL1WatchedSymbols = new Hashtable(); htL2WatchedSymbols = new Hashtable(); ProviderManager.Add(this); }
public override void Run() { strategy = new MyStrategy(framework, "ComponentStrategy"); Instrument instrument = InstrumentManager.Instruments["AAPL"]; strategy.AddInstrument(instrument); //DataSimulator.DateTime1 = new DateTime(2012, 12, 03); //DataSimulator.DateTime2 = new DateTime(2013, 12, 04); BarFactory.Add(instrument, BarType.Time, 60); StartStrategy(); }
public override void Run() { // Prepare running. Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode); // Get trading instruments. Instrument ins1 = InstrumentManager.Instruments["AAPL"]; // Create SMA Crossover with Loading data on start strategy. // and add trading instruments. SMACrossoverLoadOnStart_Strategy smaCrossoverLOS = new SMACrossoverLoadOnStart_Strategy(framework, "SMACrossoverLOS"); smaCrossoverLOS.Instruments.Add(ins1); // Set strategy as main. strategy = smaCrossoverLOS; Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode); // Set DataSimulator's dates. DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 18); // Set property for suspend trading during simulation. SMACrossoverLoadOnStart_Strategy.SuspendTrading = true; // Add 5 minute bars (300 seconds) for trading instruments. BarFactory.Add(ins1, SmartQuant.BarType.Time, barSize); StartStrategy(StrategyMode.Backtest); DataSimulator.DateTime1 = new DateTime(2013, 12, 18); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); // Set property for trading. SMACrossoverLoadOnStart_Strategy.SuspendTrading = false; // Run. Console.WriteLine("Run in {0} mode.", framework.StrategyManager.Mode); StartStrategy(StrategyMode.Backtest); return; }
public override void Run() { Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; strategy = new MyStrategy(framework, "BollingerBands"); strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); strategy.DataProvider = ProviderManager.GetDataProvider("QuantRouter"); strategy.ExecutionProvider = ProviderManager.GetExecutionProvider("QuantRouter"); BarFactory.Add(instrument1, BarType.Time, barSize); BarFactory.Add(instrument2, BarType.Time, barSize); StartStrategy(); }
public override void Run() { // Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; strategy = new MyStrategy(framework, "BollingerBands"); // strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 17); // BarFactory.Add(instrument1, BarType.Time, barSize); BarFactory.Add(instrument2, BarType.Time, barSize); StartStrategy(); }
public override void Run() { Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; strategy = new Turtles(framework, "Turtles"); strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); BarFactory.Add(instrument1, BarType.Time, barSize); BarFactory.Add(instrument2, BarType.Time, barSize); StartStrategy(); }
public override void Run() { Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; strategy = new MyStrategy(framework, "RSI"); strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); strategy.DataProvider = ProviderManager.GetDataProvider("QuantRouter"); strategy.ExecutionProvider = ProviderManager.GetExecutionProvider("QuantRouter"); DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); BarFactory.Add(instrument1, BarType.Time, barSize); BarFactory.Add(instrument2, BarType.Time, barSize); StartStrategy(); }
public override void Run() { //Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; //Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; //Instrument instrument3 = InstrumentManager.Instruments["IF1412_TB"]; Instrument instrument4 = InstrumentManager.Instruments["IF999"]; // Create SMA Crossover strategy strategy = new BIAS_Strategy(framework, "BIAS"); //strategy = new KaufmanAMA_Strategy(framework, "KaufmanAMA"); //strategy = new KDJ_Strategy(framework, "KDJ"); //strategy = new LookBackDays_Strategy(framework, "LookBackDays"); //strategy = new DPO1_Strategy(framework, "DPO1"); //strategy = new PC_Strategy(framework, "PC"); // Add instruments //strategy.AddInstrument(instrument1); //strategy.AddInstrument(instrument2); //strategy.AddInstrument(instrument3); strategy.AddInstrument(instrument4); // Set simulation interval //DataSimulator.DateTime1 = new DateTime(2013, 01, 01); //DataSimulator.DateTime1 = new DateTime(2014, 11, 27); DataSimulator.DateTime1 = new DateTime(2015, 04, 16); //DataSimulator.DateTime2 = new DateTime(2013, 12, 16, 9, 36, 0); //DataSimulator.DateTime2 = new DateTime(2013, 12, 31); //DataSimulator.DateTime2 = new DateTime(2014, 11, 28); DataSimulator.DateTime2 = new DateTime(2016, 11, 02); // Add 1 minute bars //BarFactory.Add(instrument1, BarType.Time, barSize); //BarFactory.Add(instrument2, BarType.Time, barSize); //BarFactory.Add(instrument3, BarType.Time, barSize); BarFactory.Add(instrument4, SmartQuant.BarType.Time, barSize); // Run the strategy StartStrategy(); }
public void ReturnInstanceOfType() { var name = "Bar"; var imageUrl = "www.test.com"; var phoneNum = "33333"; var address = new AddressDTO { CityId = 1, Name = "Address", Latitude = 1.0, Longitude = 1.0, }; var sut = new BarFactory(); var bar = sut.Create(name, imageUrl, phoneNum, address); Assert.IsInstanceOfType(bar, typeof(Bar)); Assert.AreEqual(name, bar.Name); Assert.AreEqual(imageUrl, bar.ImagePath); Assert.AreEqual(phoneNum, bar.PhoneNumber); }
public override void Run() { StatisticsManager.Add(new DailyNumOfLossTrades()); StatisticsManager.Add(new DailyNumOfWinTrades()); StatisticsManager.Add(new DailyConsecutiveLossTrades()); Instrument instrument1 = InstrumentManager.Instruments["IF999"]; Instrument instrument2 = InstrumentManager.Instruments["IC999"]; // Create SMA Crossover strategy //DualThrust_RangeBreak_Strategy strategy = new DualThrust_RangeBreak_Strategy(framework, "DualThrust & RangeBreak"); //RBreaker_Strategy strategy = new RBreaker_Strategy(framework, "RBreaker"); //DynamicBreakOut2 strategy = new DynamicBreakOut2(framework, "DynamicBreakOut2"); DoubleMA_Crossover strategy = new DoubleMA_Crossover(framework, "DoubleMA Crossover"); strategy.MaxBarSize = MaxBarSize; // Add instruments strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); // Set simulation interval DataSimulator.DateTime1 = new DateTime(2015, 04, 16); //DataSimulator.DateTime2 = new DateTime(2013, 12, 16, 9, 36, 0); DataSimulator.DateTime2 = new DateTime(2016, 11, 02); // Add 1 minute bars BarFactory.Add(instrument1, SmartQuant.BarType.Time, barSize); BarFactory.Add(instrument2, SmartQuant.BarType.Time, barSize); BarFactory.Add(instrument1, SmartQuant.BarType.Time, MaxBarSize); BarFactory.Add(instrument2, SmartQuant.BarType.Time, MaxBarSize); this.strategy = strategy; // Run the strategy StartStrategy(); }
public override void Run() { StrategyMode sm = StrategyMode.Backtest; bool isTest = false; if (isTest) { Instrument instrument1 = InstrumentManager.Instruments["AAPL"]; Instrument instrument2 = InstrumentManager.Instruments["MSFT"]; strategy = new Strategy_BB(framework, "BollingerBands"); sm = StrategyMode.Backtest; strategy.AddInstrument(instrument1); strategy.AddInstrument(instrument2); DataSimulator.DateTime1 = new DateTime(2013, 01, 01); DataSimulator.DateTime2 = new DateTime(2013, 12, 31); BarFactory.Add(instrument1, BarType.Time, barSize); BarFactory.Add(instrument2, BarType.Time, barSize); } else { IDataProvider dataProvider = null; IExecutionProvider executionProvider = null; OQFunc.UserInputProviderId(out dataProvider, out executionProvider, this.ProviderManager); Instrument instrument3 = OQFunc.UserInputInstrument(this.InstrumentManager); strategy = new Strategy_BB(framework, "BollingerBands"); sm = StrategyMode.Live; strategy.DataProvider = dataProvider; strategy.ExecutionProvider = executionProvider; strategy.AddInstrument(instrument3); } StartStrategy(sm); }
public override void Run() { // Prepare running. Console.WriteLine("Prepare running in {0} mode...", StrategyManager.Mode); // Get spread instrument. Instrument spreadInsturment = InstrumentManager.Get("AAPL vs MSFT"); // Add spread instrument if needed. if (spreadInsturment == null) { spreadInsturment = new Instrument(InstrumentType.Stock, "AAPL vs MSFT"); InstrumentManager.Add(spreadInsturment); } // Add legs for spread instrument if needed. if (spreadInsturment.Legs.Count == 0) { spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("AAPL"), 1)); spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("MSFT"), -1)); } // Main strategy. strategy = new Strategy(framework, "SpreadTrading"); // Create BuySide strategy and add trading instrument. MyStrategy buySide = new MyStrategy(framework, "BuySide"); buySide.Instruments.Add(spreadInsturment); // Create SellSide strategy. SpreadSellSide sellSide = new SpreadSellSide(framework, "SellSide"); sellSide.Global[SpreadSellSide.barSizeCode] = barSize; // Set SellSide as data and execution provider for BuySide strategy. buySide.DataProvider = sellSide; buySide.ExecutionProvider = sellSide; // Add strategies to main. strategy.AddStrategy(buySide); strategy.AddStrategy(sellSide); // Get provider for realtime. Provider quantRouter = ProviderManager.Providers["QuantRouter"] as Provider; if (quantRouter.Status == ProviderStatus.Disconnected) { quantRouter.Connect(); } if (StrategyManager.Mode == StrategyMode.Paper) { // Set QuantRouter as data provider. sellSide.DataProvider = quantRouter as IDataProvider; } else if (StrategyManager.Mode == StrategyMode.Live) { // Set QuantRouter as data and execution provider. sellSide.DataProvider = quantRouter as IDataProvider; sellSide.ExecutionProvider = quantRouter as IExecutionProvider; } // Set null for event filter. EventManager.Filter = null; // Add 1 minute bars (60 seconds) for spread instrument. BarFactory.Add(spreadInsturment, BarType.Time, barSize); // Run. Console.WriteLine("Run in {0} mode.", StrategyManager.Mode); StartStrategy(StrategyManager.Mode); }
public override void Run() { StatisticsManager.Add(new DailyNumOfLossTrades()); StatisticsManager.Add(new DailyNumOfWinTrades()); StatisticsManager.Add(new DailyConsecutiveLossTrades()); Instrument instrument1 = InstrumentManager.Instruments["IF999"]; Instrument instrument2 = InstrumentManager.Instruments["IC999"]; // Create SMA Crossover strategy //DualThrust_RangeBreak_Strategy strategy = new DualThrust_RangeBreak_Strategy(framework, "DualThrust & RangeBreak"); //RBreaker_Strategy strategy = new RBreaker_Strategy(framework, "RBreaker"); //DynamicBreakOut2 strategy = new DynamicBreakOut2(framework, "DynamicBreakOut2"); DoubleMA_Crossover strategy = new DoubleMA_Crossover(framework, "DoubleMA Crossover"); strategy.MaxBarSize = MaxBarSize; // Add instruments strategy.AddInstrument(instrument1); //strategy.AddInstrument(instrument2); // Set simulation interval DataSimulator.DateTime1 = new DateTime(2015, 04, 16); //DataSimulator.DateTime2 = new DateTime(2013, 12, 16, 9, 36, 0); DataSimulator.DateTime2 = new DateTime(2016, 11, 02); // Add 1 minute bars BarFactory.Add(instrument1, SmartQuant.BarType.Time, barSize); //BarFactory.Add(instrument2, SmartQuant.BarType.Time, barSize); BarFactory.Add(instrument1, SmartQuant.BarType.Time, MaxBarSize); //BarFactory.Add(instrument2, SmartQuant.BarType.Time, MaxBarSize); this.strategy = strategy; Provider quantRouter = framework.ProviderManager.GetProvider(99) as Provider; if (quantRouter.Status == ProviderStatus.Disconnected) { quantRouter.Connect(); } while (!quantRouter.IsConnected) { Thread.Sleep(1000); } if (framework.StrategyManager.Mode == StrategyMode.Paper) { // Set QuantRouter as data provider. strategy.DataProvider = quantRouter as IDataProvider; } else if (framework.StrategyManager.Mode == StrategyMode.Live) { // Set QuantRouter as data and execution provider. strategy.DataProvider = quantRouter as IDataProvider; strategy.ExecutionProvider = quantRouter as IExecutionProvider; } // Run the strategy StartStrategy(); }
public static void AddQBTimeBar(this BarFactory factory, Instrument inst, long barSize) { var barItem = new QBTimeBarFactoryItem(inst, barSize); factory.Add(barItem); }
public override void Run() { // Prepare running. Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode); // Get trading instruments. Instrument ins1 = InstrumentManager.Instruments["IF1612"]; // Create SMA Crossover with Loading data on start strategy. // and add trading instruments. DoubleMA_Crossover smaCrossoverLOS = new DoubleMA_Crossover(framework, "SMACrossoverLOS"); smaCrossoverLOS.Instruments.Add(ins1); // Set strategy as main. strategy = smaCrossoverLOS; Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode); // 开始时间是前一个交易日,这个地方要按自己策略的实际情况进行调整 DateTime startDate = DateTime.Now.DayOfWeek == DayOfWeek.Monday ? DateTime.Now.AddDays(-3).Date : DateTime.Now.AddDays(-1).Date; DateTime historicalData1EndTime = startDate; // 取本地的数据的最后时间 DataSeries ins1DataSeries = framework.DataManager.GetDataSeries(ins1, DataObjectType.Trade); if (ins1DataSeries != null && ins1DataSeries.Count > 0) { historicalData1EndTime = ins1DataSeries.DateTime2; } // 以两个时间的最大值为起点 historicalData1EndTime = new DateTime(Math.Max(historicalData1EndTime.Ticks, startDate.Ticks)); // Load and save historical trades from QuantBase provider. IHistoricalDataProvider quantBase = framework.ProviderManager.GetHistoricalDataProvider(94); if (quantBase.Status == ProviderStatus.Disconnected) { quantBase.Connect(); } // 等待连接成功,订阅太快了不行 while (!quantBase.IsConnected) { Thread.Sleep(1000); } // Load historical trades. Console.WriteLine("Load historical data."); TickSeries ins1TickSeries = framework.DataManager.GetHistoricalTrades(quantBase, ins1, historicalData1EndTime, DateTime.Now); Console.WriteLine("Save historical data."); // Save historical trades. foreach (Trade trade in ins1TickSeries) { framework.DataManager.Save(ins1, trade); } // Set DataSimulator's dates. DataSimulator.DateTime1 = startDate; DataSimulator.DateTime2 = DateTime.Now; // Set null for event filter. framework.EventManager.Filter = null; // Set property for suspend trading during simulation. DoubleMA_Crossover.SuspendTrading = true; // Add 5 minute bars (300 seconds) for trading instruments. BarFactory.Add(ins1, SmartQuant.BarType.Time, barSize); // Run in simulation. Console.WriteLine("Run in Backtest mode."); // Save current strategy mode. StrategyMode mode = framework.StrategyManager.Mode; // Set backtest mode. framework.StrategyManager.Mode = StrategyMode.Backtest; StartStrategy(StrategyMode.Backtest); // Run. Console.WriteLine("Run in {0} mode.", framework.StrategyManager.Mode); // Restore strategy mode. framework.StrategyManager.Mode = mode; // Get provider for realtime. Provider quantRouter = framework.ProviderManager.GetProvider(99) as Provider; if (quantRouter.Status == ProviderStatus.Disconnected) { quantRouter.Connect(); } while (!quantRouter.IsConnected) { Thread.Sleep(1000); } // Set property for trading. DoubleMA_Crossover.SuspendTrading = false; if (framework.StrategyManager.Mode == StrategyMode.Paper) { // Set QuantRouter as data provider. strategy.DataProvider = quantRouter as IDataProvider; } else if (framework.StrategyManager.Mode == StrategyMode.Live) { // Set QuantRouter as data and execution provider. strategy.DataProvider = quantRouter as IDataProvider; strategy.ExecutionProvider = quantRouter as IExecutionProvider; } StartStrategy(framework.StrategyManager.Mode); }
public void ExecuteSave() { var barFactory = new BarFactory(); IBarDependency bar = barFactory.CreateBar(); }
public override void Run() { // Synthetic instrument. Instrument instrument1 = InstrumentManager.Instruments["NQ"]; // Init roll info - leg index, symbol and maturity date. List <RollInfo> rollInfo = new List <RollInfo>() { new RollInfo(0, "NQZ3", new DateTime(2013, 12, 20)), new RollInfo(1, "NQH4", new DateTime(2014, 03, 21)), }; // Add legs. for (var i = 0; i < rollInfo.Count; i++) { instrument1.Legs.Add(new Leg(InstrumentManager.Instruments[rollInfo[i].Symbol])); } // Main strategy. strategy = new Strategy(framework, "Roll"); // Create BuySide strategy and add trading instrument. MyStrategy buySide = new MyStrategy(framework, "BuySide"); buySide.Instruments.Add(instrument1); // Create SellSide strategy. RollSellSide sellSide = new RollSellSide(framework, "SellSide"); sellSide.Global[RollSellSide.barSizeCode] = barSize; sellSide.Global[RollSellSide.rollInfoCode] = rollInfo; // Set SellSide as data and execution provider for BuySide strategy. buySide.DataProvider = sellSide; buySide.ExecutionProvider = sellSide; // Add strategies to main. strategy.AddStrategy(buySide); strategy.AddStrategy(sellSide); // Get provider for realtime. Provider quantRouter = framework.ProviderManager.Providers["QuantRouter"] as Provider; if (quantRouter.Status == ProviderStatus.Disconnected) { quantRouter.Connect(); } if (StrategyManager.Mode == StrategyMode.Paper) { // Set QuantRouter as data provider. strategy.DataProvider = quantRouter as IDataProvider; } else if (StrategyManager.Mode == StrategyMode.Live) { // Set QuantRouter as data and execution provider. strategy.DataProvider = quantRouter as IDataProvider; strategy.ExecutionProvider = quantRouter as IExecutionProvider; } BarFactory.Add(instrument1, BarType.Time, barSize); // Run. StartStrategy(); }