public void UpdateCallsDisposeOnDisposableInstances() { var disposable = new Disposable(Symbols.SPY); var dictionary = new Dictionary <Symbol, Disposable> { [Symbols.SPY] = disposable }; var SPY = new Equity( Symbols.SPY, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), new Cash("USD", 1m, 1m), SymbolProperties.GetDefault("USD"), ErrorCurrencyConverter.Instance, new RegisteredSecurityDataTypesProvider(), new SecurityCache() ); var changes = SecurityChangesTests.RemovedNonInternal(SPY); NotifiedSecurityChanges.UpdateDictionary(dictionary, changes, security => security.Symbol, security => new Disposable(security.Symbol) ); Assert.IsTrue(disposable.Disposed); }
/// <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(QCAlgorithmFramework algorithm, SecurityChanges changes) { // save securities removed so we can zero out our holdings _removedSymbols = changes.RemovedSecurities.Select(x => x.Symbol).ToList(); NotifiedSecurityChanges.UpdateCollection(_securities, changes); }
/// <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) { NotifiedSecurityChanges.UpdateCollection(Securities, changes); var symbols = Securities.Select(x => x.Symbol).ToArray(); var history = algorithm.History(symbols, _lookback, _resolution); var vectors = GetPriceVectors(history); if (vectors.LongLength == 0) { algorithm.Debug($"PearsonCorrelationPairsTradingAlphaModel.OnSecuritiesChanged(): The requested historical data does not have series of prices with the same date/time. Please consider increasing the looback period. Current lookback: {_lookback}"); } else { var pearsonMatrix = Correlation.PearsonMatrix(vectors).UpperTriangle(); var maxValue = pearsonMatrix.Enumerate().Where(x => Math.Abs(x) < 1).Max(); if (maxValue >= _minimumCorrelation) { var maxTuple = pearsonMatrix.Find(x => x == maxValue); _bestPair = Tuple.Create(symbols[maxTuple.Item1], symbols[maxTuple.Item2]); } } base.OnSecuritiesChanged(algorithm, changes); }
/// <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(QCAlgorithmFramework algorithm, SecurityChanges changes) { NotifiedSecurityChanges.UpdateCollection(_securities, changes); // this will allow the insight to be re-sent when the security re-joins the universe foreach (var removed in changes.RemovedSecurities) { _insightsTimeBySymbol.Remove(removed.Symbol); } }
/// <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) { NotifiedSecurityChanges.UpdateCollection(Securities, changes); UpdatePairs(algorithm); // Remove pairs that has assets that were removed from the universe foreach (var security in changes.RemovedSecurities) { var symbol = security.Symbol; var keys = _pairs.Keys.Where(k => k.Item1 == symbol || k.Item2 == symbol).ToList(); foreach (var key in keys) { _pairs.Remove(key); } } }
/// <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 void OnSecuritiesChanged(QCAlgorithmFramework algorithm, SecurityChanges changes) { NotifiedSecurityChanges.UpdateCollection(_securities, changes); }