コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChartingAlphaManagerExtension"/> class
        /// </summary>
        /// <param name="algorithm">The algorithm instance. This is only used for adding the charts
        /// to the algorithm. We purposefully do not save a reference to avoid potentially inconsistent reads</param>
        /// <param name="statisticsManager">Statistics manager used to access mean population scores for charting</param>
        public ChartingAlphaManagerExtension(IAlgorithm algorithm, StatisticsAlphaManagerExtension statisticsManager)
        {
            _statisticsManager = statisticsManager;
            _liveMode          = algorithm.LiveMode;

            // chart for average scores over sample period
            var scoreChart = new Chart("Alpha");

            foreach (var scoreType in AlphaManager.ScoreTypes)
            {
                var series = new Series($"{scoreType} Score", SeriesType.Line, "%");
                scoreChart.AddSeries(series);
                _alphaScoreSeriesByScoreType[scoreType] = series;
            }

            // chart for prediction count over sample period
            var predictionCount = new Chart("Alpha Count");

            predictionCount.AddSeries(_totalAlphaCountSeries);

            algorithm.AddChart(scoreChart);
            algorithm.AddChart(predictionCount);
            algorithm.AddChart(_totalAlphaCountPerSymbolChart);
            // removing this for now, not sure best way to display this data
            //Algorithm.AddChart(_dailyAlphaCountPerSymbolChart);
        }
コード例 #2
0
        /// <summary>
        /// Initializes this alpha handler to accept alphas from the specified algorithm
        /// </summary>
        /// <param name="job">The algorithm job</param>
        /// <param name="algorithm">The algorithm instance</param>
        /// <param name="messagingHandler">Handler used for sending alphas</param>
        /// <param name="api">Api instance</param>
        public virtual void Initialize(AlgorithmNodePacket job, IAlgorithm algorithm, IMessagingHandler messagingHandler, IApi api)
        {
            // initializing these properties just in case, doens't hurt to have them populated
            Job                      = job;
            Algorithm                = algorithm;
            _messagingHandler        = messagingHandler;
            _isNotFrameworkAlgorithm = !algorithm.IsFrameworkAlgorithm;
            if (_isNotFrameworkAlgorithm)
            {
                return;
            }


            _securityValuesProvider = new AlgorithmSecurityValuesProvider(algorithm);

            AlphaManager = CreateAlphaManager();

            var statistics = new StatisticsAlphaManagerExtension();

            RuntimeStatistics = statistics.Statistics;
            AlphaManager.AddExtension(statistics);
            _charting = new ChartingAlphaManagerExtension(algorithm, statistics);
            AlphaManager.AddExtension(_charting);

            // when alpha is generated, take snapshot of securities and place in queue for alpha manager to process on alpha thread
            algorithm.AlphasGenerated += (algo, collection) => _alphaQueue.Enqueue(new AlphaQueueItem(collection.DateTimeUtc, CreateSecurityValuesSnapshot(), collection));
        }