Beispiel #1
0
        /// <summary>
        /// Submit orders for the specified portolio targets if the spread is tighter/equal to preset level
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets to be ordered</param>
        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            // update the complete set of portfolio targets with the new targets
            _targetsCollection.AddRange(targets);

            // for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call
            if (_targetsCollection.Count > 0)
            {
                foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm))
                {
                    var symbol = target.Symbol;
                    // calculate remaining quantity to be ordered
                    var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                    if (unorderedQuantity != 0)
                    {
                        // get security object
                        var security = algorithm.Securities[symbol];

                        // check order entry conditions
                        if (PriceIsFavorable(security))
                        {
                            algorithm.MarketOrder(symbol, unorderedQuantity);
                        }
                    }
                }

                _targetsCollection.ClearFulfilled(algorithm);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Submit orders for the specified portolio targets.
        /// This model is free to delay or spread out these orders as it sees fit
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets to be ordered</param>
        public void Execute(QCAlgorithmFramework algorithm, IEnumerable <IPortfolioTarget> targets)
        {
            // update the complete set of portfolio targets with the new targets
            _targetsCollection.AddRange(targets);

            foreach (var target in _targetsCollection)
            {
                var symbol = target.Symbol;

                // calculate remaining quantity to be ordered
                var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                // fetch our symbol data containing our VWAP indicator
                SymbolData data;
                if (!_symbolData.TryGetValue(symbol, out data))
                {
                    continue;
                }

                // ensure we're receiving price data before submitting orders
                if (data.Security.Price == 0m)
                {
                    continue;
                }

                // check order entry conditions
                if (PriceIsFavorable(data, unorderedQuantity))
                {
                    // get the maximum order size based on a percentage of current volume
                    var maxOrderSize = OrderSizing.PercentVolume(data.Security, MaximumOrderQuantityPercentVolume);
                    var orderSize    = Math.Min(maxOrderSize, Math.Abs(unorderedQuantity));

                    // round down to even lot size
                    orderSize -= orderSize % data.Security.SymbolProperties.LotSize;
                    if (orderSize != 0)
                    {
                        algorithm.MarketOrder(data.Security.Symbol, Math.Sign(unorderedQuantity) * orderSize);
                    }
                }

                // check to see if we're done with this target
                unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);
                if (unorderedQuantity == 0m)
                {
                    _targetsCollection.Remove(target.Symbol);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Executes market orders if the standard deviation of price is more than the configured number of deviations
        /// in the favorable direction.
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets</param>
        public override void Execute(QCAlgorithmFramework algorithm, IPortfolioTarget[] targets)
        {
            _targetsCollection.AddRange(targets);

            foreach (var target in _targetsCollection)
            {
                var symbol = target.Symbol;

                // calculate remaining quantity to be ordered
                var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                // fetch our symbol data containing our STD/SMA indicators
                SymbolData data;
                if (!_symbolData.TryGetValue(symbol, out data))
                {
                    continue;
                }

                // ensure we're receiving price data before submitting orders
                if (data.Security.Price == 0m)
                {
                    continue;
                }

                // check order entry conditions
                if (data.STD.IsReady && PriceIsFavorable(data, unorderedQuantity))
                {
                    // get the maximum order size based on total order value
                    var maxOrderSize = OrderSizing.Value(data.Security, MaximumOrderValue);
                    var orderSize    = Math.Min(maxOrderSize, Math.Abs(unorderedQuantity));

                    // round down to even lot size
                    orderSize -= orderSize % data.Security.SymbolProperties.LotSize;
                    if (orderSize != 0)
                    {
                        algorithm.MarketOrder(symbol, Math.Sign(unorderedQuantity) * orderSize);
                    }
                }

                // check to see if we're done with this target
                unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);
                if (unorderedQuantity == 0m)
                {
                    _targetsCollection.Remove(target.Symbol);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Immediately submits orders for the specified portfolio targets.
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets to be ordered</param>
        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            _targetsCollection.AddRange(targets);
            // for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call
            if (_targetsCollection.Count > 0)
            {
                foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm))
                {
                    // calculate remaining quantity to be ordered
                    var quantity = OrderSizing.GetUnorderedQuantity(algorithm, target);
                    if (quantity != 0)
                    {
                        algorithm.MarketOrder(target.Symbol, quantity);
                    }
                }

                _targetsCollection.ClearFulfilled(algorithm);
            }
        }
        /// <summary>
        /// Submit orders for the specified portolio targets.
        /// This model is free to delay or spread out these orders as it sees fit
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets to be ordered</param>
        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            // update the complete set of portfolio targets with the new targets
            _targetsCollection.AddRange(targets);

            // for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call
            if (_targetsCollection.Count > 0)
            {
                foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm))
                {
                    var symbol = target.Symbol;

                    // calculate remaining quantity to be ordered
                    var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                    // fetch our symbol data containing our VWAP indicator
                    SymbolData data;
                    if (!_symbolData.TryGetValue(symbol, out data))
                    {
                        continue;
                    }

                    // check order entry conditions
                    if (PriceIsFavorable(data, unorderedQuantity))
                    {
                        // get the maximum order size based on a percentage of current volume
                        var maxOrderSize = OrderSizing.PercentVolume(data.Security, MaximumOrderQuantityPercentVolume);
                        var orderSize    = Math.Min(maxOrderSize, Math.Abs(unorderedQuantity));

                        // round down to even lot size
                        orderSize -= orderSize % data.Security.SymbolProperties.LotSize;
                        if (orderSize != 0)
                        {
                            algorithm.MarketOrder(data.Security.Symbol, Math.Sign(unorderedQuantity) * orderSize);
                        }
                    }
                }

                _targetsCollection.ClearFulfilled(algorithm);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Executes market orders if the standard deviation of price is more than the configured number of deviations
        /// in the favorable direction.
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets</param>
        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            _targetsCollection.AddRange(targets);

            // for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call
            if (_targetsCollection.Count > 0)
            {
                foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm))
                {
                    var symbol = target.Symbol;

                    // calculate remaining quantity to be ordered
                    var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                    // fetch our symbol data containing our STD/SMA indicators
                    SymbolData data;
                    if (!_symbolData.TryGetValue(symbol, out data))
                    {
                        continue;
                    }

                    // check order entry conditions
                    if (data.STD.IsReady && PriceIsFavorable(data, unorderedQuantity))
                    {
                        // Adjust order size to respect the maximum total order value
                        var orderSize = OrderSizing.GetOrderSizeForMaximumValue(data.Security, MaximumOrderValue, unorderedQuantity);

                        if (orderSize != 0)
                        {
                            algorithm.MarketOrder(symbol, orderSize);
                        }
                    }
                }

                _targetsCollection.ClearFulfilled(algorithm);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Executes market orders if the standard deviation of price is more than the configured number of deviations
        /// in the favorable direction.
        /// </summary>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="targets">The portfolio targets</param>
        public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
        {
            _targetsCollection.AddRange(targets);

            foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm))
            {
                var symbol = target.Symbol;

                // calculate remaining quantity to be ordered
                var unorderedQuantity = OrderSizing.GetUnorderedQuantity(algorithm, target);

                // fetch our symbol data containing our STD/SMA indicators
                SymbolData data;
                if (!_symbolData.TryGetValue(symbol, out data))
                {
                    continue;
                }

                // check order entry conditions
                if (data.STD.IsReady && PriceIsFavorable(data, unorderedQuantity))
                {
                    // get the maximum order size based on total order value
                    var maxOrderSize = OrderSizing.Value(data.Security, MaximumOrderValue);
                    var orderSize    = Math.Min(maxOrderSize, Math.Abs(unorderedQuantity));

                    // round down to even lot size
                    orderSize -= orderSize % data.Security.SymbolProperties.LotSize;
                    if (orderSize != 0)
                    {
                        algorithm.MarketOrder(symbol, Math.Sign(unorderedQuantity) * orderSize);
                    }
                }
            }

            _targetsCollection.ClearFulfilled(algorithm);
        }