示例#1
0
 /// <summary>
 /// Event fired each time the we add/remove securities from the data feed
 /// </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 virtual void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
 {
     _securityChanges = changes != SecurityChanges.None;
     // Get removed symbol and invalidate them in the insight collection
     _removedSymbols = changes.RemovedSecurities.Select(x => x.Symbol).ToList();
     InsightCollection.Clear(_removedSymbols.ToArray());
 }
示例#2
0
 /// <summary>
 /// Event fired each time the we add/remove securities from the data feed
 /// </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)
 {
     base.OnSecuritiesChanged(algorithm, changes);
     // Get removed symbol and invalidate them in the insight collection
     _removedSymbols = changes.RemovedSecurities.Select(x => x.Symbol).ToList();
     InsightCollection.Clear(_removedSymbols.ToArray());
 }
        /// <summary>
        /// Event fired each time the we add/remove securities from the data feed
        /// </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)
        {
            // Get removed symbol and invalidate them in the insight collection
            _removedSymbols = changes.RemovedSecurities.Select(x => x.Symbol).ToList();
            _insightCollection.Clear(_removedSymbols.ToArray());

            foreach (var symbol in _removedSymbols)
            {
                if (_symbolDataDict.ContainsKey(symbol))
                {
                    _symbolDataDict[symbol].Reset();
                    _symbolDataDict.Remove(symbol);
                }
            }

            // initialize data for added securities
            var addedSymbols = changes.AddedSecurities.Select(x => x.Symbol).ToList();

            algorithm.History(addedSymbols, _lookback * _period, _resolution)
            .PushThrough(bar =>
            {
                ReturnsSymbolData symbolData;
                if (!_symbolDataDict.TryGetValue(bar.Symbol, out symbolData))
                {
                    symbolData = new ReturnsSymbolData(bar.Symbol, _lookback, _period);
                    _symbolDataDict.Add(bar.Symbol, symbolData);
                }
                symbolData.Update(bar.EndTime, bar.Value);
            });
        }