Esempio n. 1
0
        //set position for each stock
        private void positionSetting(Symbol symbol, IndicatorBase <IndicatorDataPoint> data)
        {
            SymbolData sd = null;

            if (_sd.TryGetValue(symbol, out sd))
            {
                Debug("Calculate position value for the Symbol:" + symbol.ToString() + " at: " + Time);
                sd.Position = (int)(TOTALCASH * ACCOUNTPERC / data);
            }
            else
            {
                Error("Can not calculate position value for the Symbol:" + symbol.ToString() + " at: " + Time);
                sd.Position = 0;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Cleans out old security data and initializes the RSI for any newly added securities.
        /// This functional also seeds any new indicators using a history request.
        /// </summary>
        /// <param name="algorithm">The algorithm instance that experienced the change in securities</param>
        /// <param name="changes">The security additions and removals from the algorithm</param>
        public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
        {
            // clean up data for removed securities
            if (changes.RemovedSecurities.Count > 0)
            {
                var removed = changes.RemovedSecurities.ToHashSet(x => x.Symbol);
                foreach (var subscription in algorithm.SubscriptionManager.Subscriptions)
                {
                    if (removed.Contains(subscription.Symbol))
                    {
                        _symbolDataBySymbol.Remove(subscription.Symbol);
                        subscription.Consolidators.Clear();
                    }
                }
            }

            // initialize data for added securities
            var addedSymbols = new List <Symbol>();

            foreach (var added in changes.AddedSecurities)
            {
                if (!_symbolDataBySymbol.ContainsKey(added.Symbol))
                {
                    Differential indicator = algorithm.DIFF(added.Symbol, _window_size, _window_timeframe, algorithm.SubscriptionManager, _resolution);
                    //var rsi = algorithm.RSI(added.Symbol, _period, MovingAverageType.Wilders, _resolution);
                    var symbolData = new SymbolData(added.Symbol, indicator);
                    _symbolDataBySymbol[added.Symbol] = symbolData;
                    addedSymbols.Add(symbolData.Symbol);
                }
            }

            if (addedSymbols.Count > 0)
            {
                // warmup our indicators by pushing history through the consolidators
                algorithm.History(addedSymbols, _window_size, _resolution)
                .PushThrough(data =>
                {
                    SymbolData symbolData;
                    if (_symbolDataBySymbol.TryGetValue(data.Symbol, out symbolData))
                    {
                        symbolData.DIFF.Update(data.EndTime, data.Value);
                    }
                });
            }
        }
Esempio n. 3
0
            public int CompareTo(object obj)
            {
                if (obj == null)
                {
                    return(1);
                }

                SymbolData other = obj as SymbolData;

                if (other != null)
                {
                    return(this.Return.CompareTo(other.Return));
                }
                else
                {
                    throw new ArgumentException("Object is not a SymbolData");
                }
            }
Esempio n. 4
0
 protected override bool PriceIsFavorable(SymbolData data, decimal unorderedQuantity)
 {
     return(base.PriceIsFavorable(data, unorderedQuantity));
 }