Beispiel #1
0
        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();
        }
Beispiel #2
0
        public OrderProcessor(SpreadSellSide strategy, ExecutionCommand command)
        {
            strategy.processors.AddLast(this);

            // Init OrderProcessor fields.
            this.strategy    = strategy;
            this.command     = command;
            order            = command.Order;
            spreadInstrument = order.Instrument;
            orders           = new Dictionary <Order, Leg>();

            // Send leg orders if order type is market.
            if (order.Type == OrderType.Market)
            {
                SendLegOrders();
            }
        }
Beispiel #3
0
        public override void Run()
        {
            // Prepare running.
            Console.WriteLine("Prepare running in {0} mode...", StrategyManager.Mode);

            // Get spread instrument.
            Instrument spreadInsturment = InstrumentManager.Get("NG 01-15 vs NG 02-15");

            // Add spread instrument if needed.
            if (spreadInsturment == null)
            {
                spreadInsturment = new Instrument(InstrumentType.Stock, "NG 01-15 vs NG 02-15");
                InstrumentManager.Add(spreadInsturment);
            }

            // Add legs for spread instrument if needed.
            if (spreadInsturment.Legs.Count == 0)
            {
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("NG 01-15"), 1));
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("NG 02-15"), 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.Clear();
            //	BarFactory.Add(spreadInsturment, BarType.Time, barSize);

            // Run.
            Console.WriteLine("Run in {0} mode.", StrategyManager.Mode);
            StartStrategy(StrategyManager.Mode);
        }
Beispiel #4
0
        public override void Run()
        {
            MulticoreOptimizer optimizer = new MulticoreOptimizer(this.framework);


            OptimizationUniverse universe = new OptimizationUniverse();

            for (decimal Delta = 1; Delta < 8; Delta++)
            {
                OptimizationParameterSet parameter = new OptimizationParameterSet();

                parameter.Add("Delta", Delta);

                universe.Add(parameter);
            }
            Instrument spreadInsturment = InstrumentManager.Get("*NG 01-15 vs *NG 02-15");

            // Add spread instrument if needed.
            if (spreadInsturment == null)
            {
                spreadInsturment = new Instrument(InstrumentType.Future, "*NG 01-15 vs *NG 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("*NG 01-15"), 1));
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("*NG 02-15"), 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, 18);            // 1 day before real start
            DataSimulator.DateTime2 = new DateTime(2014, 12, 30);            // 1 day after real end

            InstrumentList instruments = new InstrumentList();

            instruments.Add(spreadInsturment);

            strategy.AddInstruments(instruments);

            //You can choose an optimization method from the "Optimizers" window
            //and observe the optimization results in the "Optimization Results" window.

            //Optimization can use either of two ways to declare parameters:

            //1. Optimization using [OptimizationParameter] atrributes from Strategy

            //Optimize(strategy);

            //2. Optimization via OptimizationUniverse
            optimizer.Optimize(strategy, universe);
        }