void OnAlphaRemoved(AbstractAlpha alpha) { this.Dispatcher.Invoke(DispatcherPriority.Render, new Action ( delegate() { AlphaCollection.Remove(alpha); })); }
/// <summary> /// Add alphas to the manager from the collection /// </summary> /// <param name="collection">The alpha collection emitted from <see cref="IAlgorithm.AlphasGenerated"/></param> public void AddAlphas(AlphaCollection collection) { foreach (var alpha in collection.Alphas) { var initialValues = _securityValuesProvider.GetValues(alpha.Symbol); var analysisPeriod = alpha.Period + TimeSpan.FromTicks((long)(_extraAnalysisPeriodRatio * alpha.Period.Ticks)); _openAlphaContexts[alpha.Id] = new AlphaAnalysisContext(alpha, initialValues, analysisPeriod); } }
/// <summary> /// Add alphas to the manager from the collection /// </summary> /// <param name="collection">The alpha collection emitted from <see cref="IAlgorithm.AlphasGenerated"/></param> public void AddAlphas(AlphaCollection collection) { foreach (var alpha in collection.Alphas) { // save initial security values and deterine analysis period var initialValues = _securityValuesProvider.GetValues(alpha.Symbol); var analysisPeriod = alpha.Period + TimeSpan.FromTicks((long)(_extraAnalysisPeriodRatio * alpha.Period.Ticks)); // set this as an open analysis context var context = new AlphaAnalysisContext(alpha, initialValues, analysisPeriod); _openAlphaContexts[alpha.Id] = context; // let everyone know we've received alpha OnAlphaReceived(context); } }
void OnAlphaUpdated(AbstractAlpha alpha) { this.Dispatcher.Invoke(DispatcherPriority.Render, new Action ( delegate() { if (AlphaCollection.Where( c => c.SourceDataSet == alpha.SourceDataSet && c.AlphaFilter == alpha.AlphaFilter && c.Xaxis.BinWidth == alpha.Xaxis.BinWidth && c.Yaxis.BinWidth == alpha.Yaxis.BinWidth && c.Xaxis.AxisType == alpha.Xaxis.AxisType && c.Yaxis.AxisType == alpha.Yaxis.AxisType).Count() == 0) { AlphaCollection.Add(alpha); } })); }
/// <summary> /// Handles the algorithm's <see cref="IAlgorithm.AlphasGenerated"/> event /// and broadcasts the new alpha using the messaging handler /// </summary> protected void OnAlphasGenerated(AlphaCollection collection) { // send message for newly created alphas Packet packet = new AlphaPacket(AlgorithmId, collection.Alphas); _messages.Enqueue(packet); AlphaManager.AddAlphas(collection); // aggregate alpha counts per symbol foreach (var grouping in collection.Alphas.GroupBy(alpha => alpha.Symbol)) { // predictions for this time step var count = grouping.Count(); // track daily assets _dailyAlphaCountPerSymbol.AddOrUpdate(grouping.Key, sym => count, (sym, cnt) => cnt + count); // track total assets for life of backtest _alphaCountPerSymbol.AddOrUpdate(grouping.Key, sym => count, (sym, cnt) => cnt + count); } }
public AlphaQueueItem(DateTime frontierTimeUtc, ReadOnlySecurityValuesCollection securityValues, AlphaCollection generatedAlphas = null) { FrontierTimeUtc = frontierTimeUtc; SecurityValues = securityValues; GeneratedAlphas = generatedAlphas ?? new AlphaCollection(frontierTimeUtc, Enumerable.Empty <Algorithm.Framework.Alphas.Alpha>()); }
/// <summary> /// Steps the manager forward in time, accepting new state information and potentialy newly generated alphas /// </summary> /// <param name="frontierTimeUtc">The frontier time of the alpha analysis</param> /// <param name="securityValuesCollection">Snap shot of the securities at the frontier time</param> /// <param name="generatedAlphas">Any alpha generated by the algorithm at the frontier time</param> public void Step(DateTime frontierTimeUtc, ReadOnlySecurityValuesCollection securityValuesCollection, AlphaCollection generatedAlphas) { if (generatedAlphas != null && generatedAlphas.Alphas.Count > 0) { foreach (var alpha in generatedAlphas.Alphas) { // save initial security values and deterine analysis period var initialValues = securityValuesCollection[alpha.Symbol]; var analysisPeriod = alpha.Period + TimeSpan.FromTicks((long)(_extraAnalysisPeriodRatio * alpha.Period.Ticks)); // set this as an open analysis context var context = new AlphaAnalysisContext(alpha, initialValues, analysisPeriod); _openAlphaContexts.Add(context); // let everyone know we've received alpha OnAlphaReceived(context); } } UpdateScores(securityValuesCollection); foreach (var extension in _extensions) { extension.Step(frontierTimeUtc); } }